@@ -18,17 +18,17 @@ |
||
| 18 | 18 | use OCP\User\Events\UserDeletedEvent; |
| 19 | 19 | |
| 20 | 20 | class Application extends App implements IBootstrap { |
| 21 | - public const APP_ID = 'contactsinteraction'; |
|
| 21 | + public const APP_ID = 'contactsinteraction'; |
|
| 22 | 22 | |
| 23 | - public function __construct() { |
|
| 24 | - parent::__construct(self::APP_ID); |
|
| 25 | - } |
|
| 23 | + public function __construct() { |
|
| 24 | + parent::__construct(self::APP_ID); |
|
| 25 | + } |
|
| 26 | 26 | |
| 27 | - public function register(IRegistrationContext $context): void { |
|
| 28 | - $context->registerEventListener(ContactInteractedWithEvent::class, ContactInteractionListener::class); |
|
| 29 | - $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 30 | - } |
|
| 27 | + public function register(IRegistrationContext $context): void { |
|
| 28 | + $context->registerEventListener(ContactInteractedWithEvent::class, ContactInteractionListener::class); |
|
| 29 | + $context->registerEventListener(UserDeletedEvent::class, UserDeletedListener::class); |
|
| 30 | + } |
|
| 31 | 31 | |
| 32 | - public function boot(IBootContext $context): void { |
|
| 33 | - } |
|
| 32 | + public function boot(IBootContext $context): void { |
|
| 33 | + } |
|
| 34 | 34 | } |
@@ -17,109 +17,109 @@ |
||
| 17 | 17 | * @template-extends QBMapper<RecentContact> |
| 18 | 18 | */ |
| 19 | 19 | class RecentContactMapper extends QBMapper { |
| 20 | - public const TABLE_NAME = 'recent_contact'; |
|
| 21 | - |
|
| 22 | - public function __construct(IDBConnection $db) { |
|
| 23 | - parent::__construct($db, self::TABLE_NAME); |
|
| 24 | - } |
|
| 25 | - |
|
| 26 | - /** |
|
| 27 | - * @return RecentContact[] |
|
| 28 | - */ |
|
| 29 | - public function findAll(string $uid): array { |
|
| 30 | - $qb = $this->db->getQueryBuilder(); |
|
| 31 | - |
|
| 32 | - $select = $qb |
|
| 33 | - ->select('*') |
|
| 34 | - ->from($this->getTableName()) |
|
| 35 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 36 | - |
|
| 37 | - return $this->findEntities($select); |
|
| 38 | - } |
|
| 39 | - |
|
| 40 | - /** |
|
| 41 | - * @throws DoesNotExistException |
|
| 42 | - */ |
|
| 43 | - public function find(string $uid, int $id): RecentContact { |
|
| 44 | - $qb = $this->db->getQueryBuilder(); |
|
| 45 | - |
|
| 46 | - $select = $qb |
|
| 47 | - ->select('*') |
|
| 48 | - ->from($this->getTableName()) |
|
| 49 | - ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
| 50 | - ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 51 | - |
|
| 52 | - return $this->findEntity($select); |
|
| 53 | - } |
|
| 54 | - |
|
| 55 | - /** |
|
| 56 | - * @return RecentContact[] |
|
| 57 | - */ |
|
| 58 | - public function findMatch(IUser $user, |
|
| 59 | - ?string $uid, |
|
| 60 | - ?string $email, |
|
| 61 | - ?string $cloudId): array { |
|
| 62 | - $qb = $this->db->getQueryBuilder(); |
|
| 63 | - |
|
| 64 | - $additionalWheres = []; |
|
| 65 | - if ($uid !== null) { |
|
| 66 | - $additionalWheres[] = $qb->expr()->eq('uid', $qb->createNamedParameter($uid)); |
|
| 67 | - } |
|
| 68 | - if ($email !== null) { |
|
| 69 | - $additionalWheres[] = $qb->expr()->eq('email', $qb->createNamedParameter($email)); |
|
| 70 | - } |
|
| 71 | - if ($cloudId !== null) { |
|
| 72 | - $additionalWheres[] = $qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId)); |
|
| 73 | - } |
|
| 74 | - |
|
| 75 | - $select = $qb |
|
| 76 | - ->select('*') |
|
| 77 | - ->from($this->getTableName()) |
|
| 78 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
| 79 | - |
|
| 80 | - if (!empty($additionalWheres)) { |
|
| 81 | - $select->andWhere($select->expr()->orX(...$additionalWheres)); |
|
| 82 | - } |
|
| 83 | - return $this->findEntities($select); |
|
| 84 | - } |
|
| 85 | - |
|
| 86 | - public function findLastUpdatedForUserId(string $uid): ?int { |
|
| 87 | - $qb = $this->db->getQueryBuilder(); |
|
| 88 | - |
|
| 89 | - $select = $qb |
|
| 90 | - ->select('last_contact') |
|
| 91 | - ->from($this->getTableName()) |
|
| 92 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
| 93 | - ->orderBy('last_contact', 'DESC') |
|
| 94 | - ->setMaxResults(1); |
|
| 95 | - |
|
| 96 | - $cursor = $select->executeQuery(); |
|
| 97 | - $row = $cursor->fetch(); |
|
| 98 | - |
|
| 99 | - if ($row === false) { |
|
| 100 | - return null; |
|
| 101 | - } |
|
| 102 | - |
|
| 103 | - return (int)$row['last_contact']; |
|
| 104 | - } |
|
| 105 | - |
|
| 106 | - public function cleanUp(int $olderThan): void { |
|
| 107 | - $qb = $this->db->getQueryBuilder(); |
|
| 108 | - |
|
| 109 | - $delete = $qb |
|
| 110 | - ->delete($this->getTableName()) |
|
| 111 | - ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
| 112 | - |
|
| 113 | - $delete->executeStatement(); |
|
| 114 | - } |
|
| 115 | - |
|
| 116 | - public function deleteByUserId(string $uid): void { |
|
| 117 | - $qb = $this->db->getQueryBuilder(); |
|
| 118 | - |
|
| 119 | - $delete = $qb |
|
| 120 | - ->delete($this->getTableName()) |
|
| 121 | - ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 122 | - |
|
| 123 | - $delete->executeStatement(); |
|
| 124 | - } |
|
| 20 | + public const TABLE_NAME = 'recent_contact'; |
|
| 21 | + |
|
| 22 | + public function __construct(IDBConnection $db) { |
|
| 23 | + parent::__construct($db, self::TABLE_NAME); |
|
| 24 | + } |
|
| 25 | + |
|
| 26 | + /** |
|
| 27 | + * @return RecentContact[] |
|
| 28 | + */ |
|
| 29 | + public function findAll(string $uid): array { |
|
| 30 | + $qb = $this->db->getQueryBuilder(); |
|
| 31 | + |
|
| 32 | + $select = $qb |
|
| 33 | + ->select('*') |
|
| 34 | + ->from($this->getTableName()) |
|
| 35 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 36 | + |
|
| 37 | + return $this->findEntities($select); |
|
| 38 | + } |
|
| 39 | + |
|
| 40 | + /** |
|
| 41 | + * @throws DoesNotExistException |
|
| 42 | + */ |
|
| 43 | + public function find(string $uid, int $id): RecentContact { |
|
| 44 | + $qb = $this->db->getQueryBuilder(); |
|
| 45 | + |
|
| 46 | + $select = $qb |
|
| 47 | + ->select('*') |
|
| 48 | + ->from($this->getTableName()) |
|
| 49 | + ->where($qb->expr()->eq('id', $qb->createNamedParameter($id, $qb::PARAM_INT))) |
|
| 50 | + ->andWhere($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 51 | + |
|
| 52 | + return $this->findEntity($select); |
|
| 53 | + } |
|
| 54 | + |
|
| 55 | + /** |
|
| 56 | + * @return RecentContact[] |
|
| 57 | + */ |
|
| 58 | + public function findMatch(IUser $user, |
|
| 59 | + ?string $uid, |
|
| 60 | + ?string $email, |
|
| 61 | + ?string $cloudId): array { |
|
| 62 | + $qb = $this->db->getQueryBuilder(); |
|
| 63 | + |
|
| 64 | + $additionalWheres = []; |
|
| 65 | + if ($uid !== null) { |
|
| 66 | + $additionalWheres[] = $qb->expr()->eq('uid', $qb->createNamedParameter($uid)); |
|
| 67 | + } |
|
| 68 | + if ($email !== null) { |
|
| 69 | + $additionalWheres[] = $qb->expr()->eq('email', $qb->createNamedParameter($email)); |
|
| 70 | + } |
|
| 71 | + if ($cloudId !== null) { |
|
| 72 | + $additionalWheres[] = $qb->expr()->eq('federated_cloud_id', $qb->createNamedParameter($cloudId)); |
|
| 73 | + } |
|
| 74 | + |
|
| 75 | + $select = $qb |
|
| 76 | + ->select('*') |
|
| 77 | + ->from($this->getTableName()) |
|
| 78 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($user->getUID()))); |
|
| 79 | + |
|
| 80 | + if (!empty($additionalWheres)) { |
|
| 81 | + $select->andWhere($select->expr()->orX(...$additionalWheres)); |
|
| 82 | + } |
|
| 83 | + return $this->findEntities($select); |
|
| 84 | + } |
|
| 85 | + |
|
| 86 | + public function findLastUpdatedForUserId(string $uid): ?int { |
|
| 87 | + $qb = $this->db->getQueryBuilder(); |
|
| 88 | + |
|
| 89 | + $select = $qb |
|
| 90 | + ->select('last_contact') |
|
| 91 | + ->from($this->getTableName()) |
|
| 92 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))) |
|
| 93 | + ->orderBy('last_contact', 'DESC') |
|
| 94 | + ->setMaxResults(1); |
|
| 95 | + |
|
| 96 | + $cursor = $select->executeQuery(); |
|
| 97 | + $row = $cursor->fetch(); |
|
| 98 | + |
|
| 99 | + if ($row === false) { |
|
| 100 | + return null; |
|
| 101 | + } |
|
| 102 | + |
|
| 103 | + return (int)$row['last_contact']; |
|
| 104 | + } |
|
| 105 | + |
|
| 106 | + public function cleanUp(int $olderThan): void { |
|
| 107 | + $qb = $this->db->getQueryBuilder(); |
|
| 108 | + |
|
| 109 | + $delete = $qb |
|
| 110 | + ->delete($this->getTableName()) |
|
| 111 | + ->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan))); |
|
| 112 | + |
|
| 113 | + $delete->executeStatement(); |
|
| 114 | + } |
|
| 115 | + |
|
| 116 | + public function deleteByUserId(string $uid): void { |
|
| 117 | + $qb = $this->db->getQueryBuilder(); |
|
| 118 | + |
|
| 119 | + $delete = $qb |
|
| 120 | + ->delete($this->getTableName()) |
|
| 121 | + ->where($qb->expr()->eq('actor_uid', $qb->createNamedParameter($uid))); |
|
| 122 | + |
|
| 123 | + $delete->executeStatement(); |
|
| 124 | + } |
|
| 125 | 125 | } |
@@ -19,17 +19,17 @@ |
||
| 19 | 19 | */ |
| 20 | 20 | class UserDeletedListener implements IEventListener { |
| 21 | 21 | |
| 22 | - public function __construct( |
|
| 23 | - private readonly RecentContactMapper $recentContactMapper, |
|
| 24 | - ) { |
|
| 25 | - } |
|
| 26 | - |
|
| 27 | - #[\Override] |
|
| 28 | - public function handle(Event $event): void { |
|
| 29 | - if (!($event instanceof UserDeletedEvent)) { |
|
| 30 | - return; |
|
| 31 | - } |
|
| 32 | - |
|
| 33 | - $this->recentContactMapper->deleteByUserId($event->getUser()->getUID()); |
|
| 34 | - } |
|
| 22 | + public function __construct( |
|
| 23 | + private readonly RecentContactMapper $recentContactMapper, |
|
| 24 | + ) { |
|
| 25 | + } |
|
| 26 | + |
|
| 27 | + #[\Override] |
|
| 28 | + public function handle(Event $event): void { |
|
| 29 | + if (!($event instanceof UserDeletedEvent)) { |
|
| 30 | + return; |
|
| 31 | + } |
|
| 32 | + |
|
| 33 | + $this->recentContactMapper->deleteByUserId($event->getUser()->getUID()); |
|
| 34 | + } |
|
| 35 | 35 | } |