diff --git a/lib/Command/ClearPreviews.php b/lib/Command/ClearPreviews.php index 81ca8d365..25622fe2c 100644 --- a/lib/Command/ClearPreviews.php +++ b/lib/Command/ClearPreviews.php @@ -8,20 +8,18 @@ namespace OCA\Bookmarks\Command; +use OCA\Bookmarks\Db\BookmarkMapper; use OCA\Bookmarks\Service\FileCache; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class ClearPreviews extends Command { - /** - * @var FileCache - */ - private $fileCache; - - public function __construct(FileCache $fileCache) { + public function __construct( + private FileCache $fileCache, + private BookmarkMapper $bookmarkMapper, + ) { parent::__construct(); - $this->fileCache = $fileCache; } /** @@ -45,6 +43,7 @@ protected function configure() { protected function execute(InputInterface $input, OutputInterface $output): int { try { $this->fileCache->clear(); + $this->bookmarkMapper->clearLastPreviews(); } catch (\Exception $ex) { $output->writeln('Failed to clear previews'); $output->writeln($ex->getMessage()); diff --git a/lib/Db/BookmarkMapper.php b/lib/Db/BookmarkMapper.php index e6f5b47b3..5deaae38c 100644 --- a/lib/Db/BookmarkMapper.php +++ b/lib/Db/BookmarkMapper.php @@ -724,12 +724,24 @@ public function findPendingPreviews(int $limit, int $stalePeriod): array { return $this->findEntities($qb); } + /** + * @return void + * @throws Exception + */ + public function clearLastPreviews(): void { + $qb = $this->db->getQueryBuilder(); + $qb->update('bookmarks'); + $qb->set('last_preview', $qb->createNamedParameter(0)); + $qb->executeStatement(); + } + /** * @psalm-param Bookmark $entity * @param Entity $entity * * @return Bookmark * @psalm-return Bookmark + * @throws Exception */ public function delete(Entity $entity): Bookmark { $this->eventDispatcher->dispatch(