]> git.mxchange.org Git - friendica.git/commitdiff
fix intro.cid and intro.suggest-id
authorPhilipp <admin@philipp.info>
Tue, 19 Oct 2021 21:11:47 +0000 (23:11 +0200)
committerPhilipp <admin@philipp.info>
Thu, 21 Oct 2021 19:57:23 +0000 (21:57 +0200)
src/Contact/Introduction/Depository/Introduction.php
src/Contact/Introduction/Entity/Introduction.php
src/Contact/Introduction/Factory/Introduction.php
src/Protocol/DFRN.php
tests/src/Contact/Introduction/Factory/IntroductionTest.php

index 249252d44a8f095d3efe57e8c110889cb55da2bc..b9752d81120ca7ffa19e056ae759cf16319d62a3 100644 (file)
@@ -147,12 +147,20 @@ class Introduction extends BaseDepository
                }
        }
 
-       public function existsForContact(int $cid, int $uid): bool
+       /**
+        * Checks, if the suggested contact already exists for the user
+        *
+        * @param int $sid
+        * @param int $uid
+        *
+        * @return bool
+        */
+       public function suggestionExistsForUser(int $sid, int $uid): bool
        {
                try {
-                       return $this->exists(['uid' => $uid, 'suggest-cid' => $cid]);
+                       return $this->exists(['uid' => $uid, 'suggest-cid' => $sid]);
                } catch (\Exception $e) {
-                       throw new IntroductionPersistenceException(sprintf('Cannot check Introductions for contact %d and user %d', $cid, $uid), $e);
+                       throw new IntroductionPersistenceException(sprintf('Cannot check suggested Introduction for contact %d and user %d', $sid, $uid), $e);
                }
        }
 
index 7485f8181bc84c15be3aec0b4f53339accae27d9..af9db729aaa92865052c9664a00d132e596d222a 100644 (file)
@@ -25,8 +25,8 @@ use Friendica\BaseEntity;
 
 /**
  * @property-read int $uid
- * @property-read int $sid
- * @property-read int|null $cid
+ * @property-read int $cid
+ * @property-read int|null $sid
  * @property-read bool $knowyou
  * @property-read bool $duplex
  * @property-read string $note
@@ -40,9 +40,9 @@ class Introduction extends BaseEntity
        /** @var int */
        protected $uid;
        /** @var int */
-       protected $sid;
-       /** @var int|null */
        protected $cid;
+       /** @var int|null */
+       protected $sid;
        /** @var bool */
        protected $knowyou;
        /** @var bool */
@@ -60,8 +60,8 @@ class Introduction extends BaseEntity
 
        /**
         * @param int       $uid
-        * @param int       $sid
-        * @param int|null  $cid
+        * @param int       $cid
+        * @param int|null  $sid
         * @param bool      $knowyou
         * @param bool      $duplex
         * @param string    $note
@@ -70,11 +70,11 @@ class Introduction extends BaseEntity
         * @param bool      $ignore
         * @param int|null  $id
         */
-       public function __construct(int $uid, int $sid, ?int $cid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
+       public function __construct(int $uid, int $cid, ?int $sid, bool $knowyou, bool $duplex, string $note, string $hash, \DateTime $datetime, bool $ignore, ?int $id)
        {
                $this->uid      = $uid;
-               $this->sid      = $sid;
                $this->cid      = $cid;
+               $this->sid      = $sid;
                $this->knowyou  = $knowyou;
                $this->duplex   = $duplex;
                $this->note     = $note;
index 8aa5b7591a0e549550dced25316e1d20683cad64..57598f5e80c393a74cebf428a37ad68fd47d3417 100644 (file)
@@ -36,8 +36,8 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
        {
                return new Entity\Introduction(
                        $row['uid'] ?? 0,
-                       $row['suggest-cid'] ?? 0,
-                       $row['contact-id'] ?? null,
+                       $row['contact-id'] ?? 0,
+                       $row['suggest-cid'] ?? null,
                        !empty($row['knowyou']),
                        !empty($row['duplex']),
                        $row['note'] ?? '',
@@ -50,9 +50,9 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
 
        public function createNew(
                int $uid,
-               int $sid,
+               int $cid,
                string $note,
-               int $cid = null,
+               int $sid = null,
                bool $knowyou = false,
                bool $duplex = false
        ): Entity\Introduction {
index 9246d8583349591d78d838183e5d4e216e3aacec..a9918bbd02337e6a4da4a3b9d590450998b7643f 100644 (file)
@@ -1352,7 +1352,7 @@ class DFRN
                }
 
                // Quit if we already have an introduction for this person
-               if (DI::intro()->existsForContact($cid, $uid)) {
+               if (DI::intro()->suggestionExistsForUser($cid, $uid)) {
                        return false;
                }
 
index 9f45c54b066d39bdb6a3bec5699d2eda397d6f20..529d2720efb9a8ba5f333c467a95276cabdb014a 100644 (file)
@@ -42,8 +42,8 @@ class IntroductionTest extends TestCase
                                ],
                                'assertion' => [
                                        'uid'         => 0,
-                                       'suggest-cid' => 0,
-                                       'contact-id'  => null,
+                                       'contact-id'  => 0,
+                                       'suggest-cid' => null,
                                        'knowyou'     => false,
                                        'duplex'      => false,
                                        'note'        => '',
@@ -58,8 +58,8 @@ class IntroductionTest extends TestCase
        {
                self::assertEquals($intro->id, $assertion['id'] ?? null);
                self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
-               self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? 0);
-               self::assertEquals($intro->cid, $assertion['contact-id'] ?? null);
+               self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
+               self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
                self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
                self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
                self::assertEquals($intro->note, $assertion['note'] ?? '');
@@ -94,12 +94,12 @@ class IntroductionTest extends TestCase
        {
                $factory = new Introduction(new NullLogger());
 
-               $intro = $factory->createNew($input['uid'] ?? 0, $input['sid'] ?? 0, $input['note'] ?? '');
+               $intro = $factory->createNew($input['uid'] ?? 0, $input['cid'] ?? 0, $input['note'] ?? '');
 
                $this->assertIntro($intro, [
-                       'uid'  => $input['uid'] ?? 0,
-                       'sid'  => $input['sid'] ?? 0,
-                       'note' => $input['note'] ?? '',
+                       'uid'        => $input['uid'] ?? 0,
+                       'contact-id' => $input['cid'] ?? 0,
+                       'note'       => $input['note'] ?? '',
                ]);
        }