diff options
author | Morris Jobke <hey@morrisjobke.de> | 2019-02-07 17:08:05 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-02-07 17:08:05 +0100 |
commit | fc7f04807ce3209740a017148c4d63e3f1df5993 (patch) | |
tree | 375c04d0be5a6a5f574134caff5bdb61ce079854 /lib/private | |
parent | c5dc9b57ae47ac8b111abc0bb4e8ddadbecffbf5 (diff) | |
parent | 11a27b247fefb8739ecfcaf5ba5a3c70e364197d (diff) | |
download | nextcloud-server-fc7f04807ce3209740a017148c4d63e3f1df5993.tar.gz nextcloud-server-fc7f04807ce3209740a017148c4d63e3f1df5993.zip |
Merge pull request #13986 from nextcloud/feature/cleanup-job-13843
Repair step to remove "photo." files created by photocache
Diffstat (limited to 'lib/private')
-rw-r--r-- | lib/private/Repair.php | 12 | ||||
-rw-r--r-- | lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php | 104 |
2 files changed, 111 insertions, 5 deletions
diff --git a/lib/private/Repair.php b/lib/private/Repair.php index 641475cf386..2ab3a57e824 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -30,14 +30,11 @@ namespace OC; -use OCP\AppFramework\QueryException; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; use OC\Avatar\AvatarManager; use OC\Repair\AddCleanupUpdaterBackupsJob; use OC\Repair\CleanTags; -use OC\Repair\ClearGeneratedAvatarCache; use OC\Repair\ClearFrontendCaches; +use OC\Repair\ClearGeneratedAvatarCache; use OC\Repair\Collation; use OC\Repair\MoveUpdaterStepFile; use OC\Repair\NC11\FixMountStorages; @@ -46,6 +43,7 @@ use OC\Repair\NC13\RepairInvalidPaths; use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; use OC\Repair\NC14\RepairPendingCronJobs; use OC\Repair\NC15\SetVcardDatabaseUID; +use OC\Repair\NC16\CleanupCardDAVPhotoCache; use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\DropAccountTermsTable; use OC\Repair\Owncloud\SaveAccountsTableData; @@ -55,6 +53,9 @@ use OC\Repair\RepairMimeTypes; use OC\Repair\SqliteAutoincrement; use OC\Template\JSCombiner; use OC\Template\SCSSCacher; +use OCP\AppFramework\QueryException; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; use Symfony\Component\EventDispatcher\EventDispatcher; use Symfony\Component\EventDispatcher\GenericEvent; @@ -147,7 +148,8 @@ class Repair implements IOutput { new AddPreviewBackgroundCleanupJob(\OC::$server->getJobList()), new AddCleanupUpdaterBackupsJob(\OC::$server->getJobList()), new RepairPendingCronJobs(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), - new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger()) + new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getLogger()), + new CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), ]; } diff --git a/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php new file mode 100644 index 00000000000..c9c7b5cf1c0 --- /dev/null +++ b/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php @@ -0,0 +1,104 @@ +<?php +declare(strict_types=1); +/** + * @copyright Copyright (c) 2019, Daniel Kesselberg (mail@danielkesselberg.de) + * + * @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 OC\Repair\NC16; + +use OCP\Files\IAppData; +use OCP\Files\NotFoundException; +use OCP\Files\SimpleFS\ISimpleFolder; +use OCP\IConfig; +use OCP\ILogger; +use OCP\Migration\IOutput; +use OCP\Migration\IRepairStep; + +/** + * Class CleanupCardDAVPhotoCache + * + * This repair step removes "photo." files created by photocache + * + * Before https://github.com/nextcloud/server/pull/13843 a "photo." file could be created + * for unsupported image formats by photocache. Because a file is present but not jpg, png or gif no + * photo could be returned for this vcard. These invalid files are removed by this migration step. + */ +class CleanupCardDAVPhotoCache implements IRepairStep { + + /** @var IConfig */ + private $config; + + /** @var IAppData */ + private $appData; + + /** @var ILogger */ + private $logger; + + public function __construct(IConfig $config, IAppData $appData, ILogger $logger) { + $this->config = $config; + $this->appData = $appData; + $this->logger = $logger; + } + + public function getName(): string { + return 'Cleanup invalid photocache files for carddav'; + } + + private function repair(IOutput $output): void { + try { + $folders = $this->appData->getDirectoryListing(); + } catch (NotFoundException $e) { + return; + } + + $folders = array_filter($folders, function (ISimpleFolder $folder) { + return $folder->fileExists('photo.'); + }); + + if (empty($folders)) { + return; + } + + $output->info('Delete ' . count($folders) . ' "photo." files'); + + foreach ($folders as $folder) { + try { + /** @var ISimpleFolder $folder */ + $folder->getFile('photo.')->delete(); + } catch (\Exception $e) { + $this->logger->logException($e); + $output->warning('Could not delete file "dav-photocache/' . $folder->getName() . '/photo."'); + } + } + } + + private function shouldRun(): bool { + return version_compare( + $this->config->getSystemValue('version', '0.0.0.0'), + '16.0.0.0', + '<=' + ); + } + + public function run(IOutput $output): void { + if ($this->shouldRun()) { + $this->repair($output); + } + } +} |