aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher Ng <chrng8@gmail.com>2023-07-31 17:27:02 -0700
committerChristopher Ng <chrng8@gmail.com>2023-08-08 16:29:12 -0700
commite12ae21745d464335ce3d4665f04ca564dac3bde (patch)
treee2854b43a9bc5b845ecc783e004d7cb9c5bd11f7
parent1c6114b21ac6919bd888a21ec1f5076adcf527b6 (diff)
downloadnextcloud-server-e12ae21745d464335ce3d4665f04ca564dac3bde.tar.gz
nextcloud-server-e12ae21745d464335ce3d4665f04ca564dac3bde.zip
enh: handle node deleted
Signed-off-by: Christopher Ng <chrng8@gmail.com> (cherry picked from commit f865c3ad21e03483a6f16b90a4383faef0356499)
-rw-r--r--apps/files_reminders/composer/composer/autoload_classmap.php1
-rw-r--r--apps/files_reminders/composer/composer/autoload_static.php1
-rw-r--r--apps/files_reminders/composer/composer/installed.php12
-rw-r--r--apps/files_reminders/lib/AppInfo/Application.php3
-rw-r--r--apps/files_reminders/lib/Db/ReminderMapper.php15
-rw-r--r--apps/files_reminders/lib/Listener/NodeDeletedListener.php47
-rw-r--r--apps/files_reminders/lib/Service/ReminderService.php8
7 files changed, 81 insertions, 6 deletions
diff --git a/apps/files_reminders/composer/composer/autoload_classmap.php b/apps/files_reminders/composer/composer/autoload_classmap.php
index 29f781d0006..fb17eb7a1b6 100644
--- a/apps/files_reminders/composer/composer/autoload_classmap.php
+++ b/apps/files_reminders/composer/composer/autoload_classmap.php
@@ -16,6 +16,7 @@ return array(
'OCA\\FilesReminders\\Db\\ReminderMapper' => $baseDir . '/../lib/Db/ReminderMapper.php',
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => $baseDir . '/../lib/Exception/NodeNotFoundException.php',
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => $baseDir . '/../lib/Exception/UserNotFoundException.php',
+ 'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => $baseDir . '/../lib/Listener/NodeDeletedListener.php',
'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => $baseDir . '/../lib/Migration/Version10000Date20230725162149.php',
'OCA\\FilesReminders\\Model\\RichReminder' => $baseDir . '/../lib/Model/RichReminder.php',
'OCA\\FilesReminders\\Notification\\Notifier' => $baseDir . '/../lib/Notification/Notifier.php',
diff --git a/apps/files_reminders/composer/composer/autoload_static.php b/apps/files_reminders/composer/composer/autoload_static.php
index efea8791020..1a2bc0d1bd1 100644
--- a/apps/files_reminders/composer/composer/autoload_static.php
+++ b/apps/files_reminders/composer/composer/autoload_static.php
@@ -31,6 +31,7 @@ class ComposerStaticInitFilesReminders
'OCA\\FilesReminders\\Db\\ReminderMapper' => __DIR__ . '/..' . '/../lib/Db/ReminderMapper.php',
'OCA\\FilesReminders\\Exception\\NodeNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/NodeNotFoundException.php',
'OCA\\FilesReminders\\Exception\\UserNotFoundException' => __DIR__ . '/..' . '/../lib/Exception/UserNotFoundException.php',
+ 'OCA\\FilesReminders\\Listener\\NodeDeletedListener' => __DIR__ . '/..' . '/../lib/Listener/NodeDeletedListener.php',
'OCA\\FilesReminders\\Migration\\Version10000Date20230725162149' => __DIR__ . '/..' . '/../lib/Migration/Version10000Date20230725162149.php',
'OCA\\FilesReminders\\Model\\RichReminder' => __DIR__ . '/..' . '/../lib/Model/RichReminder.php',
'OCA\\FilesReminders\\Notification\\Notifier' => __DIR__ . '/..' . '/../lib/Notification/Notifier.php',
diff --git a/apps/files_reminders/composer/composer/installed.php b/apps/files_reminders/composer/composer/installed.php
index c398e796c32..f120393f41b 100644
--- a/apps/files_reminders/composer/composer/installed.php
+++ b/apps/files_reminders/composer/composer/installed.php
@@ -1,9 +1,9 @@
<?php return array(
'root' => array(
'name' => '__root__',
- 'pretty_version' => '1.0.0+no-version-set',
- 'version' => '1.0.0.0',
- 'reference' => NULL,
+ 'pretty_version' => 'dev-master',
+ 'version' => 'dev-master',
+ 'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
@@ -11,9 +11,9 @@
),
'versions' => array(
'__root__' => array(
- 'pretty_version' => '1.0.0+no-version-set',
- 'version' => '1.0.0.0',
- 'reference' => NULL,
+ 'pretty_version' => 'dev-master',
+ 'version' => 'dev-master',
+ 'reference' => 'cce2e1543b16a04e6b9fc1ba3f89fbc47f12e773',
'type' => 'library',
'install_path' => __DIR__ . '/../',
'aliases' => array(),
diff --git a/apps/files_reminders/lib/AppInfo/Application.php b/apps/files_reminders/lib/AppInfo/Application.php
index 4d418562ef5..1e4813e1ec7 100644
--- a/apps/files_reminders/lib/AppInfo/Application.php
+++ b/apps/files_reminders/lib/AppInfo/Application.php
@@ -26,11 +26,13 @@ declare(strict_types=1);
namespace OCA\FilesReminders\AppInfo;
+use OCA\FilesReminders\Listener\NodeDeletedListener;
use OCA\FilesReminders\Notification\Notifier;
use OCP\AppFramework\App;
use OCP\AppFramework\Bootstrap\IBootContext;
use OCP\AppFramework\Bootstrap\IBootstrap;
use OCP\AppFramework\Bootstrap\IRegistrationContext;
+use OCP\Files\Events\Node\NodeDeletedEvent;
class Application extends App implements IBootstrap {
public const APP_ID = 'files_reminders';
@@ -44,5 +46,6 @@ class Application extends App implements IBootstrap {
public function register(IRegistrationContext $context): void {
$context->registerNotifierService(Notifier::class);
+ $context->registerEventListener(NodeDeletedEvent::class, NodeDeletedListener::class);
}
}
diff --git a/apps/files_reminders/lib/Db/ReminderMapper.php b/apps/files_reminders/lib/Db/ReminderMapper.php
index cb079320e5f..97f7ed0900b 100644
--- a/apps/files_reminders/lib/Db/ReminderMapper.php
+++ b/apps/files_reminders/lib/Db/ReminderMapper.php
@@ -29,6 +29,7 @@ namespace OCA\FilesReminders\Db;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\Files\Node;
use OCP\IDBConnection;
use OCP\IUser;
@@ -108,6 +109,20 @@ class ReminderMapper extends QBMapper {
/**
* @return Reminder[]
*/
+ public function findAllForNode(Node $node) {
+ $qb = $this->db->getQueryBuilder();
+
+ $qb->select('id', 'user_id', 'file_id', 'due_date', 'updated_at', 'created_at', 'notified')
+ ->from($this->getTableName())
+ ->where($qb->expr()->eq('file_id', $qb->createNamedParameter($node->getId(), IQueryBuilder::PARAM_INT)))
+ ->orderBy('due_date', 'ASC');
+
+ return $this->findEntities($qb);
+ }
+
+ /**
+ * @return Reminder[]
+ */
public function findOverdue() {
$qb = $this->db->getQueryBuilder();
diff --git a/apps/files_reminders/lib/Listener/NodeDeletedListener.php b/apps/files_reminders/lib/Listener/NodeDeletedListener.php
new file mode 100644
index 00000000000..88aed08bba8
--- /dev/null
+++ b/apps/files_reminders/lib/Listener/NodeDeletedListener.php
@@ -0,0 +1,47 @@
+<?php
+
+declare(strict_types=1);
+
+/**
+ * @copyright 2023 Christopher Ng <chrng8@gmail.com>
+ *
+ * @author Christopher Ng <chrng8@gmail.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+
+namespace OCA\FilesReminders\Listener;
+
+use OCA\FilesReminders\Service\ReminderService;
+use OCP\EventDispatcher\Event;
+use OCP\EventDispatcher\IEventListener;
+use OCP\Files\Events\Node\NodeDeletedEvent;
+
+class NodeDeletedListener implements IEventListener {
+ public function __construct(
+ private ReminderService $reminderService,
+ ) {}
+
+ public function handle(Event $event): void {
+ if (!($event instanceof NodeDeletedEvent)) {
+ return;
+ }
+
+ $node = $event->getNode();
+ $this->reminderService->removeAllForNode($node);
+ }
+}
diff --git a/apps/files_reminders/lib/Service/ReminderService.php b/apps/files_reminders/lib/Service/ReminderService.php
index 8dbec6d5df7..eec2f1780bd 100644
--- a/apps/files_reminders/lib/Service/ReminderService.php
+++ b/apps/files_reminders/lib/Service/ReminderService.php
@@ -36,6 +36,7 @@ use OCA\FilesReminders\Exception\UserNotFoundException;
use OCA\FilesReminders\Model\RichReminder;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\Files\IRootFolder;
+use OCP\Files\Node;
use OCP\IURLGenerator;
use OCP\IUser;
use OCP\IUserManager;
@@ -117,6 +118,13 @@ class ReminderService {
$this->reminderMapper->delete($reminder);
}
+ public function removeAllForNode(Node $node): void {
+ $reminders = $this->reminderMapper->findAllForNode($node);
+ foreach ($reminders as $reminder) {
+ $this->reminderMapper->delete($reminder);
+ }
+ }
+
/**
* @throws DoesNotExistException
* @throws UserNotFoundException