summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMorris Jobke <hey@morrisjobke.de>2017-02-22 22:20:56 -0600
committerMorris Jobke <hey@morrisjobke.de>2017-02-22 22:35:18 -0600
commit2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9 (patch)
treeff6b9d5e9f7f6a16b6f10605ce9aacc779fa1176 /lib
parentc2d3e12e23a0315c2ef14aab9235dfec1f6b9e26 (diff)
downloadnextcloud-server-2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9.tar.gz
nextcloud-server-2bbf3b18d90301e4c1afc8deb5ef0cf9b91a6ff9.zip
cleanup old and not needed repair steps to speed up the update
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'lib')
-rw-r--r--lib/composer/composer/autoload_classmap.php12
-rw-r--r--lib/composer/composer/autoload_static.php12
-rw-r--r--lib/private/Repair.php35
-rw-r--r--lib/private/Repair/AssetCache.php43
-rw-r--r--lib/private/Repair/DropOldJobs.php88
-rw-r--r--lib/private/Repair/DropOldTables.php111
-rw-r--r--lib/private/Repair/FillETags.php57
-rw-r--r--lib/private/Repair/InnoDB.php70
-rw-r--r--lib/private/Repair/Preview.php48
-rw-r--r--lib/private/Repair/RemoveGetETagEntries.php58
-rw-r--r--lib/private/Repair/RemoveOldShares.php104
-rw-r--r--lib/private/Repair/RepairInvalidShares.php45
-rw-r--r--lib/private/Repair/RepairMimeTypes.php258
-rw-r--r--lib/private/Repair/RepairUnmergedShares.php357
-rw-r--r--lib/private/Repair/SearchLuceneTables.php80
-rw-r--r--lib/private/Repair/SharePropagation.php56
-rw-r--r--lib/private/Repair/UpdateOutdatedOcsIds.php106
17 files changed, 0 insertions, 1540 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php
index eec6d23dce3..19eb4ca7df6 100644
--- a/lib/composer/composer/autoload_classmap.php
+++ b/lib/composer/composer/autoload_classmap.php
@@ -679,13 +679,8 @@ return array(
'OC\\RedisFactory' => $baseDir . '/lib/private/RedisFactory.php',
'OC\\Repair' => $baseDir . '/lib/private/Repair.php',
'OC\\RepairException' => $baseDir . '/lib/private/RepairException.php',
- 'OC\\Repair\\AssetCache' => $baseDir . '/lib/private/Repair/AssetCache.php',
'OC\\Repair\\CleanTags' => $baseDir . '/lib/private/Repair/CleanTags.php',
'OC\\Repair\\Collation' => $baseDir . '/lib/private/Repair/Collation.php',
- 'OC\\Repair\\DropOldJobs' => $baseDir . '/lib/private/Repair/DropOldJobs.php',
- 'OC\\Repair\\DropOldTables' => $baseDir . '/lib/private/Repair/DropOldTables.php',
- 'OC\\Repair\\FillETags' => $baseDir . '/lib/private/Repair/FillETags.php',
- 'OC\\Repair\\InnoDB' => $baseDir . '/lib/private/Repair/InnoDB.php',
'OC\\Repair\\MoveUpdaterStepFile' => $baseDir . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\CleanPreviews' => $baseDir . '/lib/private/Repair/NC11/CleanPreviews.php',
'OC\\Repair\\NC11\\CleanPreviewsBackgroundJob' => $baseDir . '/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php',
@@ -693,17 +688,10 @@ return array(
'OC\\Repair\\NC11\\MoveAvatars' => $baseDir . '/lib/private/Repair/NC11/MoveAvatars.php',
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => $baseDir . '/lib/private/Repair/NC11/MoveAvatarsBackgroundJob.php',
'OC\\Repair\\OldGroupMembershipShares' => $baseDir . '/lib/private/Repair/OldGroupMembershipShares.php',
- 'OC\\Repair\\Preview' => $baseDir . '/lib/private/Repair/Preview.php',
- 'OC\\Repair\\RemoveGetETagEntries' => $baseDir . '/lib/private/Repair/RemoveGetETagEntries.php',
- 'OC\\Repair\\RemoveOldShares' => $baseDir . '/lib/private/Repair/RemoveOldShares.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\\RepairUnmergedShares' => $baseDir . '/lib/private/Repair/RepairUnmergedShares.php',
- 'OC\\Repair\\SearchLuceneTables' => $baseDir . '/lib/private/Repair/SearchLuceneTables.php',
- 'OC\\Repair\\SharePropagation' => $baseDir . '/lib/private/Repair/SharePropagation.php',
'OC\\Repair\\SqliteAutoincrement' => $baseDir . '/lib/private/Repair/SqliteAutoincrement.php',
- 'OC\\Repair\\UpdateOutdatedOcsIds' => $baseDir . '/lib/private/Repair/UpdateOutdatedOcsIds.php',
'OC\\RichObjectStrings\\Validator' => $baseDir . '/lib/private/RichObjectStrings/Validator.php',
'OC\\Route\\CachingRouter' => $baseDir . '/lib/private/Route/CachingRouter.php',
'OC\\Route\\Route' => $baseDir . '/lib/private/Route/Route.php',
diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php
index 9967b709c3d..e1b5e025d0b 100644
--- a/lib/composer/composer/autoload_static.php
+++ b/lib/composer/composer/autoload_static.php
@@ -709,13 +709,8 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\RedisFactory' => __DIR__ . '/../../..' . '/lib/private/RedisFactory.php',
'OC\\Repair' => __DIR__ . '/../../..' . '/lib/private/Repair.php',
'OC\\RepairException' => __DIR__ . '/../../..' . '/lib/private/RepairException.php',
- 'OC\\Repair\\AssetCache' => __DIR__ . '/../../..' . '/lib/private/Repair/AssetCache.php',
'OC\\Repair\\CleanTags' => __DIR__ . '/../../..' . '/lib/private/Repair/CleanTags.php',
'OC\\Repair\\Collation' => __DIR__ . '/../../..' . '/lib/private/Repair/Collation.php',
- 'OC\\Repair\\DropOldJobs' => __DIR__ . '/../../..' . '/lib/private/Repair/DropOldJobs.php',
- 'OC\\Repair\\DropOldTables' => __DIR__ . '/../../..' . '/lib/private/Repair/DropOldTables.php',
- 'OC\\Repair\\FillETags' => __DIR__ . '/../../..' . '/lib/private/Repair/FillETags.php',
- 'OC\\Repair\\InnoDB' => __DIR__ . '/../../..' . '/lib/private/Repair/InnoDB.php',
'OC\\Repair\\MoveUpdaterStepFile' => __DIR__ . '/../../..' . '/lib/private/Repair/MoveUpdaterStepFile.php',
'OC\\Repair\\NC11\\CleanPreviews' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/CleanPreviews.php',
'OC\\Repair\\NC11\\CleanPreviewsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/CleanPreviewsBackgroundJob.php',
@@ -723,17 +718,10 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\Repair\\NC11\\MoveAvatars' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatars.php',
'OC\\Repair\\NC11\\MoveAvatarsBackgroundJob' => __DIR__ . '/../../..' . '/lib/private/Repair/NC11/MoveAvatarsBackgroundJob.php',
'OC\\Repair\\OldGroupMembershipShares' => __DIR__ . '/../../..' . '/lib/private/Repair/OldGroupMembershipShares.php',
- 'OC\\Repair\\Preview' => __DIR__ . '/../../..' . '/lib/private/Repair/Preview.php',
- 'OC\\Repair\\RemoveGetETagEntries' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveGetETagEntries.php',
- 'OC\\Repair\\RemoveOldShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RemoveOldShares.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\\RepairUnmergedShares' => __DIR__ . '/../../..' . '/lib/private/Repair/RepairUnmergedShares.php',
- 'OC\\Repair\\SearchLuceneTables' => __DIR__ . '/../../..' . '/lib/private/Repair/SearchLuceneTables.php',
- 'OC\\Repair\\SharePropagation' => __DIR__ . '/../../..' . '/lib/private/Repair/SharePropagation.php',
'OC\\Repair\\SqliteAutoincrement' => __DIR__ . '/../../..' . '/lib/private/Repair/SqliteAutoincrement.php',
- 'OC\\Repair\\UpdateOutdatedOcsIds' => __DIR__ . '/../../..' . '/lib/private/Repair/UpdateOutdatedOcsIds.php',
'OC\\RichObjectStrings\\Validator' => __DIR__ . '/../../..' . '/lib/private/RichObjectStrings/Validator.php',
'OC\\Route\\CachingRouter' => __DIR__ . '/../../..' . '/lib/private/Route/CachingRouter.php',
'OC\\Route\\Route' => __DIR__ . '/../../..' . '/lib/private/Route/Route.php',
diff --git a/lib/private/Repair.php b/lib/private/Repair.php
index e8d466cd844..6344db64e8e 100644
--- a/lib/private/Repair.php
+++ b/lib/private/Repair.php
@@ -30,28 +30,17 @@
namespace OC;
-use OC\Repair\AssetCache;
use OC\Repair\CleanTags;
use OC\Repair\Collation;
-use OC\Repair\DropOldJobs;
use OC\Repair\MoveUpdaterStepFile;
use OC\Repair\NC11\CleanPreviews;
use OC\Repair\NC11\FixMountStorages;
use OC\Repair\NC11\MoveAvatars;
use OC\Repair\OldGroupMembershipShares;
-use OC\Repair\RemoveGetETagEntries;
-use OC\Repair\RemoveOldShares;
use OC\Repair\RemoveRootShares;
-use OC\Repair\SharePropagation;
use OC\Repair\SqliteAutoincrement;
-use OC\Repair\DropOldTables;
-use OC\Repair\FillETags;
-use OC\Repair\InnoDB;
use OC\Repair\RepairMimeTypes;
-use OC\Repair\SearchLuceneTables;
-use OC\Repair\UpdateOutdatedOcsIds;
use OC\Repair\RepairInvalidShares;
-use OC\Repair\RepairUnmergedShares;
use OCP\AppFramework\QueryException;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
@@ -131,23 +120,9 @@ class Repair implements IOutput{
return [
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), \OC::$server->getDatabaseConnection(), false),
new RepairMimeTypes(\OC::$server->getConfig()),
- new AssetCache(),
- new FillETags(\OC::$server->getDatabaseConnection()),
new CleanTags(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager()),
- new DropOldTables(\OC::$server->getDatabaseConnection()),
- new DropOldJobs(\OC::$server->getJobList()),
- new RemoveGetETagEntries(\OC::$server->getDatabaseConnection()),
- new UpdateOutdatedOcsIds(\OC::$server->getConfig()),
new RepairInvalidShares(\OC::$server->getConfig(), \OC::$server->getDatabaseConnection()),
- new SharePropagation(\OC::$server->getConfig()),
- new RemoveOldShares(\OC::$server->getDatabaseConnection()),
new RemoveRootShares(\OC::$server->getDatabaseConnection(), \OC::$server->getUserManager(), \OC::$server->getLazyRootFolder()),
- new RepairUnmergedShares(
- \OC::$server->getConfig(),
- \OC::$server->getDatabaseConnection(),
- \OC::$server->getUserManager(),
- \OC::$server->getGroupManager()
- ),
new MoveUpdaterStepFile(\OC::$server->getConfig()),
new MoveAvatars(
\OC::$server->getJobList(),
@@ -183,20 +158,10 @@ class Repair implements IOutput{
public static function getBeforeUpgradeRepairSteps() {
$connection = \OC::$server->getDatabaseConnection();
$steps = [
- new InnoDB(),
new Collation(\OC::$server->getConfig(), \OC::$server->getLogger(), $connection, true),
new SqliteAutoincrement($connection),
- new SearchLuceneTables(),
];
- //There is no need to delete all previews on every single update
- //only 7.0.0 through 7.0.2 generated broken previews
- $currentVersion = \OC::$server->getConfig()->getSystemValue('version');
- if (version_compare($currentVersion, '7.0.0.0', '>=') &&
- version_compare($currentVersion, '7.0.3.4', '<=')) {
- $steps[] = new \OC\Repair\Preview();
- }
-
return $steps;
}
diff --git a/lib/private/Repair/AssetCache.php b/lib/private/Repair/AssetCache.php
deleted file mode 100644
index 74eb9c51986..00000000000
--- a/lib/private/Repair/AssetCache.php
+++ /dev/null
@@ -1,43 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Adam Williamson <awilliam@redhat.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class AssetCache implements IRepairStep {
-
- public function getName() {
- return 'Remove asset cache';
- }
-
- public function run(IOutput $output) {
- $assetDir = \OC::$server->getConfig()->getSystemValue('assetdirectory', \OC::$SERVERROOT) . '/assets';
- \OC_Helper::rmdirr($assetDir, false);
- $output->info('Asset cache cleared.');
- }
-}
-
diff --git a/lib/private/Repair/DropOldJobs.php b/lib/private/Repair/DropOldJobs.php
deleted file mode 100644
index 126df9e940f..00000000000
--- a/lib/private/Repair/DropOldJobs.php
+++ /dev/null
@@ -1,88 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Arthur Schiwon <blizzz@arthur-schiwon.de>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\BackgroundJob\IJobList;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class DropOldJobs implements IRepairStep {
-
- /** @var IJobList */
- protected $jobList;
-
- /**
- * @param IJobList $jobList
- */
- public function __construct(IJobList $jobList) {
- $this->jobList = $jobList;
- }
-
- /**
- * Returns the step's name
- *
- * @return string
- */
- public function getName() {
- return 'Drop old background jobs';
- }
-
- /**
- * Run repair step.
- * Must throw exception on error.
- *
- * @throws \Exception in case of failure
- */
- public function run(IOutput $output) {
- $oldJobs = $this->oldJobs();
- foreach($oldJobs as $job) {
- if($this->jobList->has($job['class'], $job['arguments'])) {
- $this->jobList->remove($job['class'], $job['arguments']);
- }
- }
- }
-
- /**
- * returns a list of old jobs as an associative array with keys 'class' and
- * 'arguments'.
- *
- * @return array
- */
- public function oldJobs() {
- return [
- ['class' => 'OC_Cache_FileGlobalGC', 'arguments' => null],
- ['class' => 'OC\Cache\FileGlobalGC', 'arguments' => null],
- ['class' => 'OCA\Files\BackgroundJob\DeleteOrphanedTagsJob', 'arguments' => null],
-
- ['class' => 'OCA\Files_sharing\Lib\DeleteOrphanedSharesJob', 'arguments' => null],
- ['class' => 'OCA\Files_sharing\ExpireSharesJob', 'arguments' => null],
-
- ['class' => 'OCA\user_ldap\lib\Jobs', 'arguments' => null],
- ['class' => '\OCA\User_LDAP\Jobs\CleanUp', 'arguments' => null],
- ];
- }
-
-
-}
diff --git a/lib/private/Repair/DropOldTables.php b/lib/private/Repair/DropOldTables.php
deleted file mode 100644
index dfc3f757ea8..00000000000
--- a/lib/private/Repair/DropOldTables.php
+++ /dev/null
@@ -1,111 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Florian Preinstorfer <nblock@archlinux.us>
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-
-use OCP\IDBConnection;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class DropOldTables implements IRepairStep {
-
- /** @var IDBConnection */
- protected $connection;
-
- /**
- * @param IDBConnection $connection
- */
- public function __construct(IDBConnection $connection) {
- $this->connection = $connection;
- }
-
- /**
- * Returns the step's name
- *
- * @return string
- */
- public function getName() {
- return 'Drop old database tables';
- }
-
- /**
- * Run repair step.
- * Must throw exception on error.
- *
- * @throws \Exception in case of failure
- */
- public function run(IOutput $output) {
- $tables = $this->oldDatabaseTables();
- $output->startProgress(count($tables));
- foreach ($this->oldDatabaseTables() as $tableName) {
- if ($this->connection->tableExists($tableName)){
- $this->connection->dropTable($tableName);
- }
- $output->advance(1, "Drop old database table: $tableName");
- }
- $output->finishProgress();
- }
-
- /**
- * Returns a list of outdated tables which are not used anymore
- * @return array
- */
- protected function oldDatabaseTables() {
- return [
- 'calendar_calendars',
- 'calendar_objects',
- 'calendar_share_calendar',
- 'calendar_share_event',
- 'file_map',
- 'foldersize',
- 'fscache',
- 'gallery_sharing',
- 'locks',
- 'log',
- 'media_albums',
- 'media_artists',
- 'media_sessions',
- 'media_songs',
- 'media_users',
- 'permissions',
- 'pictures_images_cache',
- 'principalgroups',
- 'principals',
- 'queuedtasks',
- 'sharing',
- 'clndr_calendars',
- 'clndr_objects',
- 'clndr_share_event',
- 'clndr_share_calendar',
- 'clndr_repeat',
- 'contacts_addressbooks',
- 'contacts_cards',
- 'contacts_cards_properties',
- 'gallery_albums',
- 'gallery_photos'
- ];
- }
-}
diff --git a/lib/private/Repair/FillETags.php b/lib/private/Repair/FillETags.php
deleted file mode 100644
index 2954c0eaa63..00000000000
--- a/lib/private/Repair/FillETags.php
+++ /dev/null
@@ -1,57 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Joas Schilling <coding@schilljs.com>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class FillETags implements IRepairStep {
-
- /** @var \OCP\IDBConnection */
- protected $connection;
-
- /**
- * @param \OCP\IDBConnection $connection
- */
- public function __construct($connection) {
- $this->connection = $connection;
- }
-
- public function getName() {
- return 'Generate ETags for file where no ETag is present.';
- }
-
- public function run(IOutput $output) {
- $qb = $this->connection->getQueryBuilder();
- $qb->update('filecache')
- ->set('etag', $qb->expr()->literal('xxx'))
- ->where($qb->expr()->eq('etag', $qb->expr()->literal('')))
- ->orWhere($qb->expr()->isNull('etag'));
-
- $result = $qb->execute();
- $output->info("ETags have been fixed for $result files/folders.");
- }
-}
-
diff --git a/lib/private/Repair/InnoDB.php b/lib/private/Repair/InnoDB.php
deleted file mode 100644
index 174cc334482..00000000000
--- a/lib/private/Repair/InnoDB.php
+++ /dev/null
@@ -1,70 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Robin Appelman <robin@icewind.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use Doctrine\DBAL\Platforms\MySqlPlatform;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class InnoDB implements IRepairStep {
-
- public function getName() {
- return 'Repair MySQL database engine';
- }
-
- /**
- * Fix mime types
- */
- public function run(IOutput $output) {
- $connection = \OC::$server->getDatabaseConnection();
- if (!$connection->getDatabasePlatform() instanceof MySqlPlatform) {
- $output->info('Not a mysql database -> nothing to do');
- return;
- }
-
- $tables = $this->getAllMyIsamTables($connection);
- if (is_array($tables)) {
- foreach ($tables as $table) {
- $connection->exec("ALTER TABLE $table ENGINE=InnoDB;");
- $output->info("Fixed $table");
- }
- }
- }
-
- /**
- * @param \Doctrine\DBAL\Connection $connection
- * @return string[]
- */
- private function getAllMyIsamTables($connection) {
- $dbName = \OC::$server->getConfig()->getSystemValue("dbname");
- $result = $connection->fetchArray(
- "SELECT table_name FROM information_schema.tables WHERE table_schema = ? AND engine = 'MyISAM' AND TABLE_NAME LIKE \"*PREFIX*%\"",
- array($dbName)
- );
-
- return $result;
- }
-}
-
diff --git a/lib/private/Repair/Preview.php b/lib/private/Repair/Preview.php
deleted file mode 100644
index 8391c3bf726..00000000000
--- a/lib/private/Repair/Preview.php
+++ /dev/null
@@ -1,48 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Georg Ehrke <georg@owncloud.com>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Repair;
-
-use OC\Files\View;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class Preview implements IRepairStep {
-
- public function getName() {
- return 'Cleaning-up broken previews';
- }
-
- public function run(IOutput $out) {
- $view = new View('/');
- $children = $view->getDirectoryContent('/');
-
- foreach ($children as $child) {
- if ($view->is_dir($child->getPath())) {
- $thumbnailsFolder = $child->getPath() . '/thumbnails';
- if ($view->is_dir($thumbnailsFolder)) {
- $view->rmdir($thumbnailsFolder);
- }
- }
- }
- }
-}
diff --git a/lib/private/Repair/RemoveGetETagEntries.php b/lib/private/Repair/RemoveGetETagEntries.php
deleted file mode 100644
index d701a8f26de..00000000000
--- a/lib/private/Repair/RemoveGetETagEntries.php
+++ /dev/null
@@ -1,58 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\IDBConnection;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class RemoveGetETagEntries implements IRepairStep {
-
- /**
- * @var IDBConnection
- */
- protected $connection;
-
- /**
- * @param IDBConnection $connection
- */
- public function __construct(IDBConnection $connection) {
- $this->connection = $connection;
- }
-
- public function getName() {
- return 'Remove getetag entries in properties table';
- }
-
- /**
- * Removes all entries with the key "{DAV:}getetag" from the table properties
- */
- public function run(IOutput $out) {
- $sql = 'DELETE FROM `*PREFIX*properties`'
- . ' WHERE `propertyname` = ?';
- $deletedRows = $this->connection->executeUpdate($sql, ['{DAV:}getetag']);
-
- $out->info('Removed ' . $deletedRows . ' unneeded "{DAV:}getetag" entries from properties table.');
- }
-}
diff --git a/lib/private/Repair/RemoveOldShares.php b/lib/private/Repair/RemoveOldShares.php
deleted file mode 100644
index 32a17189fbf..00000000000
--- a/lib/private/Repair/RemoveOldShares.php
+++ /dev/null
@@ -1,104 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Repair;
-
-use OCP\IDBConnection;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-/**
- * Class RemoveOldShares
- *
- * @package OC\Repair
- */
-class RemoveOldShares implements IRepairStep {
-
- /** @var IDBConnection */
- protected $connection;
-
- /**
- * RemoveOldCalendarShares constructor.
- *
- * @param IDBConnection $db
- */
- public function __construct(IDBConnection $connection) {
- $this->connection = $connection;
- }
-
- /**
- * @return string
- */
- public function getName() {
- return 'Remove old (< 9.0) calendar/contact shares';
- }
-
- /**
- * @param IOutput $output
- */
- public function run(IOutput $output) {
- $output->startProgress(4);
-
- $this->removeCalendarShares($output);
- $this->removeContactShares($output);
-
- $output->finishProgress();
- }
-
- /**
- * @param IOutput $output
- */
- private function removeCalendarShares(IOutput $output) {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share')
- ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('calendar')));
- $qb->execute();
-
- $output->advance();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share')
- ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('event')));
- $qb->execute();
-
- $output->advance();
- }
-
- /**
- * @param IOutput $output
- */
- private function removeContactShares(IOutput $output) {
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share')
- ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('contact')));
- $qb->execute();
-
- $output->advance();
-
- $qb = $this->connection->getQueryBuilder();
- $qb->delete('share')
- ->where($qb->expr()->eq('item_type', $qb->createNamedParameter('addressbook')));
- $qb->execute();
-
- $output->advance();
- }
-}
-
diff --git a/lib/private/Repair/RepairInvalidShares.php b/lib/private/Repair/RepairInvalidShares.php
index 04624c910dd..eba66e295c4 100644
--- a/lib/private/Repair/RepairInvalidShares.php
+++ b/lib/private/Repair/RepairInvalidShares.php
@@ -56,43 +56,6 @@ class RepairInvalidShares implements IRepairStep {
}
/**
- * Past bugs would make it possible to set an expiration date on user shares even
- * though it is not supported. This functions removes the expiration date from such entries.
- */
- private function removeExpirationDateFromNonLinkShares(IOutput $out) {
- $builder = $this->connection->getQueryBuilder();
- $builder
- ->update('share')
- ->set('expiration', 'null')
- ->where($builder->expr()->isNotNull('expiration'))
- ->andWhere($builder->expr()->neq('share_type', $builder->expr()->literal(\OC\Share\Constants::SHARE_TYPE_LINK)));
-
- $updatedEntries = $builder->execute();
- if ($updatedEntries > 0) {
- $out->info('Removed invalid expiration date from ' . $updatedEntries . ' shares');
- }
- }
-
- /**
- * In the past link shares with public upload enabled were missing the delete permission.
- */
- private function addShareLinkDeletePermission(IOutput $out) {
- $oldPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE;
- $newPerms = \OCP\Constants::PERMISSION_READ | \OCP\Constants::PERMISSION_CREATE | \OCP\Constants::PERMISSION_UPDATE | \OCP\Constants::PERMISSION_DELETE;
- $builder = $this->connection->getQueryBuilder();
- $builder
- ->update('share')
- ->set('permissions', $builder->expr()->literal($newPerms))
- ->where($builder->expr()->eq('share_type', $builder->expr()->literal(\OC\Share\Constants::SHARE_TYPE_LINK)))
- ->andWhere($builder->expr()->eq('permissions', $builder->expr()->literal($oldPerms)));
-
- $updatedEntries = $builder->execute();
- if ($updatedEntries > 0) {
- $out->info('Fixed link share permissions for ' . $updatedEntries . ' shares');
- }
- }
-
- /**
* Adjust file share permissions
*/
private function adjustFileSharePermissions(IOutput $out) {
@@ -150,14 +113,6 @@ class RepairInvalidShares implements IRepairStep {
public function run(IOutput $out) {
$ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
- if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.7', '<')) {
- // this situation was only possible before 8.2
- $this->removeExpirationDateFromNonLinkShares($out);
- }
- if (version_compare($ocVersionFromBeforeUpdate, '9.1.0.9', '<')) {
- // this situation was only possible before 9.1
- $this->addShareLinkDeletePermission($out);
- }
if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.11', '<')) {
$this->adjustFileSharePermissions($out);
}
diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php
index fbf446a681c..534b5ce2c28 100644
--- a/lib/private/Repair/RepairMimeTypes.php
+++ b/lib/private/Repair/RepairMimeTypes.php
@@ -78,24 +78,6 @@ class RepairMimeTypes implements IRepairStep {
');
}
- private static function updateWrongStmt() {
- return \OC_DB::prepare('
- UPDATE `*PREFIX*filecache`
- SET `mimetype` = (
- SELECT `id`
- FROM `*PREFIX*mimetypes`
- WHERE `mimetype` = ?
- ) WHERE `mimetype` = ?
- ');
- }
-
- private static function deleteStmt() {
- return \OC_DB::prepare('
- DELETE FROM `*PREFIX*mimetypes`
- WHERE `id` = ?
- ');
- }
-
private static function updateByNameStmt() {
return \OC_DB::prepare('
UPDATE `*PREFIX*filecache`
@@ -104,34 +86,6 @@ class RepairMimeTypes implements IRepairStep {
');
}
- private function repairMimetypes($wrongMimetypes) {
- foreach ($wrongMimetypes as $wrong => $correct) {
- // do we need to remove a wrong mimetype?
- $result = \OC_DB::executeAudited(self::getIdStmt(), array($wrong));
- $wrongId = $result->fetchOne();
-
- if ($wrongId !== false) {
- // do we need to insert the correct mimetype?
- $result = \OC_DB::executeAudited(self::existsStmt(), array($correct));
- $exists = $result->fetchOne();
-
- if (!is_null($correct)) {
- if (!$exists) {
- // insert mimetype
- \OC_DB::executeAudited(self::insertStmt(), array($correct));
- }
-
- // change wrong mimetype to correct mimetype in filecache
- \OC_DB::executeAudited(self::updateWrongStmt(), array($correct, $wrongId));
- }
-
- // delete wrong mimetype
- \OC_DB::executeAudited(self::deleteStmt(), array($wrongId));
-
- }
- }
- }
-
private function updateMimetypes($updatedMimetypes) {
if (empty($this->folderMimeTypeId)) {
$result = \OC_DB::executeAudited(self::getIdStmt(), array('httpd/unix-directory'));
@@ -156,158 +110,6 @@ class RepairMimeTypes implements IRepairStep {
}
}
- private function fixOfficeMimeTypes() {
- // update wrong mimetypes
- $wrongMimetypes = array(
- 'application/mspowerpoint' => 'application/vnd.ms-powerpoint',
- 'application/msexcel' => 'application/vnd.ms-excel',
- );
-
- self::repairMimetypes($wrongMimetypes);
-
- $updatedMimetypes = array(
- 'docx' => 'application/vnd.openxmlformats-officedocument.wordprocessingml.document',
- 'xlsx' => 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet',
- 'pptx' => 'application/vnd.openxmlformats-officedocument.presentationml.presentation',
- );
-
-
- // separate doc from docx etc
- self::updateMimetypes($updatedMimetypes);
-
- }
-
- private function fixApkMimeType() {
- $updatedMimetypes = array(
- 'apk' => 'application/vnd.android.package-archive',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function fixFontsMimeTypes() {
- // update wrong mimetypes
- $wrongMimetypes = array(
- 'font' => null,
- 'font/opentype' => 'application/font-sfnt',
- 'application/x-font-ttf' => 'application/font-sfnt',
- );
-
- self::repairMimetypes($wrongMimetypes);
-
- $updatedMimetypes = array(
- 'ttf' => 'application/font-sfnt',
- 'otf' => 'application/font-sfnt',
- 'pfb' => 'application/x-font',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function fixPostscriptMimeType() {
- $updatedMimetypes = array(
- 'eps' => 'application/postscript',
- 'ps' => 'application/postscript',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceRawMimeType() {
- $updatedMimetypes = array(
- 'arw' => 'image/x-dcraw',
- 'cr2' => 'image/x-dcraw',
- 'dcr' => 'image/x-dcraw',
- 'dng' => 'image/x-dcraw',
- 'erf' => 'image/x-dcraw',
- 'iiq' => 'image/x-dcraw',
- 'k25' => 'image/x-dcraw',
- 'kdc' => 'image/x-dcraw',
- 'mef' => 'image/x-dcraw',
- 'nef' => 'image/x-dcraw',
- 'orf' => 'image/x-dcraw',
- 'pef' => 'image/x-dcraw',
- 'raf' => 'image/x-dcraw',
- 'rw2' => 'image/x-dcraw',
- 'srf' => 'image/x-dcraw',
- 'sr2' => 'image/x-dcraw',
- 'xrf' => 'image/x-dcraw',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduce3dImagesMimeType() {
- $updatedMimetypes = array(
- 'jps' => 'image/jpeg',
- 'mpo' => 'image/jpeg',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceConfMimeType() {
- $updatedMimetypes = array(
- 'conf' => 'text/plain',
- 'cnf' => 'text/plain',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceYamlMimeType() {
- $updatedMimetypes = array(
- 'yaml' => 'application/yaml',
- 'yml' => 'application/yaml',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceJavaMimeType() {
- $updatedMimetypes = array(
- 'class' => 'application/java',
- 'java' => 'text/x-java-source',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceHppMimeType() {
- $updatedMimetypes = array(
- 'hpp' => 'text/x-h',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceRssMimeType() {
- $updatedMimetypes = array(
- 'rss' => 'application/rss+xml',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceRtfMimeType() {
- $updatedMimetypes = array(
- 'rtf' => 'text/rtf',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
- private function introduceRichDocumentsMimeTypes() {
- $updatedMimetypes = array(
- 'lwp' => 'application/vnd.lotus-wordpro',
- 'one' => 'application/msonenote',
- 'vsd' => 'application/vnd.visio',
- 'wpd' => 'application/vnd.wordperfect',
- );
-
- self::updateMimetypes($updatedMimetypes);
- }
-
private function introduceWindowsProgramTypes() {
$updatedMimetypes = array(
'htaccess' => 'text/plain',
@@ -328,66 +130,6 @@ class RepairMimeTypes implements IRepairStep {
// NOTE TO DEVELOPERS: when adding new mime types, please make sure to
// add a version comparison to avoid doing it every time
- // only update mime types if necessary as it can be expensive
- if (version_compare($ocVersionFromBeforeUpdate, '8.2.0', '<')) {
- if ($this->fixOfficeMimeTypes()) {
- $out->info('Fixed office mime types');
- }
-
- if ($this->fixApkMimeType()) {
- $out->info('Fixed APK mime type');
- }
-
- if ($this->fixFontsMimeTypes()) {
- $out->info('Fixed fonts mime types');
- }
-
- if ($this->fixPostscriptMimeType()) {
- $out->info('Fixed Postscript mime types');
- }
-
- if ($this->introduceRawMimeType()) {
- $out->info('Fixed Raw mime types');
- }
-
- if ($this->introduce3dImagesMimeType()) {
- $out->info('Fixed 3D images mime types');
- }
-
- if ($this->introduceConfMimeType()) {
- $out->info('Fixed Conf/cnf mime types');
- }
-
- if ($this->introduceYamlMimeType()) {
- $out->info('Fixed Yaml/Yml mime types');
- }
- }
-
- // Mimetype updates from #19272
- if (version_compare($ocVersionFromBeforeUpdate, '8.2.0.8', '<')) {
- if ($this->introduceJavaMimeType()) {
- $out->info('Fixed java/class mime types');
- }
-
- if ($this->introduceHppMimeType()) {
- $out->info('Fixed hpp mime type');
- }
-
- if ($this->introduceRssMimeType()) {
- $out->info('Fixed rss mime type');
- }
-
- if ($this->introduceRtfMimeType()) {
- $out->info('Fixed rtf mime type');
- }
- }
-
- if (version_compare($ocVersionFromBeforeUpdate, '9.0.0.10', '<')) {
- if ($this->introduceRichDocumentsMimeTypes()) {
- $out->info('Fixed richdocuments additional office mime types');
- }
- }
-
if (version_compare($ocVersionFromBeforeUpdate, '12.0.0.13', '<') && $this->introduceWindowsProgramTypes()) {
$out->info('Fixed windows program mime types');
}
diff --git a/lib/private/Repair/RepairUnmergedShares.php b/lib/private/Repair/RepairUnmergedShares.php
deleted file mode 100644
index 56d935c74f5..00000000000
--- a/lib/private/Repair/RepairUnmergedShares.php
+++ /dev/null
@@ -1,357 +0,0 @@
-<?php
-/**
- * @author Vincent Petry <pvince81@owncloud.com>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-use OC\Share\Constants;
-use OCP\DB\QueryBuilder\IQueryBuilder;
-use OCP\IConfig;
-use OCP\IDBConnection;
-use OCP\IUserManager;
-use OCP\IUser;
-use OCP\IGroupManager;
-use OC\Share20\DefaultShareProvider;
-
-/**
- * Repairs shares for which the received folder was not properly deduplicated.
- *
- * An unmerged share can for example happen when sharing a folder with the same
- * user through multiple ways, like several groups and also directly, additionally
- * to group shares. Since 9.0.0 these would create duplicate entries "folder (2)",
- * one for every share. This repair step rearranges them so they only appear as a single
- * folder.
- */
-class RepairUnmergedShares implements IRepairStep {
-
- /** @var \OCP\IConfig */
- protected $config;
-
- /** @var \OCP\IDBConnection */
- protected $connection;
-
- /** @var IUserManager */
- protected $userManager;
-
- /** @var IGroupManager */
- protected $groupManager;
-
- /** @var IQueryBuilder */
- private $queryGetSharesWithUsers;
-
- /** @var IQueryBuilder */
- private $queryUpdateSharePermissionsAndTarget;
-
- /** @var IQueryBuilder */
- private $queryUpdateShareInBatch;
-
- /**
- * @param \OCP\IConfig $config
- * @param \OCP\IDBConnection $connection
- */
- public function __construct(
- IConfig $config,
- IDBConnection $connection,
- IUserManager $userManager,
- IGroupManager $groupManager
- ) {
- $this->connection = $connection;
- $this->config = $config;
- $this->userManager = $userManager;
- $this->groupManager = $groupManager;
- }
-
- public function getName() {
- return 'Repair unmerged shares';
- }
-
- /**
- * Builds prepared queries for reuse
- */
- private function buildPreparedQueries() {
- /**
- * Retrieve shares for a given user/group and share type
- */
- $query = $this->connection->getQueryBuilder();
- $query
- ->select('item_source', 'id', 'file_target', 'permissions', 'parent', 'share_type', 'stime')
- ->from('share')
- ->where($query->expr()->eq('share_type', $query->createParameter('shareType')))
- ->andWhere($query->expr()->in('share_with', $query->createParameter('shareWiths')))
- ->andWhere($query->expr()->in('item_type', $query->createParameter('itemTypes')))
- ->orderBy('item_source', 'ASC')
- ->addOrderBy('stime', 'ASC');
-
- $this->queryGetSharesWithUsers = $query;
-
- /**
- * Updates the file_target to the given value for all given share ids.
- *
- * This updates several shares in bulk which is faster than individually.
- */
- $query = $this->connection->getQueryBuilder();
- $query->update('share')
- ->set('file_target', $query->createParameter('file_target'))
- ->where($query->expr()->in('id', $query->createParameter('ids')));
-
- $this->queryUpdateShareInBatch = $query;
-
- /**
- * Updates the share permissions and target path of a single share.
- */
- $query = $this->connection->getQueryBuilder();
- $query->update('share')
- ->set('permissions', $query->createParameter('permissions'))
- ->set('file_target', $query->createParameter('file_target'))
- ->where($query->expr()->eq('id', $query->createParameter('shareid')));
-
- $this->queryUpdateSharePermissionsAndTarget = $query;
-
- }
-
- private function getSharesWithUser($shareType, $shareWiths) {
- $groupedShares = [];
-
- $query = $this->queryGetSharesWithUsers;
- $query->setParameter('shareWiths', $shareWiths, IQueryBuilder::PARAM_STR_ARRAY);
- $query->setParameter('shareType', $shareType);
- $query->setParameter('itemTypes', ['file', 'folder'], IQueryBuilder::PARAM_STR_ARRAY);
-
- $shares = $query->execute()->fetchAll();
-
- // group by item_source
- foreach ($shares as $share) {
- if (!isset($groupedShares[$share['item_source']])) {
- $groupedShares[$share['item_source']] = [];
- }
- $groupedShares[$share['item_source']][] = $share;
- }
- return $groupedShares;
- }
-
- private function isPotentialDuplicateName($name) {
- return (preg_match('/\(\d+\)(\.[^\.]+)?$/', $name) === 1);
- }
-
- /**
- * Decide on the best target name based on all group shares and subshares,
- * goal is to increase the likeliness that the chosen name matches what
- * the user is expecting.
- *
- * For this, we discard the entries with parenthesis "(2)".
- * In case the user also renamed the duplicates to a legitimate name, this logic
- * will still pick the most recent one as it's the one the user is most likely to
- * remember renaming.
- *
- * If no suitable subshare is found, use the least recent group share instead.
- *
- * @param array $groupShares group share entries
- * @param array $subShares sub share entries
- *
- * @return string chosen target name
- */
- private function findBestTargetName($groupShares, $subShares) {
- $pickedShare = null;
- // sort by stime, this also properly sorts the direct user share if any
- @usort($subShares, function($a, $b) {
- return ((int)$a['stime'] - (int)$b['stime']);
- });
-
- foreach ($subShares as $subShare) {
- // skip entries that have parenthesis with numbers
- if ($this->isPotentialDuplicateName($subShare['file_target'])) {
- continue;
- }
- // pick any share found that would match, the last being the most recent
- $pickedShare = $subShare;
- }
-
- // no suitable subshare found
- if ($pickedShare === null) {
- // use least recent group share target instead
- $pickedShare = $groupShares[0];
- }
-
- return $pickedShare['file_target'];
- }
-
- /**
- * Fix the given received share represented by the set of group shares
- * and matching sub shares
- *
- * @param array $groupShares group share entries
- * @param array $subShares sub share entries
- *
- * @return boolean false if the share was not repaired, true if it was
- */
- private function fixThisShare($groupShares, $subShares) {
- if (empty($subShares)) {
- return false;
- }
-
- $groupSharesById = [];
- foreach ($groupShares as $groupShare) {
- $groupSharesById[$groupShare['id']] = $groupShare;
- }
-
- if ($this->isThisShareValid($groupSharesById, $subShares)) {
- return false;
- }
-
- $targetPath = $this->findBestTargetName($groupShares, $subShares);
-
- // check whether the user opted out completely of all subshares
- $optedOut = true;
- foreach ($subShares as $subShare) {
- if ((int)$subShare['permissions'] !== 0) {
- $optedOut = false;
- break;
- }
- }
-
- $shareIds = [];
- foreach ($subShares as $subShare) {
- // only if the user deleted some subshares but not all, adjust the permissions of that subshare
- if (!$optedOut && (int)$subShare['permissions'] === 0 && (int)$subShare['share_type'] === DefaultShareProvider::SHARE_TYPE_USERGROUP) {
- // set permissions from parent group share
- $permissions = $groupSharesById[$subShare['parent']]['permissions'];
-
- // fix permissions and target directly
- $query = $this->queryUpdateSharePermissionsAndTarget;
- $query->setParameter('shareid', $subShare['id']);
- $query->setParameter('file_target', $targetPath);
- $query->setParameter('permissions', $permissions);
- $query->execute();
- } else {
- // gather share ids for bulk target update
- if ($subShare['file_target'] !== $targetPath) {
- $shareIds[] = (int)$subShare['id'];
- }
- }
- }
-
- if (!empty($shareIds)) {
- $query = $this->queryUpdateShareInBatch;
- $query->setParameter('ids', $shareIds, IQueryBuilder::PARAM_INT_ARRAY);
- $query->setParameter('file_target', $targetPath);
- $query->execute();
- }
-
- return true;
- }
-
- /**
- * Checks whether the number of group shares is balanced with the child subshares.
- * If all group shares have exactly one subshare, and the target of every subshare
- * is the same, then the share is valid.
- * If however there is a group share entry that has no matching subshare, it means
- * we're in the bogus situation and the whole share must be repaired
- *
- * @param array $groupSharesById
- * @param array $subShares
- *
- * @return true if the share is valid, false if it needs repair
- */
- private function isThisShareValid($groupSharesById, $subShares) {
- $foundTargets = [];
-
- // every group share needs to have exactly one matching subshare
- foreach ($subShares as $subShare) {
- $foundTargets[$subShare['file_target']] = true;
- if (count($foundTargets) > 1) {
- // not all the same target path value => invalid
- return false;
- }
- if (isset($groupSharesById[$subShare['parent']])) {
- // remove it from the list as we found it
- unset($groupSharesById[$subShare['parent']]);
- }
- }
-
- // if we found one subshare per group entry, the set will be empty.
- // If not empty, it means that one of the group shares did not have
- // a matching subshare entry.
- return empty($groupSharesById);
- }
-
- /**
- * Detect unmerged received shares and merge them properly
- */
- private function fixUnmergedShares(IOutput $out, IUser $user) {
- $groups = $this->groupManager->getUserGroupIds($user);
- if (empty($groups)) {
- // user is in no groups, so can't have received group shares
- return;
- }
-
- // get all subshares grouped by item source
- $subSharesByItemSource = $this->getSharesWithUser(DefaultShareProvider::SHARE_TYPE_USERGROUP, [$user->getUID()]);
-
- // because sometimes one wants to give the user more permissions than the group share
- $userSharesByItemSource = $this->getSharesWithUser(Constants::SHARE_TYPE_USER, [$user->getUID()]);
-
- if (empty($subSharesByItemSource) && empty($userSharesByItemSource)) {
- // nothing to repair for this user, no need to do extra queries
- return;
- }
-
- $groupSharesByItemSource = $this->getSharesWithUser(Constants::SHARE_TYPE_GROUP, $groups);
- if (empty($groupSharesByItemSource) && empty($userSharesByItemSource)) {
- // nothing to repair for this user
- return;
- }
-
- foreach ($groupSharesByItemSource as $itemSource => $groupShares) {
- $subShares = [];
- if (isset($subSharesByItemSource[$itemSource])) {
- $subShares = $subSharesByItemSource[$itemSource];
- }
-
- if (isset($userSharesByItemSource[$itemSource])) {
- // add it to the subshares to get a similar treatment
- $subShares = array_merge($subShares, $userSharesByItemSource[$itemSource]);
- }
-
- $this->fixThisShare($groupShares, $subShares);
- }
- }
-
- public function run(IOutput $output) {
- $ocVersionFromBeforeUpdate = $this->config->getSystemValue('version', '0.0.0');
- if (version_compare($ocVersionFromBeforeUpdate, '9.1.0.16', '<')) {
- // this situation was only possible between 9.0.0 and 9.0.3 included
-
- $function = function(IUser $user) use ($output) {
- $this->fixUnmergedShares($output, $user);
- $output->advance();
- };
-
- $this->buildPreparedQueries();
-
- $output->startProgress($this->userManager->countUsers());
-
- $this->userManager->callForAllUsers($function);
-
- $output->finishProgress();
- }
- }
-}
diff --git a/lib/private/Repair/SearchLuceneTables.php b/lib/private/Repair/SearchLuceneTables.php
deleted file mode 100644
index 0a06371ce90..00000000000
--- a/lib/private/Repair/SearchLuceneTables.php
+++ /dev/null
@@ -1,80 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Jörn Friedrich Dreyer <jfd@butonic.de>
- * @author Morris Jobke <hey@morrisjobke.de>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class SearchLuceneTables implements IRepairStep {
-
- public function getName() {
- return 'Repair duplicate entries in oc_lucene_status';
- }
-
- /**
- * Fix duplicate entries in oc_lucene_status
- *
- * search_lucene prior to v0.5.0 did not have a primary key on the lucene_status table. Newer versions do, which
- * causes the migration check to fail because it tries to insert duplicate rows into the new schema.
- *
- * FIXME Currently, apps don't have a way of repairing anything before the migration check:
- * @link https://github.com/owncloud/core/issues/10980
- *
- * As a result this repair step needs to live in the core repo, although it belongs into search_lucene:
- * @link https://github.com/owncloud/core/issues/10205#issuecomment-54957557
- *
- * It will completely remove any rows that make a file id have more than one status:
- * fileid | status fileid | status
- * --------+-------- will become --------+--------
- * 2 | E 3 | E
- * 2 | I
- * 3 | E
- *
- * search_lucene will then reindex the fileids without a status when the next indexing job is executed
- */
- public function run(IOutput $out) {
- $connection = \OC::$server->getDatabaseConnection();
- if ($connection->tableExists('lucene_status')) {
- $out->info('removing duplicate entries from lucene_status');
-
- $query = $connection->prepare('
- DELETE FROM `*PREFIX*lucene_status`
- WHERE `fileid` IN (
- SELECT `fileid`
- FROM (
- SELECT `fileid`
- FROM `*PREFIX*lucene_status`
- GROUP BY `fileid`
- HAVING count(`fileid`) > 1
- ) AS `mysqlerr1093hack`
- )');
- $query->execute();
- } else {
- $out->info('lucene_status table does not exist -> nothing to do');
- }
- }
-
-}
-
diff --git a/lib/private/Repair/SharePropagation.php b/lib/private/Repair/SharePropagation.php
deleted file mode 100644
index c0cca3bd1ad..00000000000
--- a/lib/private/Repair/SharePropagation.php
+++ /dev/null
@@ -1,56 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Robin Appelman <robin@icewind.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-namespace OC\Repair;
-
-use OCP\IConfig;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-class SharePropagation implements IRepairStep {
-
- /** @var IConfig */
- private $config;
-
- /**
- * SharePropagation constructor.
- *
- * @param IConfig $config
- */
- public function __construct(IConfig $config) {
- $this->config = $config;
- }
-
- public function getName() {
- return 'Remove old share propagation app entries';
- }
-
- public function run(IOutput $out ) {
- $keys = $this->config->getAppKeys('files_sharing');
-
- foreach ($keys as $key) {
- if (is_numeric($key)) {
- $this->config->deleteAppValue('files_sharing', $key);
- }
- }
- }
-}
diff --git a/lib/private/Repair/UpdateOutdatedOcsIds.php b/lib/private/Repair/UpdateOutdatedOcsIds.php
deleted file mode 100644
index 6f4f2447e94..00000000000
--- a/lib/private/Repair/UpdateOutdatedOcsIds.php
+++ /dev/null
@@ -1,106 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Lukas Reschke <lukas@statuscode.ch>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- *
- * @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 <http://www.gnu.org/licenses/>
- *
- */
-
-namespace OC\Repair;
-
-use OCP\IConfig;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-/**
- * Class UpdateOutdatedOcsIds is used to update invalid outdated OCS IDs, this is
- * for example the case when an application has had another OCS ID in the past such
- * as for contacts and calendar when apps.owncloud.com migrated to a unified identifier
- * for multiple versions.
- *
- * @package OC\Repair
- */
-class UpdateOutdatedOcsIds implements IRepairStep {
- /** @var IConfig */
- private $config;
-
- /**
- * @param IConfig $config
- */
- public function __construct(IConfig $config) {
- $this->config = $config;
- }
-
- /**
- * {@inheritdoc}
- */
- public function getName() {
- return 'Repair outdated OCS IDs';
- }
-
- /**
- * @param string $appName
- * @param string $oldId
- * @param string $newId
- * @return bool True if updated, false otherwise
- */
- public function fixOcsId($appName, $oldId, $newId) {
- $existingId = $this->config->getAppValue($appName, 'ocsid');
-
- if($existingId === $oldId) {
- $this->config->setAppValue($appName, 'ocsid', $newId);
- return true;
- }
-
- return false;
- }
-
- /**
- * {@inheritdoc}
- */
- public function run(IOutput $output) {
- $appsToUpdate = [
- 'contacts' => [
- 'old' => '166044',
- 'new' => '168708',
- ],
- 'calendar' => [
- 'old' => '166043',
- 'new' => '168707',
- ],
- 'bookmarks' => [
- 'old' => '166042',
- 'new' => '168710',
- ],
- 'search_lucene' => [
- 'old' => '166057',
- 'new' => '168709',
- ],
- 'documents' => [
- 'old' => '166045',
- 'new' => '168711',
- ]
- ];
-
- foreach($appsToUpdate as $appName => $ids) {
- if ($this->fixOcsId($appName, $ids['old'], $ids['new'])) {
- $output->info("Fixed invalid $appName OCS id");
- }
- }
- }
-}