diff options
author | Morris Jobke <hey@morrisjobke.de> | 2021-03-24 20:27:39 +0100 |
---|---|---|
committer | Morris Jobke <hey@morrisjobke.de> | 2021-03-24 22:15:44 +0100 |
commit | ab48d5e8cbb653767070a286650b87ae97461f37 (patch) | |
tree | 57888a2d7b536c94bcc309e33566ea0db840c2d7 /core | |
parent | bb0c50717cd604ffeafacafe901a70c894ed29f3 (diff) | |
download | nextcloud-server-ab48d5e8cbb653767070a286650b87ae97461f37.tar.gz nextcloud-server-ab48d5e8cbb653767070a286650b87ae97461f37.zip |
Cleanup unneeded code around database.xml
Signed-off-by: Morris Jobke <hey@morrisjobke.de>
Diffstat (limited to 'core')
-rw-r--r-- | core/Command/Db/ConvertType.php | 1 | ||||
-rw-r--r-- | core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php | 206 | ||||
-rw-r--r-- | core/register_command.php | 1 |
3 files changed, 0 insertions, 208 deletions
diff --git a/core/Command/Db/ConvertType.php b/core/Command/Db/ConvertType.php index 907cfc7d331..e4252264dbb 100644 --- a/core/Command/Db/ConvertType.php +++ b/core/Command/Db/ConvertType.php @@ -243,7 +243,6 @@ class ConvertType extends Command implements CompletionAwareInterface { $toMS->migrate($currentMigration); } - $schemaManager = new \OC\DB\MDB2SchemaManager($toDB); $apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps(); foreach ($apps as $app) { $output->writeln('<info> - '.$app.'</info>'); diff --git a/core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php b/core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php deleted file mode 100644 index 9101957a97c..00000000000 --- a/core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php +++ /dev/null @@ -1,206 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2017 Joas Schilling <coding@schilljs.com> - * - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Joas Schilling <coding@schilljs.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\Core\Command\Db\Migrations; - -use Doctrine\DBAL\Schema\Schema; -use OC\DB\Connection; -use OC\DB\MDB2SchemaReader; -use OC\DB\MigrationService; -use OC\Migration\ConsoleOutput; -use OCP\App\IAppManager; -use OCP\IConfig; -use Symfony\Component\Console\Input\InputInterface; -use Symfony\Component\Console\Output\OutputInterface; - -class GenerateFromSchemaFileCommand extends GenerateCommand { - - /** @var IConfig */ - protected $config; - - public function __construct(IConfig $config, IAppManager $appManager, Connection $connection) { - parent::__construct($connection, $appManager); - $this->config = $config; - } - - - protected function configure() { - parent::configure(); - - $this->setName('migrations:generate-from-schema'); - } - - public function execute(InputInterface $input, OutputInterface $output): int { - $appName = $input->getArgument('app'); - $version = $input->getArgument('version'); - - if (!preg_match('/^\d{1,16}$/',$version)) { - $output->writeln('<error>The given version is invalid. Only 0-9 are allowed (max. 16 digits)</error>'); - return 1; - } - - $schemaFile = $this->appManager->getAppPath($appName) . '/appinfo/database.xml'; - if (!file_exists($schemaFile)) { - $output->writeln('<error>App ' . $appName . ' does not have a database.xml file</error>'); - return 2; - } - - $reader = new MDB2SchemaReader($this->config, $this->connection->getDatabasePlatform()); - $schema = new Schema(); - $reader->loadSchemaFromFile($schemaFile, $schema); - - $schemaBody = $this->schemaToMigration($schema); - - $ms = new MigrationService($appName, $this->connection, new ConsoleOutput($output)); - - $date = date('YmdHis'); - $path = $this->generateMigration($ms, 'Version' . $version . 'Date' . $date, $schemaBody); - - $output->writeln("New migration class has been generated to <info>$path</info>"); - return 0; - } - - /** - * @param Schema $schema - * @return string - */ - protected function schemaToMigration(Schema $schema) { - $content = <<<'EOT' - /** @var ISchemaWrapper $schema */ - $schema = $schemaClosure(); - -EOT; - - foreach ($schema->getTables() as $table) { - $content .= str_replace('{{table-name}}', substr($table->getName(), 3), <<<'EOT' - - if (!$schema->hasTable('{{table-name}}')) { - $table = $schema->createTable('{{table-name}}'); - -EOT - ); - - foreach ($table->getColumns() as $column) { - $content .= str_replace(['{{name}}', '{{type}}'], [$column->getName(), $column->getType()->getName()], <<<'EOT' - $table->addColumn('{{name}}', '{{type}}', [ - -EOT - ); - if ($column->getAutoincrement()) { - $content .= <<<'EOT' - 'autoincrement' => true, - -EOT; - } - $content .= str_replace('{{notnull}}', $column->getNotnull() ? 'true' : 'false', <<<'EOT' - 'notnull' => {{notnull}}, - -EOT - ); - if ($column->getLength() !== null) { - $content .= str_replace('{{length}}', $column->getLength(), <<<'EOT' - 'length' => {{length}}, - -EOT - ); - } - $default = $column->getDefault(); - if ($default !== null) { - if (is_string($default)) { - $default = "'$default'"; - } elseif (is_bool($default)) { - $default = ($default === true) ? 'true' : 'false'; - } - $content .= str_replace('{{default}}', $default, <<<'EOT' - 'default' => {{default}}, - -EOT - ); - } - if ($column->getUnsigned()) { - $content .= <<<'EOT' - 'unsigned' => true, - -EOT; - } - - $content .= <<<'EOT' - ]); - -EOT; - } - - $content .= <<<'EOT' - -EOT; - - $primaryKey = $table->getPrimaryKey(); - if ($primaryKey !== null) { - $content .= str_replace('{{columns}}', implode('\', \'', $primaryKey->getUnquotedColumns()), <<<'EOT' - $table->setPrimaryKey(['{{columns}}']); - -EOT - ); - } - - foreach ($table->getIndexes() as $index) { - if ($index->isPrimary()) { - continue; - } - - if ($index->isUnique()) { - $content .= str_replace( - ['{{columns}}', '{{name}}'], - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], - <<<'EOT' - $table->addUniqueIndex(['{{columns}}'], '{{name}}'); - -EOT - ); - } else { - $content .= str_replace( - ['{{columns}}', '{{name}}'], - [implode('\', \'', $index->getUnquotedColumns()), $index->getName()], - <<<'EOT' - $table->addIndex(['{{columns}}'], '{{name}}'); - -EOT - ); - } - } - - $content .= <<<'EOT' - } - -EOT; - } - - $content .= <<<'EOT' - return $schema; -EOT; - - return $content; - } -} diff --git a/core/register_command.php b/core/register_command.php index 3d5d879f012..2a68cbcbe87 100644 --- a/core/register_command.php +++ b/core/register_command.php @@ -109,7 +109,6 @@ if (\OC::$server->getConfig()->getSystemValue('installed', false)) { $application->add(new OC\Core\Command\Db\Migrations\StatusCommand(\OC::$server->get(\OC\DB\Connection::class))); $application->add(new OC\Core\Command\Db\Migrations\MigrateCommand(\OC::$server->get(\OC\DB\Connection::class))); $application->add(new OC\Core\Command\Db\Migrations\GenerateCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getAppManager())); - $application->add(new OC\Core\Command\Db\Migrations\GenerateFromSchemaFileCommand(\OC::$server->getConfig(), \OC::$server->getAppManager(), \OC::$server->get(\OC\DB\Connection::class))); $application->add(new OC\Core\Command\Db\Migrations\ExecuteCommand(\OC::$server->get(\OC\DB\Connection::class), \OC::$server->getConfig())); $application->add(new OC\Core\Command\Encryption\Disable(\OC::$server->getConfig())); |