mirror of
https://github.com/nextcloud/server.git
synced 2026-05-28 04:32:30 -04:00
enh: handle node deleted
Signed-off-by: Christopher Ng <chrng8@gmail.com>
This commit is contained in:
parent
7617519502
commit
f865c3ad21
7 changed files with 81 additions and 6 deletions
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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',
|
||||
|
|
|
|||
|
|
@ -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(),
|
||||
|
|
|
|||
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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;
|
||||
|
||||
|
|
@ -105,6 +106,20 @@ class ReminderMapper extends QBMapper {
|
|||
return $this->findEntities($qb);
|
||||
}
|
||||
|
||||
/**
|
||||
* @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[]
|
||||
*/
|
||||
|
|
|
|||
47
apps/files_reminders/lib/Listener/NodeDeletedListener.php
Normal file
47
apps/files_reminders/lib/Listener/NodeDeletedListener.php
Normal file
|
|
@ -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);
|
||||
}
|
||||
}
|
||||
|
|
@ -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
|
||||
|
|
|
|||
Loading…
Reference in a new issue