aboutsummaryrefslogtreecommitdiffstats
path: root/core/Command/Db
diff options
context:
space:
mode:
Diffstat (limited to 'core/Command/Db')
-rw-r--r--core/Command/Db/AddMissingIndices.php15
-rw-r--r--core/Command/Db/ConvertFilecacheBigInt.php1
-rw-r--r--core/Command/Db/ConvertMysqlToMB4.php1
-rw-r--r--core/Command/Db/ConvertType.php25
-rw-r--r--core/Command/Db/Migrations/ExecuteCommand.php1
-rw-r--r--core/Command/Db/Migrations/GenerateCommand.php9
-rw-r--r--core/Command/Db/Migrations/GenerateMetadataCommand.php6
7 files changed, 28 insertions, 30 deletions
diff --git a/core/Command/Db/AddMissingIndices.php b/core/Command/Db/AddMissingIndices.php
index ec36400d291..eec0aedce11 100644
--- a/core/Command/Db/AddMissingIndices.php
+++ b/core/Command/Db/AddMissingIndices.php
@@ -86,14 +86,7 @@ class AddMissingIndices extends Command {
if ($schema->hasTable($toReplaceIndex['tableName'])) {
$table = $schema->getTable($toReplaceIndex['tableName']);
- $allOldIndicesExists = true;
- foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
- if (!$table->hasIndex($oldIndexName)) {
- $allOldIndicesExists = false;
- }
- }
-
- if (!$allOldIndicesExists) {
+ if ($table->hasIndex($toReplaceIndex['newIndexName'])) {
continue;
}
@@ -110,8 +103,10 @@ class AddMissingIndices extends Command {
}
foreach ($toReplaceIndex['oldIndexNames'] as $oldIndexName) {
- $output->writeln('<info>Removing ' . $oldIndexName . ' index from the ' . $table->getName() . ' table</info>');
- $table->dropIndex($oldIndexName);
+ if ($table->hasIndex($oldIndexName)) {
+ $output->writeln('<info>Removing ' . $oldIndexName . ' index from the ' . $table->getName() . ' table</info>');
+ $table->dropIndex($oldIndexName);
+ }
}
if (!$dryRun) {
diff --git a/core/Command/Db/ConvertFilecacheBigInt.php b/core/Command/Db/ConvertFilecacheBigInt.php
index f5028aacaef..0d96d139701 100644
--- a/core/Command/Db/ConvertFilecacheBigInt.php
+++ b/core/Command/Db/ConvertFilecacheBigInt.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-License-Identifier: AGPL-3.0-or-later
diff --git a/core/Command/Db/ConvertMysqlToMB4.php b/core/Command/Db/ConvertMysqlToMB4.php
index 8a2abecc804..926e56c4300 100644
--- a/core/Command/Db/ConvertMysqlToMB4.php
+++ b/core/Command/Db/ConvertMysqlToMB4.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
* SPDX-License-Identifier: AGPL-3.0-only
diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php
index b26494417ec..0067bec4d9e 100644
--- a/core/Command/Db/ConvertType.php
+++ b/core/Command/Db/ConvertType.php
@@ -13,9 +13,12 @@ use Doctrine\DBAL\Schema\Table;
use OC\DB\Connection;
use OC\DB\ConnectionFactory;
use OC\DB\MigrationService;
+use OC\DB\PgSqlTools;
+use OCP\App\IAppManager;
use OCP\DB\QueryBuilder\IQueryBuilder;
use OCP\DB\Types;
use OCP\IConfig;
+use OCP\Server;
use Stecman\Component\Symfony\Console\BashCompletion\Completion\CompletionAwareInterface;
use Stecman\Component\Symfony\Console\BashCompletion\CompletionContext;
use Symfony\Component\Console\Command\Command;
@@ -36,6 +39,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
public function __construct(
protected IConfig $config,
protected ConnectionFactory $connectionFactory,
+ protected IAppManager $appManager,
) {
parent::__construct();
}
@@ -155,18 +159,11 @@ class ConvertType extends Command implements CompletionAwareInterface {
}
protected function execute(InputInterface $input, OutputInterface $output): int {
- // WARNING:
- // Leave in place until #45257 is addressed to prevent data loss (hopefully in time for the next maintenance release)
- //
- throw new \InvalidArgumentException(
- 'This command is temporarily disabled (until the next maintenance release).'
- );
-
$this->validateInput($input, $output);
$this->readPassword($input, $output);
/** @var Connection $fromDB */
- $fromDB = \OC::$server->get(Connection::class);
+ $fromDB = Server::get(Connection::class);
$toDB = $this->getToDBConnection($input, $output);
if ($input->getOption('clear-schema')) {
@@ -213,11 +210,13 @@ class ConvertType extends Command implements CompletionAwareInterface {
$toMS->migrate($currentMigration);
}
- $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps();
+ $apps = $input->getOption('all-apps')
+ ? $this->appManager->getAllAppsInAppsFolders()
+ : $this->appManager->getEnabledApps();
foreach ($apps as $app) {
$output->writeln('<info> - ' . $app . '</info>');
// Make sure autoloading works...
- \OC_App::loadApp($app);
+ $this->appManager->loadApp($app);
$fromMS = new MigrationService($app, $fromDB);
$currentMigration = $fromMS->getMigration('current');
if ($currentMigration !== '0') {
@@ -229,7 +228,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
protected function getToDBConnection(InputInterface $input, OutputInterface $output) {
$type = $input->getArgument('type');
- $connectionParams = $this->connectionFactory->createConnectionParams();
+ $connectionParams = $this->connectionFactory->createConnectionParams(type: $type);
$connectionParams = array_merge($connectionParams, [
'host' => $input->getArgument('hostname'),
'user' => $input->getArgument('username'),
@@ -243,7 +242,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
}
// parse hostname for unix socket
- if (preg_match('/^(.+)(:(\d+|[^:]+))?$/', $input->getOption('hostname'), $matches)) {
+ if (preg_match('/^(.+)(:(\d+|[^:]+))?$/', $input->getArgument('hostname'), $matches)) {
$connectionParams['host'] = $matches[1];
if (isset($matches[3])) {
if (is_numeric($matches[3])) {
@@ -408,7 +407,7 @@ class ConvertType extends Command implements CompletionAwareInterface {
$this->copyTable($fromDB, $toDB, $schema->getTable($table), $input, $output);
}
if ($input->getArgument('type') === 'pgsql') {
- $tools = new \OC\DB\PgSqlTools($this->config);
+ $tools = new PgSqlTools($this->config);
$tools->resynchronizeDatabaseSequences($toDB);
}
// save new database config
diff --git a/core/Command/Db/Migrations/ExecuteCommand.php b/core/Command/Db/Migrations/ExecuteCommand.php
index cb6edd7c78c..a89072c1ad1 100644
--- a/core/Command/Db/Migrations/ExecuteCommand.php
+++ b/core/Command/Db/Migrations/ExecuteCommand.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
diff --git a/core/Command/Db/Migrations/GenerateCommand.php b/core/Command/Db/Migrations/GenerateCommand.php
index ed29412f00b..a75280fa8b1 100644
--- a/core/Command/Db/Migrations/GenerateCommand.php
+++ b/core/Command/Db/Migrations/GenerateCommand.php
@@ -1,4 +1,5 @@
<?php
+
/**
* SPDX-FileCopyrightText: 2017 Nextcloud GmbH and Nextcloud contributors
* SPDX-FileCopyrightText: 2017 ownCloud GmbH
@@ -22,8 +23,8 @@ use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
class GenerateCommand extends Command implements CompletionAwareInterface {
- protected static $_templateSimple =
- '<?php
+ protected static $_templateSimple
+ = '<?php
declare(strict_types=1);
@@ -38,6 +39,7 @@ use Closure;
use OCP\DB\ISchemaWrapper;
use OCP\Migration\IOutput;
use OCP\Migration\SimpleMigrationStep;
+use Override;
/**
* FIXME Auto-generated migration step: Please modify to your needs!
@@ -49,6 +51,7 @@ class {{classname}} extends SimpleMigrationStep {
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
+ #[Override]
public function preSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
@@ -58,6 +61,7 @@ class {{classname}} extends SimpleMigrationStep {
* @param array $options
* @return null|ISchemaWrapper
*/
+ #[Override]
public function changeSchema(IOutput $output, Closure $schemaClosure, array $options): ?ISchemaWrapper {
{{schemabody}}
}
@@ -67,6 +71,7 @@ class {{classname}} extends SimpleMigrationStep {
* @param Closure(): ISchemaWrapper $schemaClosure
* @param array $options
*/
+ #[Override]
public function postSchemaChange(IOutput $output, Closure $schemaClosure, array $options): void {
}
}
diff --git a/core/Command/Db/Migrations/GenerateMetadataCommand.php b/core/Command/Db/Migrations/GenerateMetadataCommand.php
index ae83f92b29e..581259c99df 100644
--- a/core/Command/Db/Migrations/GenerateMetadataCommand.php
+++ b/core/Command/Db/Migrations/GenerateMetadataCommand.php
@@ -68,15 +68,11 @@ class GenerateMetadataCommand extends Command {
$metadata = [];
foreach ($allApps as $appId) {
// We need to load app before being able to extract Migrations
- // If app was not enabled before, we will disable it afterward.
- $alreadyLoaded = $this->appManager->isInstalled($appId);
+ $alreadyLoaded = $this->appManager->isAppLoaded($appId);
if (!$alreadyLoaded) {
$this->appManager->loadApp($appId);
}
$metadata[$appId] = $this->metadataManager->extractMigrationAttributes($appId);
- if (!$alreadyLoaded) {
- $this->appManager->disableApp($appId);
- }
}
return $metadata;
}