Skip to content

Commit f865c3a

Browse files
committed
enh: handle node deleted
Signed-off-by: Christopher Ng <[email protected]>
1 parent 7617519 commit f865c3a

7 files changed

Lines changed: 81 additions & 6 deletions

File tree

apps/files_reminders/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@
1616
'OCA\\FilesReminders\\Db\\ReminderMapper' => $baseDir . '/../lib/Db/ReminderMapper.php',
1717
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => $baseDir . '/../lib/Exception/NodeNotFoundException.php',
1818
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => $baseDir . '/../lib/Exception/UserNotFoundException.php',
19+
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => $baseDir . '/../lib/Listener/NodeDeletedListener.php',
1920
'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => $baseDir . '/../lib/Migration/Version10000Date20230725162149.php',
2021
'OCA\\FilesReminders\\Model\\RichReminder' => $baseDir . '/../lib/Model/RichReminder.php',
2122
'OCA\\FilesReminders\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',

apps/files_reminders/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@ class ComposerStaticInitFilesReminders
3131
'OCA\\FilesReminders\\Db\\ReminderMapper' => __DIR__ . '/..' . '/../lib/Db/ReminderMapper.php',
3232
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/NodeNotFoundException.php',
3333
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/UserNotFoundException.php',
34+
'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/NodeDeletedListener.php',
3435
'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => __DIR__ . '/..' . '/../lib/Migration/Version10000Date20230725162149.php',
3536
'OCA\\FilesReminders\\Model\\RichReminder' => __DIR__ . '/..' . '/../lib/Model/RichReminder.php',
3637
'OCA\\FilesReminders\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',

apps/files_reminders/composer/composer/installed.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,19 @@
11
<?php return array(
22
'root' => array(
33
'name' => '__root__',
4-
'pretty_version' => '1.0.0+no-version-set',
5-
'version' => '1.0.0.0',
6-
'reference' => NULL,
4+
'pretty_version' => 'dev-master',
5+
'version' => 'dev-master',
6+
'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773',
77
'type' => 'library',
88
'install_path' => __DIR__ . '/../',
99
'aliases' => array(),
1010
'dev' => false,
1111
),
1212
'versions' => array(
1313
'__root__' => array(
14-
'pretty_version' => '1.0.0+no-version-set',
15-
'version' => '1.0.0.0',
16-
'reference' => NULL,
14+
'pretty_version' => 'dev-master',
15+
'version' => 'dev-master',
16+
'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773',
1717
'type' => 'library',
1818
'install_path' => __DIR__ . '/../',
1919
'aliases' => array(),

apps/files_reminders/lib/AppInfo/Application.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,11 +26,13 @@
2626

2727
namespace OCA\FilesReminders\AppInfo;
2828

29+
use OCA\FilesReminders\Listener\NodeDeletedListener;
2930
use OCA\FilesReminders\Notification\Notifier;
3031
use OCP\AppFramework\App;
3132
use OCP\AppFramework\Bootstrap\IBootContext;
3233
use OCP\AppFramework\Bootstrap\IBootstrap;
3334
use OCP\AppFramework\Bootstrap\IRegistrationContext;
35+
use OCP\Files\Events\Node\NodeDeletedEvent;
3436

3537
class Application extends App implements IBootstrap {
3638
public const APP_ID = 'files_reminders';
@@ -44,5 +46,6 @@ public function boot(IBootContext $context): void {
4446

4547
public function register(IRegistrationContext $context): void {
4648
$context->registerNotifierService(Notifier::class);
49+
$context->registerEventListener(NodeDeletedEvent::class, NodeDeletedListener::class);
4750
}
4851
}

apps/files_reminders/lib/Db/ReminderMapper.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@
2929
use OCP\AppFramework\Db\DoesNotExistException;
3030
use OCP\AppFramework\Db\QBMapper;
3131
use OCP\DB\QueryBuilder\IQueryBuilder;
32+
use OCP\Files\Node;
3233
use OCP\IDBConnection;
3334
use OCP\IUser;
3435

@@ -105,6 +106,20 @@ public function findAllForUser(IUser $user) {
105106
return $this->findEntities($qb);
106107
}
107108

109+
/**
110+
* @return Reminder[]
111+
*/
112+
public function findAllForNode(Node $node) {
113+
$qb = $this->db->getQueryBuilder();
114+
115+
$qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
116+
->from($this->getTableName())
117+
->where($qb->expr()->eq('file_id', $qb->createNamedParameter($node->getId(), IQueryBuilder::PARAM_INT)))
118+
->orderBy('due_date', 'ASC');
119+
120+
return $this->findEntities($qb);
121+
}
122+
108123
/**
109124
* @return Reminder[]
110125
*/
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* @copyright 2023 Christopher Ng <[email protected]>
7+
*
8+
* @author Christopher Ng <[email protected]>
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+
27+
namespace OCA\FilesReminders\Listener;
28+
29+
use OCA\FilesReminders\Service\ReminderService;
30+
use OCP\EventDispatcher\Event;
31+
use OCP\EventDispatcher\IEventListener;
32+
use OCP\Files\Events\Node\NodeDeletedEvent;
33+
34+
class NodeDeletedListener implements IEventListener {
35+
public function __construct(
36+
private ReminderService $reminderService,
37+
) {}
38+
39+
public function handle(Event $event): void {
40+
if (!($event instanceof NodeDeletedEvent)) {
41+
return;
42+
}
43+
44+
$node = $event->getNode();
45+
$this->reminderService->removeAllForNode($node);
46+
}
47+
}

apps/files_reminders/lib/Service/ReminderService.php

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
use OCA\FilesReminders\Model\RichReminder;
3737
use OCP\AppFramework\Db\DoesNotExistException;
3838
use OCP\Files\IRootFolder;
39+
use OCP\Files\Node;
3940
use OCP\IURLGenerator;
4041
use OCP\IUser;
4142
use OCP\IUserManager;
@@ -117,6 +118,13 @@ public function remove(IUser $user, int $fileId): void {
117118
$this->reminderMapper->delete($reminder);
118119
}
119120

121+
public function removeAllForNode(Node $node): void {
122+
$reminders = $this->reminderMapper->findAllForNode($node);
123+
foreach ($reminders as $reminder) {
124+
$this->reminderMapper->delete($reminder);
125+
}
126+
}
127+
120128
/**
121129
* @throws DoesNotExistException
122130
* @throws UserNotFoundException

0 commit comments

Comments
 (0)