fix intro.cid and intro.suggest-id
This commit is contained in:
parent
b4572a5293
commit
44627a0b12
|
@ -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 {
|
try {
|
||||||
return $this->exists(['uid' => $uid, 'suggest-cid' => $cid]);
|
return $this->exists(['uid' => $uid, 'suggest-cid' => $sid]);
|
||||||
} catch (\Exception $e) {
|
} 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);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -25,8 +25,8 @@ use Friendica\BaseEntity;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @property-read int $uid
|
* @property-read int $uid
|
||||||
* @property-read int $sid
|
* @property-read int $cid
|
||||||
* @property-read int|null $cid
|
* @property-read int|null $sid
|
||||||
* @property-read bool $knowyou
|
* @property-read bool $knowyou
|
||||||
* @property-read bool $duplex
|
* @property-read bool $duplex
|
||||||
* @property-read string $note
|
* @property-read string $note
|
||||||
|
@ -40,9 +40,9 @@ class Introduction extends BaseEntity
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $uid;
|
protected $uid;
|
||||||
/** @var int */
|
/** @var int */
|
||||||
protected $sid;
|
|
||||||
/** @var int|null */
|
|
||||||
protected $cid;
|
protected $cid;
|
||||||
|
/** @var int|null */
|
||||||
|
protected $sid;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
protected $knowyou;
|
protected $knowyou;
|
||||||
/** @var bool */
|
/** @var bool */
|
||||||
|
@ -60,8 +60,8 @@ class Introduction extends BaseEntity
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param int $uid
|
* @param int $uid
|
||||||
* @param int $sid
|
* @param int $cid
|
||||||
* @param int|null $cid
|
* @param int|null $sid
|
||||||
* @param bool $knowyou
|
* @param bool $knowyou
|
||||||
* @param bool $duplex
|
* @param bool $duplex
|
||||||
* @param string $note
|
* @param string $note
|
||||||
|
@ -70,11 +70,11 @@ class Introduction extends BaseEntity
|
||||||
* @param bool $ignore
|
* @param bool $ignore
|
||||||
* @param int|null $id
|
* @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->uid = $uid;
|
||||||
$this->sid = $sid;
|
|
||||||
$this->cid = $cid;
|
$this->cid = $cid;
|
||||||
|
$this->sid = $sid;
|
||||||
$this->knowyou = $knowyou;
|
$this->knowyou = $knowyou;
|
||||||
$this->duplex = $duplex;
|
$this->duplex = $duplex;
|
||||||
$this->note = $note;
|
$this->note = $note;
|
||||||
|
|
|
@ -36,8 +36,8 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
|
||||||
{
|
{
|
||||||
return new Entity\Introduction(
|
return new Entity\Introduction(
|
||||||
$row['uid'] ?? 0,
|
$row['uid'] ?? 0,
|
||||||
$row['suggest-cid'] ?? 0,
|
$row['contact-id'] ?? 0,
|
||||||
$row['contact-id'] ?? null,
|
$row['suggest-cid'] ?? null,
|
||||||
!empty($row['knowyou']),
|
!empty($row['knowyou']),
|
||||||
!empty($row['duplex']),
|
!empty($row['duplex']),
|
||||||
$row['note'] ?? '',
|
$row['note'] ?? '',
|
||||||
|
@ -50,9 +50,9 @@ class Introduction extends BaseFactory implements ICanCreateFromTableRow
|
||||||
|
|
||||||
public function createNew(
|
public function createNew(
|
||||||
int $uid,
|
int $uid,
|
||||||
int $sid,
|
int $cid,
|
||||||
string $note,
|
string $note,
|
||||||
int $cid = null,
|
int $sid = null,
|
||||||
bool $knowyou = false,
|
bool $knowyou = false,
|
||||||
bool $duplex = false
|
bool $duplex = false
|
||||||
): Entity\Introduction {
|
): Entity\Introduction {
|
||||||
|
|
|
@ -1352,7 +1352,7 @@ class DFRN
|
||||||
}
|
}
|
||||||
|
|
||||||
// Quit if we already have an introduction for this person
|
// Quit if we already have an introduction for this person
|
||||||
if (DI::intro()->existsForContact($cid, $uid)) {
|
if (DI::intro()->suggestionExistsForUser($cid, $uid)) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -42,8 +42,8 @@ class IntroductionTest extends TestCase
|
||||||
],
|
],
|
||||||
'assertion' => [
|
'assertion' => [
|
||||||
'uid' => 0,
|
'uid' => 0,
|
||||||
'suggest-cid' => 0,
|
'contact-id' => 0,
|
||||||
'contact-id' => null,
|
'suggest-cid' => null,
|
||||||
'knowyou' => false,
|
'knowyou' => false,
|
||||||
'duplex' => false,
|
'duplex' => false,
|
||||||
'note' => '',
|
'note' => '',
|
||||||
|
@ -58,8 +58,8 @@ class IntroductionTest extends TestCase
|
||||||
{
|
{
|
||||||
self::assertEquals($intro->id, $assertion['id'] ?? null);
|
self::assertEquals($intro->id, $assertion['id'] ?? null);
|
||||||
self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
|
self::assertEquals($intro->uid, $assertion['uid'] ?? 0);
|
||||||
self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? 0);
|
self::assertEquals($intro->cid, $assertion['contact-id'] ?? 0);
|
||||||
self::assertEquals($intro->cid, $assertion['contact-id'] ?? null);
|
self::assertEquals($intro->sid, $assertion['suggest-cid'] ?? null);
|
||||||
self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
|
self::assertEquals($intro->knowyou, $assertion['knowyou'] ?? false);
|
||||||
self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
|
self::assertEquals($intro->duplex, $assertion['duplex'] ?? false);
|
||||||
self::assertEquals($intro->note, $assertion['note'] ?? '');
|
self::assertEquals($intro->note, $assertion['note'] ?? '');
|
||||||
|
@ -94,11 +94,11 @@ class IntroductionTest extends TestCase
|
||||||
{
|
{
|
||||||
$factory = new Introduction(new NullLogger());
|
$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, [
|
$this->assertIntro($intro, [
|
||||||
'uid' => $input['uid'] ?? 0,
|
'uid' => $input['uid'] ?? 0,
|
||||||
'sid' => $input['sid'] ?? 0,
|
'contact-id' => $input['cid'] ?? 0,
|
||||||
'note' => $input['note'] ?? '',
|
'note' => $input['note'] ?? '',
|
||||||
]);
|
]);
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue
Block a user