aboutsummaryrefslogtreecommitdiffstats
path: root/lib/private/Repair
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/Repair')
-rw-r--r--lib/private/Repair/AddAppConfigLazyMigration.php62
-rw-r--r--lib/private/Repair/AddMetadataGenerationJob.php43
-rw-r--r--lib/private/Repair/AddRemoveOldTasksBackgroundJob.php8
-rw-r--r--lib/private/Repair/ClearFrontendCaches.php2
-rw-r--r--lib/private/Repair/ClearGeneratedAvatarCache.php2
-rw-r--r--lib/private/Repair/ClearGeneratedAvatarCacheJob.php4
-rw-r--r--lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php2
-rw-r--r--lib/private/Repair/NC20/EncryptionLegacyCipher.php2
-rw-r--r--lib/private/Repair/NC20/EncryptionMigration.php2
-rw-r--r--lib/private/Repair/NC21/ValidatePhoneNumber.php4
-rw-r--r--lib/private/Repair/Owncloud/CleanPreviews.php4
-rw-r--r--lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php49
-rw-r--r--lib/private/Repair/Owncloud/MigrateOauthTables.php4
-rw-r--r--lib/private/Repair/Owncloud/MoveAvatars.php2
-rw-r--r--lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php34
-rw-r--r--lib/private/Repair/Owncloud/UpdateLanguageCodes.php2
-rw-r--r--lib/private/Repair/RemoveLinkShares.php8
-rw-r--r--lib/private/Repair/RepairMimeTypes.php38
-rw-r--r--lib/private/Repair/SqliteAutoincrement.php100
19 files changed, 198 insertions, 174 deletions
diff --git a/lib/private/Repair/AddAppConfigLazyMigration.php b/lib/private/Repair/AddAppConfigLazyMigration.php
new file mode 100644
index 00000000000..1f466b98b28
--- /dev/null
+++ b/lib/private/Repair/AddAppConfigLazyMigration.php
@@ -0,0 +1,62 @@
+<?php
+
+declare(strict_types=1);
+/**
+ * @copyright Copyright (c) 2024 Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @author Maxence Lange <maxence@artificial-owl.com>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OC\Repair;
+
+use OCP\IAppConfig;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+use Psr\Log\LoggerInterface;
+
+class AddAppConfigLazyMigration implements IRepairStep {
+ /**
+ * Just add config values that needs to be migrated to lazy loading
+ */
+ private static array $lazyAppConfig = [
+ 'core' => [
+ 'oc.integritycheck.checker',
+ ],
+ ];
+
+ public function __construct(
+ private IAppConfig $appConfig,
+ private LoggerInterface $logger,
+ ) {
+ }
+
+ public function getName() {
+ return 'migrate lazy config values';
+ }
+
+ public function run(IOutput $output) {
+ $c = 0;
+ foreach (self::$lazyAppConfig as $appId => $configKeys) {
+ foreach ($configKeys as $configKey) {
+ $c += (int)$this->appConfig->updateLazy($appId, $configKey, true);
+ }
+ }
+
+ $this->logger->notice('core/BackgroundJobs/AppConfigLazyMigration: ' . $c . ' config values updated');
+ }
+}
diff --git a/lib/private/Repair/AddMetadataGenerationJob.php b/lib/private/Repair/AddMetadataGenerationJob.php
new file mode 100644
index 00000000000..72e5df03bbd
--- /dev/null
+++ b/lib/private/Repair/AddMetadataGenerationJob.php
@@ -0,0 +1,43 @@
+<?php
+/**
+ * @copyright Copyright (c) 2023 Louis Chmn <louis@chmn.me>
+ *
+ * @author Louis Chmn <louis@chmn.me>
+ *
+ * @license GNU AGPL version 3 or any later version
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License as
+ * published by the Free Software Foundation, either version 3 of the
+ * License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ */
+namespace OC\Repair;
+
+use OC\Core\BackgroundJobs\GenerateMetadataJob;
+use OCP\BackgroundJob\IJobList;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
+
+class AddMetadataGenerationJob implements IRepairStep {
+ public function __construct(
+ private IJobList $jobList,
+ ) {
+ }
+
+ public function getName() {
+ return 'Queue a job to generate metadata';
+ }
+
+ public function run(IOutput $output) {
+ $this->jobList->add(GenerateMetadataJob::class);
+ }
+}
diff --git a/lib/private/Repair/AddRemoveOldTasksBackgroundJob.php b/lib/private/Repair/AddRemoveOldTasksBackgroundJob.php
index 94ae39f2183..00badbb726d 100644
--- a/lib/private/Repair/AddRemoveOldTasksBackgroundJob.php
+++ b/lib/private/Repair/AddRemoveOldTasksBackgroundJob.php
@@ -25,7 +25,8 @@ declare(strict_types=1);
*/
namespace OC\Repair;
-use OC\TextProcessing\RemoveOldTasksBackgroundJob;
+use OC\TextProcessing\RemoveOldTasksBackgroundJob as RemoveOldTextProcessingTasksBackgroundJob;
+use OC\TextToImage\RemoveOldTasksBackgroundJob as RemoveOldTextToImageTasksBackgroundJob;
use OCP\BackgroundJob\IJobList;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
@@ -38,10 +39,11 @@ class AddRemoveOldTasksBackgroundJob implements IRepairStep {
}
public function getName(): string {
- return 'Add language model tasks cleanup job';
+ return 'Add AI tasks cleanup job';
}
public function run(IOutput $output) {
- $this->jobList->add(RemoveOldTasksBackgroundJob::class);
+ $this->jobList->add(RemoveOldTextProcessingTasksBackgroundJob::class);
+ $this->jobList->add(RemoveOldTextToImageTasksBackgroundJob::class);
}
}
diff --git a/lib/private/Repair/ClearFrontendCaches.php b/lib/private/Repair/ClearFrontendCaches.php
index bf94e5bfbff..3661560c5f6 100644
--- a/lib/private/Repair/ClearFrontendCaches.php
+++ b/lib/private/Repair/ClearFrontendCaches.php
@@ -37,7 +37,7 @@ class ClearFrontendCaches implements IRepairStep {
protected $jsCombiner;
public function __construct(ICacheFactory $cacheFactory,
- JSCombiner $JSCombiner) {
+ JSCombiner $JSCombiner) {
$this->cacheFactory = $cacheFactory;
$this->jsCombiner = $JSCombiner;
}
diff --git a/lib/private/Repair/ClearGeneratedAvatarCache.php b/lib/private/Repair/ClearGeneratedAvatarCache.php
index fb3b42847dc..88b2b07ead5 100644
--- a/lib/private/Repair/ClearGeneratedAvatarCache.php
+++ b/lib/private/Repair/ClearGeneratedAvatarCache.php
@@ -25,8 +25,8 @@
namespace OC\Repair;
use OC\Avatar\AvatarManager;
-use OCP\IConfig;
use OCP\BackgroundJob\IJobList;
+use OCP\IConfig;
use OCP\Migration\IOutput;
use OCP\Migration\IRepairStep;
diff --git a/lib/private/Repair/ClearGeneratedAvatarCacheJob.php b/lib/private/Repair/ClearGeneratedAvatarCacheJob.php
index e8513e7a933..5caa74638e5 100644
--- a/lib/private/Repair/ClearGeneratedAvatarCacheJob.php
+++ b/lib/private/Repair/ClearGeneratedAvatarCacheJob.php
@@ -20,9 +20,9 @@
*/
namespace OC\Repair;
-use OCP\BackgroundJob\QueuedJob;
-use OCP\AppFramework\Utility\ITimeFactory;
use OC\Avatar\AvatarManager;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
class ClearGeneratedAvatarCacheJob extends QueuedJob {
protected AvatarManager $avatarManager;
diff --git a/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php b/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php
index d5ae1d7ab63..185ff3be1be 100644
--- a/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php
+++ b/lib/private/Repair/NC18/ResetGeneratedAvatarFlag.php
@@ -37,7 +37,7 @@ class ResetGeneratedAvatarFlag implements IRepairStep {
private $connection;
public function __construct(IConfig $config,
- IDBConnection $connection) {
+ IDBConnection $connection) {
$this->config = $config;
$this->connection = $connection;
}
diff --git a/lib/private/Repair/NC20/EncryptionLegacyCipher.php b/lib/private/Repair/NC20/EncryptionLegacyCipher.php
index a7d008e87be..42a8778662b 100644
--- a/lib/private/Repair/NC20/EncryptionLegacyCipher.php
+++ b/lib/private/Repair/NC20/EncryptionLegacyCipher.php
@@ -38,7 +38,7 @@ class EncryptionLegacyCipher implements IRepairStep {
private $manager;
public function __construct(IConfig $config,
- IManager $manager) {
+ IManager $manager) {
$this->config = $config;
$this->manager = $manager;
}
diff --git a/lib/private/Repair/NC20/EncryptionMigration.php b/lib/private/Repair/NC20/EncryptionMigration.php
index 239a62c2718..dea51b1b57e 100644
--- a/lib/private/Repair/NC20/EncryptionMigration.php
+++ b/lib/private/Repair/NC20/EncryptionMigration.php
@@ -38,7 +38,7 @@ class EncryptionMigration implements IRepairStep {
private $manager;
public function __construct(IConfig $config,
- IManager $manager) {
+ IManager $manager) {
$this->config = $config;
$this->manager = $manager;
}
diff --git a/lib/private/Repair/NC21/ValidatePhoneNumber.php b/lib/private/Repair/NC21/ValidatePhoneNumber.php
index b3534dbeae8..51120c9d139 100644
--- a/lib/private/Repair/NC21/ValidatePhoneNumber.php
+++ b/lib/private/Repair/NC21/ValidatePhoneNumber.php
@@ -42,8 +42,8 @@ class ValidatePhoneNumber implements IRepairStep {
private $accountManager;
public function __construct(IUserManager $userManager,
- IAccountManager $accountManager,
- IConfig $config) {
+ IAccountManager $accountManager,
+ IConfig $config) {
$this->config = $config;
$this->userManager = $userManager;
$this->accountManager = $accountManager;
diff --git a/lib/private/Repair/Owncloud/CleanPreviews.php b/lib/private/Repair/Owncloud/CleanPreviews.php
index 853a94c8adc..2020ae8bfc1 100644
--- a/lib/private/Repair/Owncloud/CleanPreviews.php
+++ b/lib/private/Repair/Owncloud/CleanPreviews.php
@@ -47,8 +47,8 @@ class CleanPreviews implements IRepairStep {
* @param IConfig $config
*/
public function __construct(IJobList $jobList,
- IUserManager $userManager,
- IConfig $config) {
+ IUserManager $userManager,
+ IConfig $config) {
$this->jobList = $jobList;
$this->userManager = $userManager;
$this->config = $config;
diff --git a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php
index 7f4bbc35c17..a23816e4711 100644
--- a/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php
+++ b/lib/private/Repair/Owncloud/CleanPreviewsBackgroundJob.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -22,9 +25,9 @@
*/
namespace OC\Repair\Owncloud;
-use OC\BackgroundJob\QueuedJob;
use OCP\AppFramework\Utility\ITimeFactory;
use OCP\BackgroundJob\IJobList;
+use OCP\BackgroundJob\QueuedJob;
use OCP\Files\Folder;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
@@ -33,33 +36,14 @@ use OCP\IUserManager;
use Psr\Log\LoggerInterface;
class CleanPreviewsBackgroundJob extends QueuedJob {
- /** @var IRootFolder */
- private $rootFolder;
-
- private LoggerInterface $logger;
-
- /** @var IJobList */
- private $jobList;
-
- /** @var ITimeFactory */
- private $timeFactory;
-
- /** @var IUserManager */
- private $userManager;
-
- /**
- * CleanPreviewsBackgroundJob constructor.
- */
- public function __construct(IRootFolder $rootFolder,
- LoggerInterface $logger,
- IJobList $jobList,
- ITimeFactory $timeFactory,
- IUserManager $userManager) {
- $this->rootFolder = $rootFolder;
- $this->logger = $logger;
- $this->jobList = $jobList;
- $this->timeFactory = $timeFactory;
- $this->userManager = $userManager;
+ public function __construct(
+ private IRootFolder $rootFolder,
+ private LoggerInterface $logger,
+ private IJobList $jobList,
+ ITimeFactory $timeFactory,
+ private IUserManager $userManager,
+ ) {
+ parent::__construct($timeFactory);
}
public function run($arguments) {
@@ -80,10 +64,9 @@ class CleanPreviewsBackgroundJob extends QueuedJob {
}
/**
- * @param $uid
- * @return bool
+ * @param string $uid
*/
- private function cleanupPreviews($uid) {
+ private function cleanupPreviews($uid): bool {
try {
$userFolder = $this->rootFolder->getUserFolder($uid);
} catch (NotFoundException $e) {
@@ -101,7 +84,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob {
$thumbnails = $thumbnailFolder->getDirectoryListing();
- $start = $this->timeFactory->getTime();
+ $start = $this->time->getTime();
foreach ($thumbnails as $thumbnail) {
try {
$thumbnail->delete();
@@ -109,7 +92,7 @@ class CleanPreviewsBackgroundJob extends QueuedJob {
// Ignore
}
- if (($this->timeFactory->getTime() - $start) > 15) {
+ if (($this->time->getTime() - $start) > 15) {
return false;
}
}
diff --git a/lib/private/Repair/Owncloud/MigrateOauthTables.php b/lib/private/Repair/Owncloud/MigrateOauthTables.php
index 5bf0816d8de..ae2b46e1949 100644
--- a/lib/private/Repair/Owncloud/MigrateOauthTables.php
+++ b/lib/private/Repair/Owncloud/MigrateOauthTables.php
@@ -20,11 +20,11 @@
*/
namespace OC\Repair\Owncloud;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
use OC\DB\Connection;
use OC\DB\SchemaWrapper;
use OCP\DB\QueryBuilder\IQueryBuilder;
+use OCP\Migration\IOutput;
+use OCP\Migration\IRepairStep;
class MigrateOauthTables implements IRepairStep {
/** @var Connection */
diff --git a/lib/private/Repair/Owncloud/MoveAvatars.php b/lib/private/Repair/Owncloud/MoveAvatars.php
index 44ba9b7643b..1ec08710b3a 100644
--- a/lib/private/Repair/Owncloud/MoveAvatars.php
+++ b/lib/private/Repair/Owncloud/MoveAvatars.php
@@ -41,7 +41,7 @@ class MoveAvatars implements IRepairStep {
* @param IConfig $config
*/
public function __construct(IJobList $jobList,
- IConfig $config) {
+ IConfig $config) {
$this->jobList = $jobList;
$this->config = $config;
}
diff --git a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php
index 83c78c2cba4..9f01c4051e6 100644
--- a/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php
+++ b/lib/private/Repair/Owncloud/MoveAvatarsBackgroundJob.php
@@ -1,4 +1,7 @@
<?php
+
+declare(strict_types=1);
+
/**
* @copyright 2016 Roeland Jago Douma <roeland@famdouma.nl>
*
@@ -23,10 +26,11 @@
*/
namespace OC\Repair\Owncloud;
-use OC\BackgroundJob\QueuedJob;
+use OCP\AppFramework\Utility\ITimeFactory;
+use OCP\BackgroundJob\QueuedJob;
use OCP\Files\IRootFolder;
use OCP\Files\NotFoundException;
-use OCP\Files\Storage;
+use OCP\Files\Storage\IStorage;
use OCP\IAvatarManager;
use OCP\IUser;
use OCP\IUserManager;
@@ -34,22 +38,16 @@ use Psr\Log\LoggerInterface;
use function is_resource;
class MoveAvatarsBackgroundJob extends QueuedJob {
- /** @var IUserManager */
- private $userManager;
-
- /** @var LoggerInterface */
- private $logger;
-
- /** @var IAvatarManager */
- private $avatarManager;
-
- /** @var Storage */
- private $owncloudAvatarStorage;
+ private ?IStorage $owncloudAvatarStorage = null;
- public function __construct(IUserManager $userManager, LoggerInterface $logger, IAvatarManager $avatarManager, IRootFolder $rootFolder) {
- $this->userManager = $userManager;
- $this->logger = $logger;
- $this->avatarManager = $avatarManager;
+ public function __construct(
+ private IUserManager $userManager,
+ private LoggerInterface $logger,
+ private IAvatarManager $avatarManager,
+ private IRootFolder $rootFolder,
+ ITimeFactory $time,
+ ) {
+ parent::__construct($time);
try {
$this->owncloudAvatarStorage = $rootFolder->get('avatars')->getStorage();
} catch (\Exception $e) {
@@ -69,7 +67,7 @@ class MoveAvatarsBackgroundJob extends QueuedJob {
}
$counter = 0;
- $this->userManager->callForSeenUsers(function (IUser $user) use ($counter) {
+ $this->userManager->callForSeenUsers(function (IUser $user) use (&$counter) {
$uid = $user->getUID();
$path = 'avatars/' . $this->buildOwnCloudAvatarPath($uid);
diff --git a/lib/private/Repair/Owncloud/UpdateLanguageCodes.php b/lib/private/Repair/Owncloud/UpdateLanguageCodes.php
index e08a0b55a9a..ae8e8bb0743 100644
--- a/lib/private/Repair/Owncloud/UpdateLanguageCodes.php
+++ b/lib/private/Repair/Owncloud/UpdateLanguageCodes.php
@@ -40,7 +40,7 @@ class UpdateLanguageCodes implements IRepairStep {
* @param IConfig $config
*/
public function __construct(IDBConnection $connection,
- IConfig $config) {
+ IConfig $config) {
$this->connection = $connection;
$this->config = $config;
}
diff --git a/lib/private/Repair/RemoveLinkShares.php b/lib/private/Repair/RemoveLinkShares.php
index b45a1d83a56..3e47e3233a2 100644
--- a/lib/private/Repair/RemoveLinkShares.php
+++ b/lib/private/Repair/RemoveLinkShares.php
@@ -54,10 +54,10 @@ class RemoveLinkShares implements IRepairStep {
private $timeFactory;
public function __construct(IDBConnection $connection,
- IConfig $config,
- IGroupManager $groupManager,
- IManager $notificationManager,
- ITimeFactory $timeFactory) {
+ IConfig $config,
+ IGroupManager $groupManager,
+ IManager $notificationManager,
+ ITimeFactory $timeFactory) {
$this->connection = $connection;
$this->config = $config;
$this->groupManager = $groupManager;
diff --git a/lib/private/Repair/RepairMimeTypes.php b/lib/private/Repair/RepairMimeTypes.php
index ee5a84ad65c..b204c27a9a2 100644
--- a/lib/private/Repair/RepairMimeTypes.php
+++ b/lib/private/Repair/RepairMimeTypes.php
@@ -49,7 +49,7 @@ class RepairMimeTypes implements IRepairStep {
protected $folderMimeTypeId;
public function __construct(IConfig $config,
- IDBConnection $connection) {
+ IDBConnection $connection) {
$this->config = $config;
$this->connection = $connection;
}
@@ -229,6 +229,30 @@ class RepairMimeTypes implements IRepairStep {
return $this->updateMimetypes($updatedMimetypes);
}
+ private function introduceEnhancedMetafileFormatType() {
+ $updatedMimetypes = [
+ 'emf' => 'image/emf',
+ ];
+
+ return $this->updateMimetypes($updatedMimetypes);
+ }
+
+ private function introduceEmlAndMsgFormatType() {
+ $updatedMimetypes = [
+ 'eml' => 'message/rfc822',
+ 'msg' => 'application/vnd.ms-outlook',
+ ];
+
+ return $this->updateMimetypes($updatedMimetypes);
+ }
+
+ private function introduceAacAudioType() {
+ $updatedMimetypes = [
+ 'aac' => 'audio/aac',
+ ];
+
+ return $this->updateMimetypes($updatedMimetypes);
+ }
/**
* Fix mime types
@@ -286,5 +310,17 @@ class RepairMimeTypes implements IRepairStep {
if (version_compare($ocVersionFromBeforeUpdate, '26.0.0.1', '<') && $this->introduceAsciidocType()) {
$out->info('Fixed AsciiDoc mime types');
}
+
+ if (version_compare($ocVersionFromBeforeUpdate, '28.0.0.5', '<') && $this->introduceEnhancedMetafileFormatType()) {
+ $out->info('Fixed Enhanced Metafile Format mime types');
+ }
+
+ if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.2', '<') && $this->introduceEmlAndMsgFormatType()) {
+ $out->info('Fixed eml and msg mime type');
+ }
+
+ if (version_compare($ocVersionFromBeforeUpdate, '29.0.0.6', '<') && $this->introduceAacAudioType()) {
+ $out->info('Fixed aac mime type');
+ }
}
}
diff --git a/lib/private/Repair/SqliteAutoincrement.php b/lib/private/Repair/SqliteAutoincrement.php
deleted file mode 100644
index 4a8b2a45d3f..00000000000
--- a/lib/private/Repair/SqliteAutoincrement.php
+++ /dev/null
@@ -1,100 +0,0 @@
-<?php
-/**
- * @copyright Copyright (c) 2016, ownCloud, Inc.
- *
- * @author Roeland Jago Douma <roeland@famdouma.nl>
- * @author Thomas Müller <thomas.mueller@tmit.eu>
- * @author Vincent Petry <vincent@nextcloud.com>
- *
- * @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\SqlitePlatform;
-use Doctrine\DBAL\Schema\ColumnDiff;
-use Doctrine\DBAL\Schema\SchemaDiff;
-use Doctrine\DBAL\Schema\SchemaException;
-use Doctrine\DBAL\Schema\TableDiff;
-use OCP\Migration\IOutput;
-use OCP\Migration\IRepairStep;
-
-/**
- * Fixes Sqlite autoincrement by forcing the SQLite table schemas to be
- * altered in order to retrigger SQL schema generation through OCSqlitePlatform.
- */
-class SqliteAutoincrement implements IRepairStep {
- /**
- * @var \OC\DB\Connection
- */
- protected $connection;
-
- /**
- * @param \OC\DB\Connection $connection
- */
- public function __construct($connection) {
- $this->connection = $connection;
- }
-
- public function getName() {
- return 'Repair SQLite autoincrement';
- }
-
- /**
- * Fix mime types
- */
- public function run(IOutput $out) {
- if (!$this->connection->getDatabasePlatform() instanceof SqlitePlatform) {
- return;
- }
-
- $sourceSchema = $this->connection->getSchemaManager()->createSchema();
-
- $schemaDiff = new SchemaDiff();
-
- foreach ($sourceSchema->getTables() as $tableSchema) {
- $primaryKey = $tableSchema->getPrimaryKey();
- if (!$primaryKey) {
- continue;
- }
-
- $columnNames = $primaryKey->getColumns();
-
- // add a column diff for every primary key column,
- // but do not actually change anything, this will
- // force the generation of SQL statements to alter
- // those tables, which will then trigger the
- // specific SQL code from OCSqlitePlatform
- try {
- $tableDiff = new TableDiff($tableSchema->getName());
- $tableDiff->fromTable = $tableSchema;
- foreach ($columnNames as $columnName) {
- $columnSchema = $tableSchema->getColumn($columnName);
- $columnDiff = new ColumnDiff($columnSchema->getName(), $columnSchema);
- $tableDiff->changedColumns[$columnSchema->getName()] = $columnDiff;
- $schemaDiff->changedTables[] = $tableDiff;
- }
- } catch (SchemaException $e) {
- // ignore
- }
- }
-
- $this->connection->beginTransaction();
- foreach ($schemaDiff->toSql($this->connection->getDatabasePlatform()) as $sql) {
- $this->connection->query($sql);
- }
- $this->connection->commit();
- }
-}