Skip to content

Commit 79e4147

Browse files
kesselbbackportbot[bot]
authored andcommitted
feat: add command to clear contacts photo cache
Signed-off-by: Daniel Kesselberg <mail@danielkesselberg.de>
1 parent 6f36ace commit 79e4147

File tree

4 files changed

+78
-0
lines changed

4 files changed

+78
-0
lines changed

apps/dav/appinfo/info.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@
5656

5757
<commands>
5858
<command>OCA\DAV\Command\ClearCalendarUnshares</command>
59+
<command>OCA\DAV\Command\ClearContactsPhotoCache</command>
5960
<command>OCA\DAV\Command\CreateAddressBook</command>
6061
<command>OCA\DAV\Command\CreateCalendar</command>
6162
<command>OCA\DAV\Command\CreateSubscription</command>

apps/dav/composer/composer/autoload_classmap.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -155,6 +155,7 @@
155155
'OCA\\DAV\\CardDAV\\Validation\\CardDavValidatePlugin' => $baseDir . '/../lib/CardDAV/Validation/CardDavValidatePlugin.php',
156156
'OCA\\DAV\\CardDAV\\Xml\\Groups' => $baseDir . '/../lib/CardDAV/Xml/Groups.php',
157157
'OCA\\DAV\\Command\\ClearCalendarUnshares' => $baseDir . '/../lib/Command/ClearCalendarUnshares.php',
158+
'OCA\\DAV\\Command\\ClearContactsPhotoCache' => $baseDir . '/../lib/Command/ClearContactsPhotoCache.php',
158159
'OCA\\DAV\\Command\\CreateAddressBook' => $baseDir . '/../lib/Command/CreateAddressBook.php',
159160
'OCA\\DAV\\Command\\CreateCalendar' => $baseDir . '/../lib/Command/CreateCalendar.php',
160161
'OCA\\DAV\\Command\\CreateSubscription' => $baseDir . '/../lib/Command/CreateSubscription.php',

apps/dav/composer/composer/autoload_static.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -170,6 +170,7 @@ class ComposerStaticInitDAV
170170
'OCA\\DAV\\CardDAV\\Validation\\CardDavValidatePlugin' => __DIR__ . '/..' . '/../lib/CardDAV/Validation/CardDavValidatePlugin.php',
171171
'OCA\\DAV\\CardDAV\\Xml\\Groups' => __DIR__ . '/..' . '/../lib/CardDAV/Xml/Groups.php',
172172
'OCA\\DAV\\Command\\ClearCalendarUnshares' => __DIR__ . '/..' . '/../lib/Command/ClearCalendarUnshares.php',
173+
'OCA\\DAV\\Command\\ClearContactsPhotoCache' => __DIR__ . '/..' . '/../lib/Command/ClearContactsPhotoCache.php',
173174
'OCA\\DAV\\Command\\CreateAddressBook' => __DIR__ . '/..' . '/../lib/Command/CreateAddressBook.php',
174175
'OCA\\DAV\\Command\\CreateCalendar' => __DIR__ . '/..' . '/../lib/Command/CreateCalendar.php',
175176
'OCA\\DAV\\Command\\CreateSubscription' => __DIR__ . '/..' . '/../lib/Command/CreateSubscription.php',
Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/**
6+
* SPDX-FileCopyrightText: 2025 Nextcloud GmbH and Nextcloud contributors
7+
* SPDX-License-Identifier: AGPL-3.0-or-later
8+
*/
9+
10+
namespace OCA\DAV\Command;
11+
12+
use OCP\Files\AppData\IAppDataFactory;
13+
use OCP\Files\NotPermittedException;
14+
use Symfony\Component\Console\Attribute\AsCommand;
15+
use Symfony\Component\Console\Command\Command;
16+
use Symfony\Component\Console\Helper\ProgressBar;
17+
use Symfony\Component\Console\Helper\QuestionHelper;
18+
use Symfony\Component\Console\Input\InputInterface;
19+
use Symfony\Component\Console\Output\OutputInterface;
20+
use Symfony\Component\Console\Question\ConfirmationQuestion;
21+
22+
#[AsCommand(
23+
name: 'dav:clear-contacts-photo-cache',
24+
description: 'Clear cached contact photos',
25+
hidden: false,
26+
)]
27+
class ClearContactsPhotoCache extends Command {
28+
29+
public function __construct(
30+
private IAppDataFactory $appDataFactory,
31+
) {
32+
parent::__construct();
33+
}
34+
35+
protected function execute(InputInterface $input, OutputInterface $output): int {
36+
$photoCacheAppData = $this->appDataFactory->get('dav-photocache');
37+
38+
$folders = $photoCacheAppData->getDirectoryListing();
39+
$countFolders = count($folders);
40+
41+
if ($countFolders === 0) {
42+
$output->writeln('No cached contact photos found.');
43+
return self::SUCCESS;
44+
}
45+
46+
$output->writeln('Found ' . count($folders) . ' cached contact photos.');
47+
48+
/** @var QuestionHelper $helper */
49+
$helper = $this->getHelper('question');
50+
$question = new ConfirmationQuestion('Please confirm to clear the contacts photo cache [y/n] ', true);
51+
52+
if ($helper->ask($input, $output, $question) === false) {
53+
$output->writeln('Clearing the contacts photo cache aborted.');
54+
return self::SUCCESS;
55+
}
56+
57+
$progressBar = new ProgressBar($output, $countFolders);
58+
$progressBar->start();
59+
60+
foreach ($folders as $folder) {
61+
try {
62+
$folder->delete();
63+
} catch (NotPermittedException) {
64+
}
65+
$progressBar->advance();
66+
}
67+
68+
$progressBar->finish();
69+
70+
$output->writeln('');
71+
$output->writeln('Contacts photo cache cleared.');
72+
73+
return self::SUCCESS;
74+
}
75+
}

0 commit comments

Comments
 (0)