Browse Source

feat: add command to clear contacts photo cache

Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
pull/52995/head
Daniel Kesselberg 7 months ago
parent
commit
da4b6ce20b
No known key found for this signature in database GPG Key ID: 4A81C29F63464E8F
  1. 1
      apps/dav/appinfo/info.xml
  2. 1
      apps/dav/composer/composer/autoload_classmap.php
  3. 1
      apps/dav/composer/composer/autoload_static.php
  4. 75
      apps/dav/lib/Command/ClearContactsPhotoCache.php

1
apps/dav/appinfo/info.xml

@ -55,6 +55,7 @@
</repair-steps>
<commands>
<command>OCA\DAV\Command\ClearContactsPhotoCache</command>
<command>OCA\DAV\Command\CreateAddressBook</command>
<command>OCA\DAV\Command\CreateCalendar</command>
<command>OCA\DAV\Command\DeleteCalendar</command>

1
apps/dav/composer/composer/autoload_classmap.php

@ -154,6 +154,7 @@ return array(
'OCA\\DAV\\CardDAV\\UserAddressBooks' => $baseDir . '/../lib/CardDAV/UserAddressBooks.php',
'OCA\\DAV\\CardDAV\\Validation\\CardDavValidatePlugin' => $baseDir . '/../lib/CardDAV/Validation/CardDavValidatePlugin.php',
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php',
'OCA\\DAV\\Command\\ClearContactsPhotoCache' => $baseDir . '/../lib/Command/ClearContactsPhotoCache.php',
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php',
'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php',
'OCA\\DAV\\Command\\DeleteCalendar' => $baseDir . '/../lib/Command/DeleteCalendar.php',

1
apps/dav/composer/composer/autoload_static.php

@ -169,6 +169,7 @@ class ComposerStaticInitDAV
'OCA\\DAV\\CardDAV\\UserAddressBooks' => __DIR__ . '/..' . '/../lib/CardDAV/UserAddressBooks.php',
'OCA\\DAV\\CardDAV\\Validation\\CardDavValidatePlugin' => __DIR__ . '/..' . '/../lib/CardDAV/Validation/CardDavValidatePlugin.php',
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php',
'OCA\\DAV\\Command\\ClearContactsPhotoCache' => __DIR__ . '/..' . '/../lib/Command/ClearContactsPhotoCache.php',
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php',
'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php',
'OCA\\DAV\\Command\\DeleteCalendar' => __DIR__ . '/..' . '/../lib/Command/DeleteCalendar.php',

75
apps/dav/lib/Command/ClearContactsPhotoCache.php

@ -0,0 +1,75 @@
<?php
declare(strict_types=1);
/**
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
*/
namespace OCA\DAV\Command;
use OCP\Files\AppData\IAppDataFactory;
use OCP\Files\NotPermittedException;
use Symfony\Component\Console\Attribute\AsCommand;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Helper\ProgressBar;
use Symfony\Component\Console\Helper\QuestionHelper;
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
#[AsCommand(
name: 'dav:clear-contacts-photo-cache',
description: 'Clear cached contact photos',
hidden: false,
)]
class ClearContactsPhotoCache extends Command {
public function __construct(
private IAppDataFactory $appDataFactory,
) {
parent::__construct();
}
protected function execute(InputInterface $input, OutputInterface $output): int {
$photoCacheAppData = $this->appDataFactory->get('dav-photocache');
$folders = $photoCacheAppData->getDirectoryListing();
$countFolders = count($folders);
if ($countFolders === 0) {
$output->writeln('No cached contact photos found.');
return self::SUCCESS;
}
$output->writeln('Found ' . count($folders) . ' cached contact photos.');
/** @var QuestionHelper $helper */
$helper = $this->getHelper('question');
$question = new ConfirmationQuestion('Please confirm to clear the contacts photo cache [y/n] ', true);
if ($helper->ask($input, $output, $question) === false) {
$output->writeln('Clearing the contacts photo cache aborted.');
return self::SUCCESS;
}
$progressBar = new ProgressBar($output, $countFolders);
$progressBar->start();
foreach ($folders as $folder) {
try {
$folder->delete();
} catch (NotPermittedException) {
}
$progressBar->advance();
}
$progressBar->finish();
$output->writeln('');
$output->writeln('Contacts photo cache cleared.');
return self::SUCCESS;
}
}
Loading…
Cancel
Save