Skip to content

Commit

Permalink
Merge pull request #39876 from nextcloud/fix/files-reminders
Browse files Browse the repository at this point in the history
  • Loading branch information
Pytal authored Aug 15, 2023
2 parents 892f770 + be6c4c4 commit 3c13efd
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
9 changes: 5 additions & 4 deletions apps/files_reminders/lib/Command/ListCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,10 +77,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
}

$reminders = $this->reminderService->getAll($user ?? null);
if (empty($reminders)) {
$io->text('No reminders');
return 0;
}

$outputOption = $input->getOption('output');
switch ($outputOption) {
Expand All @@ -97,6 +93,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
);
return 0;
default:
if (empty($reminders)) {
$io->text('No reminders');
return 0;
}

$io->table(
['User Id', 'File Id', 'Path', 'Due Date', 'Updated At', 'Created At', 'Notified'],
array_map(
Expand Down
4 changes: 4 additions & 0 deletions apps/files_reminders/lib/Controller/ApiController.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@
use OCA\FilesReminders\Service\ReminderService;
use OCP\AppFramework\Db\DoesNotExistException;
use OCP\AppFramework\Http;
use OCP\AppFramework\Http\Attribute\NoAdminRequired;
use OCP\AppFramework\Http\DataResponse;
use OCP\AppFramework\OCSController;
use OCP\IRequest;
Expand All @@ -54,6 +55,7 @@ public function __construct(
/**
* Get a reminder
*/
#[NoAdminRequired]
public function get(int $fileId): DataResponse {
$user = $this->userSession->getUser();
if ($user === null) {
Expand All @@ -79,6 +81,7 @@ public function get(int $fileId): DataResponse {
*
* @param string $dueDate ISO 8601 formatted date time string
*/
#[NoAdminRequired]
public function set(int $fileId, string $dueDate): DataResponse {
try {
$dueDate = (new DateTime($dueDate))->setTimezone(new DateTimeZone('UTC'));
Expand Down Expand Up @@ -106,6 +109,7 @@ public function set(int $fileId, string $dueDate): DataResponse {
/**
* Remove a reminder
*/
#[NoAdminRequired]
public function remove(int $fileId): DataResponse {
$user = $this->userSession->getUser();
if ($user === null) {
Expand Down
9 changes: 8 additions & 1 deletion apps/files_reminders/lib/Db/ReminderMapper.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
use OCP\AppFramework\Db\QBMapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\Files\Node;
use OCP\Files\NotFoundException;
use OCP\IDBConnection;
use OCP\IUser;

Expand Down Expand Up @@ -111,11 +112,17 @@ public function findAllForUser(IUser $user) {
* @return Reminder[]
*/
public function findAllForNode(Node $node) {
try {
$nodeId = $node->getId();
} catch (NotFoundException $e) {
return [];
}

$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)))
->where($qb->expr()->eq('file_id', $qb->createNamedParameter($nodeId, IQueryBuilder::PARAM_INT)))
->orderBy('due_date', 'ASC');

return $this->findEntities($qb);
Expand Down
6 changes: 0 additions & 6 deletions apps/files_reminders/lib/Listener/NodeDeletedListener.php
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@

namespace OCA\FilesReminders\Listener;

use OC\Files\Node\NonExistingFile;
use OC\Files\Node\NonExistingFolder;
use OCA\FilesReminders\Service\ReminderService;
use OCP\EventDispatcher\Event;
use OCP\EventDispatcher\IEventListener;
Expand All @@ -44,10 +42,6 @@ public function handle(Event $event): void {
}

$node = $event->getNode();
if ($node instanceof NonExistingFile || $node instanceof NonExistingFolder) {
return;
}

$this->reminderService->removeAllForNode($node);
}
}

0 comments on commit 3c13efd

Please sign in to comment.