diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 356861ed57..300e3df912 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -1059,10 +1059,7 @@ return array( 'OC\\Repair\\MoveUpdaterStepFile' => $baseDir . '/lib/private/Repair/MoveUpdaterStepFile.php', 'OC\\Repair\\NC11\\FixMountStorages' => $baseDir . '/lib/private/Repair/NC11/FixMountStorages.php', 'OC\\Repair\\NC13\\AddLogRotateJob' => $baseDir . '/lib/private/Repair/NC13/AddLogRotateJob.php', - 'OC\\Repair\\NC13\\RepairInvalidPaths' => $baseDir . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => $baseDir . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', - 'OC\\Repair\\NC14\\RepairPendingCronJobs' => $baseDir . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', - 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => $baseDir . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\NC16\\AddClenupLoginFlowV2BackgroundJob' => $baseDir . '/lib/private/Repair/NC16/AddClenupLoginFlowV2BackgroundJob.php', 'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => $baseDir . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php', 'OC\\Repair\\NC16\\RemoveCypressFiles' => $baseDir . '/lib/private/Repair/NC16/RemoveCypressFiles.php', @@ -1070,7 +1067,6 @@ return array( 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => $baseDir . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => $baseDir . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', 'OC\\Repair\\RemoveLinkShares' => $baseDir . '/lib/private/Repair/RemoveLinkShares.php', - 'OC\\Repair\\RemoveRootShares' => $baseDir . '/lib/private/Repair/RemoveRootShares.php', 'OC\\Repair\\RepairInvalidShares' => $baseDir . '/lib/private/Repair/RepairInvalidShares.php', 'OC\\Repair\\RepairMimeTypes' => $baseDir . '/lib/private/Repair/RepairMimeTypes.php', 'OC\\Repair\\SqliteAutoincrement' => $baseDir . '/lib/private/Repair/SqliteAutoincrement.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index f19eb7ce00..9df8b8769d 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -1093,10 +1093,7 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Repair\\MoveUpdaterStepFile' => __DIR__ . '/../../..' . '/lib/private/Repair/MoveUpdaterStepFile.php', 'OC\\Repair\\NC11\\FixMountStorages' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/FixMountStorages.php', 'OC\\Repair\\NC13\\AddLogRotateJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/AddLogRotateJob.php', - 'OC\\Repair\\NC13\\RepairInvalidPaths' => __DIR__ . '/../../..' . '/lib/private/Repair/NC13/RepairInvalidPaths.php', 'OC\\Repair\\NC14\\AddPreviewBackgroundCleanupJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/AddPreviewBackgroundCleanupJob.php', - 'OC\\Repair\\NC14\\RepairPendingCronJobs' => __DIR__ . '/../../..' . '/lib/private/Repair/NC14/RepairPendingCronJobs.php', - 'OC\\Repair\\NC15\\SetVcardDatabaseUID' => __DIR__ . '/../../..' . '/lib/private/Repair/NC15/SetVcardDatabaseUID.php', 'OC\\Repair\\NC16\\AddClenupLoginFlowV2BackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/AddClenupLoginFlowV2BackgroundJob.php', 'OC\\Repair\\NC16\\CleanupCardDAVPhotoCache' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/CleanupCardDAVPhotoCache.php', 'OC\\Repair\\NC16\\RemoveCypressFiles' => __DIR__ . '/../../..' . '/lib/private/Repair/NC16/RemoveCypressFiles.php', @@ -1104,7 +1101,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Repair\\Owncloud\\DropAccountTermsTable' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/DropAccountTermsTable.php', 'OC\\Repair\\Owncloud\\SaveAccountsTableData' => __DIR__ . '/../../..' . '/lib/private/Repair/Owncloud/SaveAccountsTableData.php', 'OC\\Repair\\RemoveLinkShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveLinkShares.php', - 'OC\\Repair\\RemoveRootShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveRootShares.php', 'OC\\Repair\\RepairInvalidShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairInvalidShares.php', 'OC\\Repair\\RepairMimeTypes' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairMimeTypes.php', 'OC\\Repair\\SqliteAutoincrement' => __DIR__ . '/../../..' . '/lib/private/Repair/SqliteAutoincrement.php', diff --git a/lib/private/Repair.php b/lib/private/Repair.php index fa89e95e9f..4fbc89835c 100644 --- a/lib/private/Repair.php +++ b/lib/private/Repair.php @@ -39,10 +39,7 @@ use OC\Repair\Collation; use OC\Repair\MoveUpdaterStepFile; use OC\Repair\NC11\FixMountStorages; use OC\Repair\NC13\AddLogRotateJob; -use OC\Repair\NC13\RepairInvalidPaths; use OC\Repair\NC14\AddPreviewBackgroundCleanupJob; -use OC\Repair\NC14\RepairPendingCronJobs; -use OC\Repair\NC15\SetVcardDatabaseUID; use OC\Repair\NC16\AddClenupLoginFlowV2BackgroundJob; use OC\Repair\NC16\CleanupCardDAVPhotoCache; use OC\Repair\NC16\RemoveCypressFiles; @@ -50,7 +47,6 @@ use OC\Repair\OldGroupMembershipShares; use OC\Repair\Owncloud\DropAccountTermsTable; use OC\Repair\Owncloud\SaveAccountsTableData; use OC\Repair\RemoveLinkShares; -use OC\Repair\RemoveRootShares; use OC\Repair\RepairInvalidShares; use OC\Repair\RepairMimeTypes; use OC\Repair\SqliteAutoincrement; @@ -142,17 +138,13 @@ class Repair implements IOutput { new RepairMimeTypes(\OC::$server->getConfig()), new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()), new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()), - new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()), new MoveUpdaterStepFile(\OC::$server->getConfig()), new FixMountStorages(\OC::$server->getDatabaseConnection()), - new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig()), new AddLogRotateJob(\OC::$server->getJobList()), new ClearFrontendCaches(\OC::$server->getMemCacheFactory(), \OC::$server->query(SCSSCacher::class), \OC::$server->query(JSCombiner::class)), new ClearGeneratedAvatarCache(\OC::$server->getConfig(), \OC::$server->query(AvatarManager::class)), 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 CleanupCardDAVPhotoCache(\OC::$server->getConfig(), \OC::$server->getAppDataDir('dav-photocache'), \OC::$server->getLogger()), new AddClenupLoginFlowV2BackgroundJob(\OC::$server->getJobList()), new RemoveLinkShares(\OC::$server->getDatabaseConnection(), \OC::$server->getConfig(), \OC::$server->getGroupManager(), \OC::$server->getNotificationManager(), \OC::$server->query(ITimeFactory::class)), diff --git a/lib/private/Repair/NC13/RepairInvalidPaths.php b/lib/private/Repair/NC13/RepairInvalidPaths.php deleted file mode 100644 index 941224012a..0000000000 --- a/lib/private/Repair/NC13/RepairInvalidPaths.php +++ /dev/null @@ -1,197 +0,0 @@ - - * - * @author Joas Schilling - * @author Lukas Reschke - * @author Morris Jobke - * @author Robin Appelman - * - * @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 . - * - */ - -namespace OC\Repair\NC13; - - -use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; - -class RepairInvalidPaths implements IRepairStep { - const MAX_ROWS = 1000; - - /** @var IDBConnection */ - private $connection; - /** @var IConfig */ - private $config; - - private $getIdQuery; - private $updateQuery; - private $reparentQuery; - private $deleteQuery; - - public function __construct(IDBConnection $connection, IConfig $config) { - $this->connection = $connection; - $this->config = $config; - } - - - public function getName() { - return 'Repair invalid paths in file cache'; - } - - /** - * @return \Generator - * @suppress SqlInjectionChecker - */ - private function getInvalidEntries() { - $builder = $this->connection->getQueryBuilder(); - - $computedPath = $builder->func()->concat( - 'p.path', - $builder->func()->concat($builder->createNamedParameter('/'), 'f.name') - ); - - //select f.path, f.parent,p.path from oc_filecache f inner join oc_filecache p on f.parent=p.fileid and p.path!='' where f.path != p.path || '/' || f.name; - $builder->select('f.fileid', 'f.path', 'f.name', 'f.parent', 'f.storage') - ->selectAlias('p.path', 'parent_path') - ->selectAlias('p.storage', 'parent_storage') - ->from('filecache', 'f') - ->innerJoin('f', 'filecache', 'p', $builder->expr()->andX( - $builder->expr()->eq('f.parent', 'p.fileid'), - $builder->expr()->nonEmptyString('p.name') - )) - ->where($builder->expr()->neq('f.path', $computedPath)) - ->setMaxResults(self::MAX_ROWS); - - do { - $result = $builder->execute(); - $rows = $result->fetchAll(); - foreach ($rows as $row) { - yield $row; - } - $result->closeCursor(); - } while (count($rows) > 0); - } - - private function getId($storage, $path) { - if (!$this->getIdQuery) { - $builder = $this->connection->getQueryBuilder(); - - $this->getIdQuery = $builder->select('fileid') - ->from('filecache') - ->where($builder->expr()->eq('storage', $builder->createParameter('storage'))) - ->andWhere($builder->expr()->eq('path_hash', $builder->createParameter('path_hash'))); - } - - $this->getIdQuery->setParameter('storage', $storage, IQueryBuilder::PARAM_INT); - $this->getIdQuery->setParameter('path_hash', md5($path)); - - return $this->getIdQuery->execute()->fetchColumn(); - } - - /** - * @param string $fileid - * @param string $newPath - * @param string $newStorage - * @suppress SqlInjectionChecker - */ - private function update($fileid, $newPath, $newStorage) { - if (!$this->updateQuery) { - $builder = $this->connection->getQueryBuilder(); - - $this->updateQuery = $builder->update('filecache') - ->set('path', $builder->createParameter('newpath')) - ->set('path_hash', $builder->func()->md5($builder->createParameter('newpath'))) - ->set('storage', $builder->createParameter('newstorage')) - ->where($builder->expr()->eq('fileid', $builder->createParameter('fileid'))); - } - - $this->updateQuery->setParameter('newpath', $newPath); - $this->updateQuery->setParameter('newstorage', $newStorage); - $this->updateQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT); - - $this->updateQuery->execute(); - } - - private function reparent($from, $to) { - if (!$this->reparentQuery) { - $builder = $this->connection->getQueryBuilder(); - - $this->reparentQuery = $builder->update('filecache') - ->set('parent', $builder->createParameter('to')) - ->where($builder->expr()->eq('fileid', $builder->createParameter('from'))); - } - - $this->reparentQuery->setParameter('from', $from); - $this->reparentQuery->setParameter('to', $to); - - $this->reparentQuery->execute(); - } - - private function delete($fileid) { - if (!$this->deleteQuery) { - $builder = $this->connection->getQueryBuilder(); - - $this->deleteQuery = $builder->delete('filecache') - ->where($builder->expr()->eq('fileid', $builder->createParameter('fileid'))); - } - - $this->deleteQuery->setParameter('fileid', $fileid, IQueryBuilder::PARAM_INT); - - $this->deleteQuery->execute(); - } - - private function repair() { - $this->connection->beginTransaction(); - $entries = $this->getInvalidEntries(); - $count = 0; - foreach ($entries as $entry) { - $count++; - $calculatedPath = $entry['parent_path'] . '/' . $entry['name']; - if ($newId = $this->getId($entry['parent_storage'], $calculatedPath)) { - // a new entry with the correct path has already been created, reuse that one and delete the incorrect entry - $this->reparent($entry['fileid'], $newId); - $this->delete($entry['fileid']); - } else { - $this->update($entry['fileid'], $calculatedPath, $entry['parent_storage']); - } - } - $this->connection->commit(); - return $count; - } - - private function shouldRun() { - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); - - // was added to 11.0.5.2, 12.0.0.30 and 13.0.0.1 - $shouldRun = version_compare($versionFromBeforeUpdate, '11.0.5.2', '<'); - $shouldRun |= version_compare($versionFromBeforeUpdate, '12.0.0.0', '>=') && version_compare($versionFromBeforeUpdate, '12.0.0.30', '<'); - $shouldRun |= version_compare($versionFromBeforeUpdate, '13.0.0.0', '=='); - return $shouldRun; - } - - public function run(IOutput $output) { - if ($this->shouldRun()) { - $count = $this->repair(); - - $output->info('Repaired ' . $count . ' paths'); - } - } -} diff --git a/lib/private/Repair/NC14/RepairPendingCronJobs.php b/lib/private/Repair/NC14/RepairPendingCronJobs.php deleted file mode 100644 index a8ca2c75e8..0000000000 --- a/lib/private/Repair/NC14/RepairPendingCronJobs.php +++ /dev/null @@ -1,77 +0,0 @@ - - * - * @author Morris Jobke - * - * @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 . - * - */ - -namespace OC\Repair\NC14; - -use OCP\DB\QueryBuilder\IQueryBuilder; -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; - -class RepairPendingCronJobs implements IRepairStep { - const MAX_ROWS = 1000; - - /** @var IDBConnection */ - private $connection; - /** @var IConfig */ - private $config; - - public function __construct(IDBConnection $connection, IConfig $config) { - $this->connection = $connection; - $this->config = $config; - } - - - public function getName() { - return 'Repair pending cron jobs'; - } - - private function shouldRun() { - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0'); - - return version_compare($versionFromBeforeUpdate, '14.0.0.9', '<'); - } - - /** - * @suppress SqlInjectionChecker - */ - private function repair() { - $reset = $this->connection->getQueryBuilder(); - $reset->update('jobs') - ->set('reserved_at', $reset->expr()->literal(0, IQueryBuilder::PARAM_INT)) - ->where($reset->expr()->neq('reserved_at', $reset->expr()->literal(0, IQueryBuilder::PARAM_INT))); - - return $reset->execute(); - } - - public function run(IOutput $output) { - if ($this->shouldRun()) { - $count = $this->repair(); - - $output->info('Repaired ' . $count . ' pending cron job(s).'); - } else { - $output->info('No need to repair pending cron jobs.'); - } - } -} diff --git a/lib/private/Repair/NC15/SetVcardDatabaseUID.php b/lib/private/Repair/NC15/SetVcardDatabaseUID.php deleted file mode 100644 index cefb1c1811..0000000000 --- a/lib/private/Repair/NC15/SetVcardDatabaseUID.php +++ /dev/null @@ -1,154 +0,0 @@ - - * - * @author John Molakvoæ - * - * @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 . - * - */ - -namespace OC\Repair\NC15; - -use OCP\IConfig; -use OCP\IDBConnection; -use OCP\ILogger; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; -use Sabre\VObject\Reader; -use Sabre\VObject\ParseException; - -class SetVcardDatabaseUID implements IRepairStep { - const MAX_ROWS = 1000; - - /** @var IDBConnection */ - private $connection; - - /** @var IConfig */ - private $config; - - /** @var ILogger */ - private $logger; - - private $updateQuery; - - public function __construct(IDBConnection $connection, IConfig $config, ILogger $logger) { - $this->connection = $connection; - $this->config = $config; - $this->logger = $logger; - } - - public function getName() { - return 'Extract the vcard uid and store it in the db'; - } - - /** - * @return \Generator - * @suppress SqlInjectionChecker - */ - private function getInvalidEntries() { - $builder = $this->connection->getQueryBuilder(); - - $builder->select('id', 'carddata') - ->from('cards') - ->where($builder->expr()->isNull('uid')) - ->setMaxResults(self::MAX_ROWS); - - do { - $result = $builder->execute(); - $rows = $result->fetchAll(); - foreach ($rows as $row) { - yield $row; - } - $result->closeCursor(); - } while (count($rows) > 0); - } - - /** - * Extract UID from vcard - * - * @param string $cardData the vcard raw data - * @param IOutput $output the output logger - * @return string the uid or empty if none - */ - private function getUID(string $cardData, IOutput $output): string { - try { - $vCard = Reader::read($cardData); - if ($vCard->UID) { - $uid = $vCard->UID->getValue(); - - return $uid; - } - } catch (ParseException $e) { - $output->warning('One vCard is broken. We logged the exception and will continue the repair.'); - $this->logger->logException($e); - } - - return ''; - } - - /** - * @param int $id - * @param string $uid - */ - private function update(int $id, string $uid) { - if (!$this->updateQuery) { - $builder = $this->connection->getQueryBuilder(); - - $this->updateQuery = $builder->update('cards') - ->set('uid', $builder->createParameter('uid')) - ->where($builder->expr()->eq('id', $builder->createParameter('id'))); - } - - $this->updateQuery->setParameter('id', $id); - $this->updateQuery->setParameter('uid', $uid); - - $this->updateQuery->execute(); - } - - private function repair(IOutput $output): int { - $this->connection->beginTransaction(); - $entries = $this->getInvalidEntries(); - $count = 0; - foreach ($entries as $entry) { - $count++; - $cardData = $entry['carddata']; - if (is_resource($cardData)) { - $cardData = stream_get_contents($cardData); - } - $uid = $this->getUID($cardData, $output); - $this->update($entry['id'], $uid); - } - $this->connection->commit(); - - return $count; - } - - private function shouldRun() { - $versionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0.0'); - - // was added to 15.0.0.2 - return version_compare($versionFromBeforeUpdate, '15.0.0.2', '<='); - } - - public function run(IOutput $output) { - if ($this->shouldRun()) { - $count = $this->repair($output); - - $output->info('Fixed ' . $count . ' vcards'); - } - } -} diff --git a/lib/private/Repair/RemoveRootShares.php b/lib/private/Repair/RemoveRootShares.php deleted file mode 100644 index a06105384f..0000000000 --- a/lib/private/Repair/RemoveRootShares.php +++ /dev/null @@ -1,142 +0,0 @@ - - * @author Roeland Jago Douma - * - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ -namespace OC\Repair; - -use OCP\Files\IRootFolder; -use OCP\IDBConnection; -use OCP\IUser; -use OCP\IUserManager; -use OCP\Migration\IOutput; -use OCP\Migration\IRepairStep; - -/** - * Class RemoveRootShares - * - * @package OC\Repair - */ -class RemoveRootShares implements IRepairStep { - - /** @var IDBConnection */ - protected $connection; - - /** @var IUserManager */ - protected $userManager; - - /** @var IRootFolder */ - protected $rootFolder; - - /** - * RemoveRootShares constructor. - * - * @param IDBConnection $connection - * @param IUserManager $userManager - * @param IRootFolder $rootFolder - */ - public function __construct(IDBConnection $connection, - IUserManager $userManager, - IRootFolder $rootFolder) { - $this->connection = $connection; - $this->userManager = $userManager; - $this->rootFolder = $rootFolder; - } - - /** - * @return string - */ - public function getName() { - return 'Remove shares of a users root folder'; - } - - /** - * @param IOutput $output - */ - public function run(IOutput $output) { - if ($this->rootSharesExist()) { - $this->removeRootShares($output); - } - } - - /** - * @param IOutput $output - */ - private function removeRootShares(IOutput $output) { - $function = function(IUser $user) use ($output) { - $userFolder = $this->rootFolder->getUserFolder($user->getUID()); - $fileId = $userFolder->getId(); - - $qb = $this->connection->getQueryBuilder(); - $qb->delete('share') - ->where($qb->expr()->eq('file_source', $qb->createNamedParameter($fileId))) - ->andWhere($qb->expr()->orX( - $qb->expr()->eq('item_type', $qb->expr()->literal('file')), - $qb->expr()->eq('item_type', $qb->expr()->literal('folder')) - )); - - $qb->execute(); - - $output->advance(); - }; - - $output->startProgress($this->userManager->countSeenUsers()); - - $this->userManager->callForSeenUsers($function); - - $output->finishProgress(); - } - - /** - * Verify if this repair steps is required - * It *should* not be necessary in most cases and it can be very - * costly. - * - * @return bool - */ - private function rootSharesExist() { - $qb = $this->connection->getQueryBuilder(); - $qb2 = $this->connection->getQueryBuilder(); - - $qb->select('fileid') - ->from('filecache') - ->where($qb->expr()->eq('path', $qb->expr()->literal('files'))); - - $qb2->select('id') - ->from('share') - ->where($qb2->expr()->in('file_source', $qb2->createFunction($qb->getSQL()))) - ->andWhere($qb2->expr()->orX( - $qb2->expr()->eq('item_type', $qb->expr()->literal('file')), - $qb2->expr()->eq('item_type', $qb->expr()->literal('folder')) - )) - ->setMaxResults(1); - - $cursor = $qb2->execute(); - $data = $cursor->fetch(); - $cursor->closeCursor(); - - if ($data === false) { - return false; - } - - return true; - } -} - diff --git a/tests/lib/Repair/RemoveRootSharesTest.php b/tests/lib/Repair/RemoveRootSharesTest.php deleted file mode 100644 index 9a4882bef2..0000000000 --- a/tests/lib/Repair/RemoveRootSharesTest.php +++ /dev/null @@ -1,197 +0,0 @@ - - * - * @copyright Copyright (c) 2016, ownCloud, Inc. - * @license AGPL-3.0 - * - * This code is free software: you can redistribute it and/or modify - * it under the terms of the GNU Affero General Public License, version 3, - * as published by the Free Software Foundation. - * - * 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, version 3, - * along with this program. If not, see - * - */ -namespace Test\Repair; - -use OC\Repair\RemoveRootShares; -use OCP\Files\IRootFolder; -use OCP\IDBConnection; -use OCP\IUserManager; -use OCP\Migration\IOutput; -use Test\Traits\UserTrait; - -/** - * Class RemoveOldSharesTest - * - * @package Test\Repair - * @group DB - */ -class RemoveRootSharesTest extends \Test\TestCase { - use UserTrait; - - /** @var RemoveRootShares */ - protected $repair; - - /** @var IDBConnection */ - protected $connection; - - /** @var IOutput */ - private $outputMock; - - /** @var IUserManager */ - private $userManager; - - /** @var IRootFolder */ - private $rootFolder; - - protected function setUp() { - parent::setUp(); - - $this->outputMock = $this->getMockBuilder('\OCP\Migration\IOutput') - ->disableOriginalConstructor() - ->getMock(); - - $this->userManager = \OC::$server->getUserManager(); - $this->rootFolder = \OC::$server->getRootFolder(); - - $this->connection = \OC::$server->getDatabaseConnection(); - $this->repair = new RemoveRootShares($this->connection, $this->userManager, $this->rootFolder); - } - - protected function tearDown() { - $qb = $this->connection->getQueryBuilder(); - $qb->delete('share'); - $qb->execute(); - - return parent::tearDown(); - } - - public function testRootSharesExist() { - //Add test user - $user = $this->userManager->createUser('test', 'test'); - $userFolder = $this->rootFolder->getUserFolder('test'); - $fileId = $userFolder->getId(); - - //Now insert cyclic share - $qb = $this->connection->getQueryBuilder(); - $qb->insert('share') - ->values([ - 'share_type' => $qb->createNamedParameter(0), - 'share_with' => $qb->createNamedParameter('foo'), - 'uid_owner' => $qb->createNamedParameter('owner'), - 'item_type' => $qb->createNamedParameter('file'), - 'item_source' => $qb->createNamedParameter($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $res = $this->invokePrivate($this->repair, 'rootSharesExist', []); - $this->assertTrue($res); - - $user->delete(); - } - - public function testRootSharesDontExist() { - //Add test user - $user = $this->userManager->createUser('test', 'test'); - $userFolder = $this->rootFolder->getUserFolder('test'); - $fileId = $userFolder->getId(); - $user->updateLastLoginTimestamp(); - - //Now insert cyclic share - $qb = $this->connection->getQueryBuilder(); - $qb->insert('share') - ->values([ - 'share_type' => $qb->createNamedParameter(0), - 'share_with' => $qb->createNamedParameter('foo'), - 'uid_owner' => $qb->createNamedParameter('owner'), - 'item_type' => $qb->createNamedParameter('file'), - 'item_source' => $qb->createNamedParameter($fileId+1), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId+1), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $res = $this->invokePrivate($this->repair, 'rootSharesExist', []); - $this->assertFalse($res); - - $user->delete(); - } - - public function testRun() { - //Add test user - $user1 = $this->userManager->createUser('test1', 'test1'); - $userFolder = $this->rootFolder->getUserFolder('test1'); - $fileId = $userFolder->getId(); - $user1->updateLastLoginTimestamp(); - - //Now insert cyclic share - $qb = $this->connection->getQueryBuilder(); - $qb->insert('share') - ->values([ - 'share_type' => $qb->createNamedParameter(0), - 'share_with' => $qb->createNamedParameter('foo'), - 'uid_owner' => $qb->createNamedParameter('owner'), - 'item_type' => $qb->createNamedParameter('file'), - 'item_source' => $qb->createNamedParameter($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - //Add test user - $user2 = $this->userManager->createUser('test2', 'test2'); - $userFolder = $this->rootFolder->getUserFolder('test2'); - $folder = $userFolder->newFolder('foo'); - $fileId = $folder->getId(); - $user2->updateLastLoginTimestamp(); - - //Now insert cyclic share - $qb = $this->connection->getQueryBuilder(); - $qb->insert('share') - ->values([ - 'share_type' => $qb->createNamedParameter(0), - 'share_with' => $qb->createNamedParameter('foo'), - 'uid_owner' => $qb->createNamedParameter('owner'), - 'item_type' => $qb->createNamedParameter('file'), - 'item_source' => $qb->createNamedParameter($fileId), - 'item_target' => $qb->createNamedParameter('/target'), - 'file_source' => $qb->createNamedParameter($fileId), - 'file_target' => $qb->createNamedParameter('/target'), - 'permissions' => $qb->createNamedParameter(1), - ]); - $qb->execute(); - - $this->repair->run($this->outputMock); - - //Verify - $qb = $this->connection->getQueryBuilder(); - $qb->select($qb->func()->count('*', 'count')) - ->from('share'); - - $cursor = $qb->execute(); - $data = $cursor->fetch(); - $cursor->closeCursor(); - - $count = (int)$data['count']; - - $this->assertEquals(1, $count); - - $user1->delete(); - $user2->delete(); - } -} diff --git a/tests/lib/Repair/RepairInvalidPathsTest.php b/tests/lib/Repair/RepairInvalidPathsTest.php deleted file mode 100644 index 17c584fd14..0000000000 --- a/tests/lib/Repair/RepairInvalidPathsTest.php +++ /dev/null @@ -1,219 +0,0 @@ - - * - * @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 . - * - */ - -namespace Test\Repair; - -use OC\Files\Cache\Cache; -use OC\Files\Storage\Temporary; -use OC\Repair\NC13\RepairInvalidPaths; -use OCP\IConfig; -use OCP\Migration\IOutput; -use Test\TestCase; - -/** - * @group DB - */ -class RepairInvalidPathsTest extends TestCase { - /** @var Temporary */ - private $storage; - /** @var Cache */ - private $cache; - /** @var Temporary */ - private $storage2; - /** @var Cache */ - private $cache2; - /** @var RepairInvalidPaths */ - private $repair; - - protected function setUp() { - parent::setUp(); - - $this->storage = new Temporary(); - $this->cache = $this->storage->getCache(); - $this->storage2 = new Temporary(); - $this->cache2 = $this->storage2->getCache(); - $config = $this->createMock(IConfig::class); - $config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0') - ->willReturn('12.0.0.0'); - $this->repair = new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), $config); - } - - protected function tearDown() { - $this->cache->clear(); - - return parent::tearDown(); - } - - public function testRepairNonDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId, $this->cache->getId('foo2/bar')); - } - - public function testRepairDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - $this->storage->rename('foo/bar', 'foo2/bar'); - $this->storage->mkdir('foo2/bar/asd/foo'); - - // usage causes the renamed subfolder to be scanned - $this->storage->getScanner()->scan('foo2/bar/asd'); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($this->cache->getId('foo2/bar'), $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($this->cache->getId('foo2/bar/asd'), $this->cache->get('foo2/bar/asd/foo')['parent']); - } - - public function testRepairMultipleNonDuplicate() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage->mkdir('foo/bar2/asd'); - $this->storage->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - - $folderId1 = $this->cache->getId('foo/bar'); - $folderId2 = $this->cache->getId('foo/bar2'); - $newParentFolderId = $this->cache->getId('foo2'); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId1, ['path' => 'foo2/bar', 'parent' => $newParentFolderId]); - $this->cache->update($folderId2, ['path' => 'foo2/bar2', 'parent' => $newParentFolderId]); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar2')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertTrue($this->cache->inCache('foo/bar2/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo2/bar2/asd')); - - $this->assertEquals($folderId1, $this->cache->get('foo/bar/asd')['parent']); - $this->assertEquals($folderId2, $this->cache->get('foo/bar2/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo2/bar2')); - $this->assertTrue($this->cache->inCache('foo2/bar/asd')); - $this->assertTrue($this->cache->inCache('foo2/bar2/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar2/asd')); - - $this->assertEquals($folderId1, $this->cache->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId2, $this->cache->get('foo2/bar2/asd')['parent']); - $this->assertEquals($folderId1, $this->cache->getId('foo2/bar')); - $this->assertEquals($folderId2, $this->cache->getId('foo2/bar2')); - } - - public function testRepairNonDuplicateBetweenStorage() { - $this->storage->mkdir('foo/bar/asd'); - $this->storage2->mkdir('foo2'); - $this->storage->getScanner()->scan(''); - $this->storage2->getScanner()->scan(''); - - $folderId = $this->cache->getId('foo/bar'); - $newParentEntry = $this->cache2->get('foo2'); - $newParentFolderId = $newParentEntry->getId(); - // failed rename, moved entry is updated but not it's children - $this->cache->update($folderId, ['path' => 'foo2/bar', 'parent' => $newParentFolderId, 'storage' => $newParentEntry->getStorageId()]); - - $this->assertTrue($this->cache2->inCache('foo2/bar')); - $this->assertTrue($this->cache->inCache('foo/bar/asd')); - $this->assertFalse($this->cache2->inCache('foo2/bar/asd')); - - $this->assertEquals($folderId, $this->cache->get('foo/bar/asd')['parent']); - - $this->repair->run($this->createMock(IOutput::class)); - - $this->assertTrue($this->cache2->inCache('foo2/bar')); - $this->assertTrue($this->cache2->inCache('foo2/bar/asd')); - $this->assertFalse($this->cache->inCache('foo/bar/asd')); - - $this->assertEquals($folderId, $this->cache2->get('foo2/bar/asd')['parent']); - $this->assertEquals($folderId, $this->cache2->getId('foo2/bar')); - } - - public function shouldRunDataProvider() { - return [ - ['11.0.0.0', true], - ['11.0.0.31', true], - ['11.0.5.2', false], - ['12.0.0.0', true], - ['12.0.0.1', true], - ['12.0.0.31', false], - ['13.0.0.0', true], - ['13.0.0.1', false] - ]; - } - - /** - * @dataProvider shouldRunDataProvider - * - * @param string $from - * @param boolean $expected - */ - public function testShouldRun($from, $expected) { - $config = $this->createMock(IConfig::class); - $config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0') - ->willReturn($from); - $repair = new RepairInvalidPaths(\OC::$server->getDatabaseConnection(), $config); - - $this->assertEquals($expected, $this->invokePrivate($repair, 'shouldRun')); - } -} diff --git a/tests/lib/Repair/SetVcardDatabaseUIDTest.php b/tests/lib/Repair/SetVcardDatabaseUIDTest.php deleted file mode 100644 index 2939528a21..0000000000 --- a/tests/lib/Repair/SetVcardDatabaseUIDTest.php +++ /dev/null @@ -1,128 +0,0 @@ - - * - * @author John Molakvoæ - * - * @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 . - * - */ - -namespace Test\Repair; - -use OCP\IConfig; -use OCP\ILogger; -use OCP\Migration\IOutput; -use OC\Repair\NC15\SetVcardDatabaseUID; -use Test\TestCase; - -/** - * @group DB - */ -class SetVcardDatabaseUIDTest extends TestCase { - - /** @var SetVcardDatabaseUID */ - private $repair; - - /** @var IConfig */ - private $config; - - /** @var Ilogger */ - private $logger; - - protected function setUp() { - parent::setUp(); - - $this->config = $this->createMock(IConfig::class); - $this->logger = $this->createMock(Ilogger::class); - $this->repair = new SetVcardDatabaseUID(\OC::$server->getDatabaseConnection(), $this->config, $this->logger); - } - - protected function tearDown() { - return parent::tearDown(); - } - - public function dataTestVcards() { - return [ - // classic vcard - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'UID:Test'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', 'Test'], - - // UID as url - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'UID:https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', 'https://User@old.domain.com/remote.php/carddav/addressbooks/User/contacts/2EAF6525-17ADC861-38D6BB1D.vcf'], - - // No uid - ['BEGIN:VCARD'.PHP_EOL. - 'VERSION:3.0'.PHP_EOL. - 'PRODID:-//Sabre//Sabre VObject 4.1.2//EN'.PHP_EOL. - 'FN:Test'.PHP_EOL. - 'N:Test;;;;'.PHP_EOL. - 'END:VCARD', false] - ]; - } - - /** - * @dataProvider dataTestVcards - * - * @param string $from - * @param string|boolean $expected - */ - public function testExtractUIDFromVcard($from, $expected) { - $output = $this->createMock(IOutput::class); - $uid = $this->invokePrivate($this->repair, 'getUid', ['carddata' => $from, 'output' => $output]); - $this->assertEquals($expected, $uid); - } - - public function shouldRunDataProvider() { - return [ - ['11.0.0.0', true], - ['15.0.0.3', false], - ['13.0.5.2', true], - ['12.0.0.0', true], - ['16.0.0.1', false], - ['15.0.0.2', true], - ['13.0.0.0', true], - ['13.0.0.1', true] - ]; - } - - /** - * @dataProvider shouldRunDataProvider - * - * @param string $from - * @param boolean $expected - */ - public function testShouldRun($from, $expected) { - $this->config->expects($this->any()) - ->method('getSystemValue') - ->with('version', '0.0.0.0') - ->willReturn($from); - - $this->assertEquals($expected, $this->invokePrivate($this->repair, 'shouldRun')); - } - -}