Skip to content

Commit 74e5830

Browse files
fixup! Register an address book with recent contacts
Signed-off-by: Christoph Wurst <christoph@winzerhof-wurst.at>
1 parent 5f2d9f6 commit 74e5830

5 files changed

Lines changed: 65 additions & 1 deletion

File tree

apps/contactsinteraction/appinfo/info.xml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,9 @@
1919
<dependencies>
2020
<nextcloud min-version="19" max-version="19"/>
2121
</dependencies>
22+
<background-jobs>
23+
<job>OCA\ContactsInteraction\BackgroundJob\CleanupJob</job>
24+
</background-jobs>
2225
<sabre>
2326
<address-book-plugins>
2427
<plugin>OCA\ContactsInteraction\AddressBookProvider</plugin>

apps/contactsinteraction/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
'OCA\\ContactsInteraction\\AddressBook' => $baseDir . '/../lib/AddressBook.php',
1010
'OCA\\ContactsInteraction\\AddressBookProvider' => $baseDir . '/../lib/AddressBookProvider.php',
1111
'OCA\\ContactsInteraction\\AppInfo\\Application' => $baseDir . '/../lib/AppInfo/Application.php',
12+
'OCA\\ContactsInteraction\\BackgroundJob\\CleanupJob' => $baseDir . '/../lib/BackgroundJob/CleanupJob.php',
1213
'OCA\\ContactsInteraction\\Card' => $baseDir . '/../lib/Card.php',
1314
'OCA\\ContactsInteraction\\Db\\CardSearchDao' => $baseDir . '/../lib/Db/CardSearchDao.php',
1415
'OCA\\ContactsInteraction\\Db\\RecentContact' => $baseDir . '/../lib/Db/RecentContact.php',

apps/contactsinteraction/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ class ComposerStaticInitContactsInteraction
2424
'OCA\\ContactsInteraction\\AddressBook' => __DIR__ . '/..' . '/../lib/AddressBook.php',
2525
'OCA\\ContactsInteraction\\AddressBookProvider' => __DIR__ . '/..' . '/../lib/AddressBookProvider.php',
2626
'OCA\\ContactsInteraction\\AppInfo\\Application' => __DIR__ . '/..' . '/../lib/AppInfo/Application.php',
27+
'OCA\\ContactsInteraction\\BackgroundJob\\CleanupJob' => __DIR__ . '/..' . '/../lib/BackgroundJob/CleanupJob.php',
2728
'OCA\\ContactsInteraction\\Card' => __DIR__ . '/..' . '/../lib/Card.php',
2829
'OCA\\ContactsInteraction\\Db\\CardSearchDao' => __DIR__ . '/..' . '/../lib/Db/CardSearchDao.php',
2930
'OCA\\ContactsInteraction\\Db\\RecentContact' => __DIR__ . '/..' . '/../lib/Db/RecentContact.php',
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
7+
*
8+
* @author 2020 Christoph Wurst <christoph@winzerhof-wurst.at>
9+
*
10+
* @license GNU AGPL version 3 or any later version
11+
*
12+
* This program is free software: you can redistribute it and/or modify
13+
* it under the terms of the GNU Affero General Public License as
14+
* published by the Free Software Foundation, either version 3 of the
15+
* License, or (at your option) any later version.
16+
*
17+
* This program is distributed in the hope that it will be useful,
18+
* but WITHOUT ANY WARRANTY; without even the implied warranty of
19+
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20+
* GNU Affero General Public License for more details.
21+
*
22+
* You should have received a copy of the GNU Affero General Public License
23+
* along with this program. If not, see <http://www.gnu.org/licenses/>.
24+
*/
25+
26+
namespace OCA\ContactsInteraction\BackgroundJob;
27+
28+
use OCA\ContactsInteraction\Db\RecentContactMapper;
29+
use OCP\AppFramework\Utility\ITimeFactory;
30+
use OCP\BackgroundJob\Job;
31+
32+
class CleanupJob extends Job {
33+
34+
/** @var RecentContactMapper */
35+
private $mapper;
36+
37+
public function __construct(ITimeFactory $time,
38+
RecentContactMapper $mapper) {
39+
parent::__construct($time);
40+
$this->mapper = $mapper;
41+
}
42+
43+
protected function run($argument) {
44+
$time = $this->time->getDateTime();
45+
$time->modify('-7days');
46+
$this->mapper->cleanUp($time->getTimestamp());
47+
}
48+
49+
}

apps/contactsinteraction/lib/Db/RecentContactMapper.php

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,8 +56,8 @@ public function findAll(string $uid): array {
5656
* @param string $uid
5757
* @param int $id
5858
*
59-
* @throws DoesNotExistException
6059
* @return RecentContact
60+
* @throws DoesNotExistException
6161
*/
6262
public function find(string $uid, int $id): RecentContact {
6363
$qb = $this->db->getQueryBuilder();
@@ -105,4 +105,14 @@ public function findMatch(IUser $user,
105105
return $this->findEntities($select);
106106
}
107107

108+
public function cleanUp(int $olderThan): void {
109+
$qb = $this->db->getQueryBuilder();
110+
111+
$delete = $qb
112+
->delete($this->getTableName())
113+
->where($qb->expr()->lt('last_contact', $qb->createNamedParameter($olderThan)));
114+
115+
$delete->execute();
116+
}
117+
108118
}

0 commit comments

Comments
 (0)