diff options
author | Roeland Jago Douma <rullzer@users.noreply.github.com> | 2021-03-25 08:58:07 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-03-25 08:58:07 +0100 |
commit | c15172bc4ee6183aa0c68a8be71ff623a62031ff (patch) | |
tree | 91c031218173802a2cb66dacc77734d8b504a230 /lib | |
parent | 9af8c0b380ffaabcce18e9872f443f039dcbd549 (diff) | |
parent | ab48d5e8cbb653767070a286650b87ae97461f37 (diff) | |
download | nextcloud-server-c15172bc4ee6183aa0c68a8be71ff623a62031ff.tar.gz nextcloud-server-c15172bc4ee6183aa0c68a8be71ff623a62031ff.zip |
Merge pull request #21641 from nextcloud/techdebt/noid/bye-bye-database-xml
Bye bye database xml
Diffstat (limited to 'lib')
-rw-r--r-- | lib/composer/composer/autoload_classmap.php | 3 | ||||
-rw-r--r-- | lib/composer/composer/autoload_static.php | 3 | ||||
-rw-r--r-- | lib/private/DB/Connection.php | 28 | ||||
-rw-r--r-- | lib/private/DB/MDB2SchemaManager.php | 161 | ||||
-rw-r--r-- | lib/private/DB/MDB2SchemaReader.php | 355 | ||||
-rw-r--r-- | lib/private/Installer.php | 36 | ||||
-rw-r--r-- | lib/private/legacy/OC_App.php | 13 | ||||
-rw-r--r-- | lib/private/legacy/OC_DB.php | 50 |
8 files changed, 42 insertions, 607 deletions
diff --git a/lib/composer/composer/autoload_classmap.php b/lib/composer/composer/autoload_classmap.php index 560ae8845e3..bf07152256d 100644 --- a/lib/composer/composer/autoload_classmap.php +++ b/lib/composer/composer/autoload_classmap.php @@ -821,7 +821,6 @@ return array( 'OC\\Core\\Command\\Db\\ConvertType' => $baseDir . '/core/Command/Db/ConvertType.php', 'OC\\Core\\Command\\Db\\Migrations\\ExecuteCommand' => $baseDir . '/core/Command/Db/Migrations/ExecuteCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\GenerateCommand' => $baseDir . '/core/Command/Db/Migrations/GenerateCommand.php', - 'OC\\Core\\Command\\Db\\Migrations\\GenerateFromSchemaFileCommand' => $baseDir . '/core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\MigrateCommand' => $baseDir . '/core/Command/Db/Migrations/MigrateCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\StatusCommand' => $baseDir . '/core/Command/Db/Migrations/StatusCommand.php', 'OC\\Core\\Command\\Encryption\\ChangeKeyStorageRoot' => $baseDir . '/core/Command/Encryption/ChangeKeyStorageRoot.php', @@ -964,8 +963,6 @@ return array( 'OC\\DB\\ConnectionAdapter' => $baseDir . '/lib/private/DB/ConnectionAdapter.php', 'OC\\DB\\ConnectionFactory' => $baseDir . '/lib/private/DB/ConnectionFactory.php', 'OC\\DB\\Exceptions\\DbalException' => $baseDir . '/lib/private/DB/Exceptions/DbalException.php', - 'OC\\DB\\MDB2SchemaManager' => $baseDir . '/lib/private/DB/MDB2SchemaManager.php', - 'OC\\DB\\MDB2SchemaReader' => $baseDir . '/lib/private/DB/MDB2SchemaReader.php', 'OC\\DB\\MigrationException' => $baseDir . '/lib/private/DB/MigrationException.php', 'OC\\DB\\MigrationService' => $baseDir . '/lib/private/DB/MigrationService.php', 'OC\\DB\\Migrator' => $baseDir . '/lib/private/DB/Migrator.php', diff --git a/lib/composer/composer/autoload_static.php b/lib/composer/composer/autoload_static.php index ce243e4ce3a..e5fe0d55bfd 100644 --- a/lib/composer/composer/autoload_static.php +++ b/lib/composer/composer/autoload_static.php @@ -850,7 +850,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\Core\\Command\\Db\\ConvertType' => __DIR__ . '/../../..' . '/core/Command/Db/ConvertType.php', 'OC\\Core\\Command\\Db\\Migrations\\ExecuteCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/ExecuteCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\GenerateCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/GenerateCommand.php', - 'OC\\Core\\Command\\Db\\Migrations\\GenerateFromSchemaFileCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/GenerateFromSchemaFileCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\MigrateCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/MigrateCommand.php', 'OC\\Core\\Command\\Db\\Migrations\\StatusCommand' => __DIR__ . '/../../..' . '/core/Command/Db/Migrations/StatusCommand.php', 'OC\\Core\\Command\\Encryption\\ChangeKeyStorageRoot' => __DIR__ . '/../../..' . '/core/Command/Encryption/ChangeKeyStorageRoot.php', @@ -993,8 +992,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c 'OC\\DB\\ConnectionAdapter' => __DIR__ . '/../../..' . '/lib/private/DB/ConnectionAdapter.php', 'OC\\DB\\ConnectionFactory' => __DIR__ . '/../../..' . '/lib/private/DB/ConnectionFactory.php', 'OC\\DB\\Exceptions\\DbalException' => __DIR__ . '/../../..' . '/lib/private/DB/Exceptions/DbalException.php', - 'OC\\DB\\MDB2SchemaManager' => __DIR__ . '/../../..' . '/lib/private/DB/MDB2SchemaManager.php', - 'OC\\DB\\MDB2SchemaReader' => __DIR__ . '/../../..' . '/lib/private/DB/MDB2SchemaReader.php', 'OC\\DB\\MigrationException' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationException.php', 'OC\\DB\\MigrationService' => __DIR__ . '/../../..' . '/lib/private/DB/MigrationService.php', 'OC\\DB\\Migrator' => __DIR__ . '/../../..' . '/lib/private/DB/Migrator.php', diff --git a/lib/private/DB/Connection.php b/lib/private/DB/Connection.php index 4d9433122ce..941d8628ca0 100644 --- a/lib/private/DB/Connection.php +++ b/lib/private/DB/Connection.php @@ -44,6 +44,9 @@ use Doctrine\DBAL\Exception; use Doctrine\DBAL\Exception\ConstraintViolationException; use Doctrine\DBAL\Exception\NotNullConstraintViolationException; use Doctrine\DBAL\Platforms\MySQLPlatform; +use Doctrine\DBAL\Platforms\OraclePlatform; +use Doctrine\DBAL\Platforms\PostgreSQL94Platform; +use Doctrine\DBAL\Platforms\SqlitePlatform; use Doctrine\DBAL\Result; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Statement; @@ -509,8 +512,7 @@ class Connection extends \Doctrine\DBAL\Connection { * @throws Exception */ public function createSchema() { - $schemaManager = new MDB2SchemaManager($this); - $migrator = $schemaManager->getMigrator(); + $migrator = $this->getMigrator(); return $migrator->createSchema(); } @@ -522,8 +524,26 @@ class Connection extends \Doctrine\DBAL\Connection { * @throws Exception */ public function migrateToSchema(Schema $toSchema) { - $schemaManager = new MDB2SchemaManager($this); - $migrator = $schemaManager->getMigrator(); + $migrator = $this->getMigrator(); $migrator->migrate($toSchema); } + + private function getMigrator() { + // TODO properly inject those dependencies + $random = \OC::$server->getSecureRandom(); + $platform = $this->getDatabasePlatform(); + $config = \OC::$server->getConfig(); + $dispatcher = \OC::$server->getEventDispatcher(); + if ($platform instanceof SqlitePlatform) { + return new SQLiteMigrator($this, $config, $dispatcher); + } elseif ($platform instanceof OraclePlatform) { + return new OracleMigrator($this, $config, $dispatcher); + } elseif ($platform instanceof MySQLPlatform) { + return new MySQLMigrator($this, $config, $dispatcher); + } elseif ($platform instanceof PostgreSQL94Platform) { + return new PostgreSqlMigrator($this, $config, $dispatcher); + } else { + return new Migrator($this, $config, $dispatcher); + } + } } diff --git a/lib/private/DB/MDB2SchemaManager.php b/lib/private/DB/MDB2SchemaManager.php deleted file mode 100644 index 30c4a87e5b3..00000000000 --- a/lib/private/DB/MDB2SchemaManager.php +++ /dev/null @@ -1,161 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Jörn Friedrich Dreyer <jfd@butonic.de> - * @author Lukas Reschke <lukas@statuscode.ch> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Robin Appelman <robin@icewind.nl> - * @author Roeland Jago Douma <roeland@famdouma.nl> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @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\DB; - -use Doctrine\DBAL\Platforms\MySQLPlatform; -use Doctrine\DBAL\Platforms\OraclePlatform; -use Doctrine\DBAL\Platforms\PostgreSQL94Platform; -use Doctrine\DBAL\Platforms\SqlitePlatform; -use Doctrine\DBAL\Schema\Schema; - -class MDB2SchemaManager { - /** @var Connection $conn */ - protected $conn; - - /** - * @param Connection $conn - */ - public function __construct($conn) { - $this->conn = $conn; - } - - /** - * Creates tables from XML file - * @param string $file file to read structure from - * @return bool - * - * TODO: write more documentation - */ - public function createDbFromStructure($file) { - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); - $toSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); - return $this->executeSchemaChange($toSchema); - } - - /** - * @return \OC\DB\Migrator - */ - public function getMigrator() { - $random = \OC::$server->getSecureRandom(); - $platform = $this->conn->getDatabasePlatform(); - $config = \OC::$server->getConfig(); - $dispatcher = \OC::$server->getEventDispatcher(); - if ($platform instanceof SqlitePlatform) { - return new SQLiteMigrator($this->conn, $config, $dispatcher); - } elseif ($platform instanceof OraclePlatform) { - return new OracleMigrator($this->conn, $config, $dispatcher); - } elseif ($platform instanceof MySQLPlatform) { - return new MySQLMigrator($this->conn, $config, $dispatcher); - } elseif ($platform instanceof PostgreSQL94Platform) { - return new PostgreSqlMigrator($this->conn, $config, $dispatcher); - } else { - return new Migrator($this->conn, $config, $dispatcher); - } - } - - /** - * Reads database schema from file - * - * @param string $file file to read from - * @return \Doctrine\DBAL\Schema\Schema - */ - private function readSchemaFromFile($file) { - $platform = $this->conn->getDatabasePlatform(); - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $platform); - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); - return $schemaReader->loadSchemaFromFile($file, $toSchema); - } - - /** - * update the database scheme - * @param string $file file to read structure from - * @param bool $generateSql only return the sql needed for the upgrade - * @return string|boolean - */ - public function updateDbFromStructure($file, $generateSql = false) { - $toSchema = $this->readSchemaFromFile($file); - $migrator = $this->getMigrator(); - - if ($generateSql) { - return $migrator->generateChangeScript($toSchema); - } else { - $migrator->migrate($toSchema); - return true; - } - } - - /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * @return string - */ - public function generateChangeScript($schema) { - $migrator = $this->getMigrator(); - return $migrator->generateChangeScript($schema); - } - - /** - * remove all tables defined in a database structure xml file - * - * @param string $file the xml file describing the tables - */ - public function removeDBStructure($file) { - $schemaReader = new MDB2SchemaReader(\OC::$server->getConfig(), $this->conn->getDatabasePlatform()); - $toSchema = new Schema([], [], $this->conn->getSchemaManager()->createSchemaConfig()); - $fromSchema = $schemaReader->loadSchemaFromFile($file, $toSchema); - $toSchema = clone $fromSchema; - foreach ($toSchema->getTables() as $table) { - $toSchema->dropTable($table->getName()); - } - $comparator = new \Doctrine\DBAL\Schema\Comparator(); - $schemaDiff = $comparator->compare($fromSchema, $toSchema); - $this->executeSchemaChange($schemaDiff); - } - - /** - * @param \Doctrine\DBAL\Schema\Schema|\Doctrine\DBAL\Schema\SchemaDiff $schema - * @return bool - */ - private function executeSchemaChange($schema) { - $this->conn->beginTransaction(); - foreach ($schema->toSql($this->conn->getDatabasePlatform()) as $sql) { - $this->conn->query($sql); - } - $this->conn->commit(); - - if ($this->conn->getDatabasePlatform() instanceof SqlitePlatform) { - $this->conn->close(); - $this->conn->connect(); - } - return true; - } -} diff --git a/lib/private/DB/MDB2SchemaReader.php b/lib/private/DB/MDB2SchemaReader.php deleted file mode 100644 index 687438495b1..00000000000 --- a/lib/private/DB/MDB2SchemaReader.php +++ /dev/null @@ -1,355 +0,0 @@ -<?php -/** - * @copyright Copyright (c) 2016, ownCloud, Inc. - * - * @author Bart Visscher <bartv@thisnet.nl> - * @author Christoph Wurst <christoph@winzerhof-wurst.at> - * @author Morris Jobke <hey@morrisjobke.de> - * @author Oliver Gasser <oliver.gasser@gmail.com> - * @author Robin Appelman <robin@icewind.nl> - * @author Robin McCorkell <robin@mccorkell.me.uk> - * @author Thomas Müller <thomas.mueller@tmit.eu> - * @author Victor Dubiniuk <dubiniuk@owncloud.com> - * @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\DB; - -use Doctrine\DBAL\Platforms\AbstractPlatform; -use Doctrine\DBAL\Schema\Schema; -use OCP\IConfig; - -class MDB2SchemaReader { - - /** - * @var string $DBTABLEPREFIX - */ - protected $DBTABLEPREFIX; - - /** - * @var \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ - protected $platform; - - /** @var IConfig */ - protected $config; - - /** - * @param \OCP\IConfig $config - * @param \Doctrine\DBAL\Platforms\AbstractPlatform $platform - */ - public function __construct(IConfig $config, AbstractPlatform $platform) { - $this->platform = $platform; - $this->config = $config; - $this->DBTABLEPREFIX = $config->getSystemValue('dbtableprefix', 'oc_'); - } - - /** - * @param string $file - * @param Schema $schema - * @return Schema - * @throws \DomainException - */ - public function loadSchemaFromFile($file, Schema $schema) { - $loadEntities = libxml_disable_entity_loader(false); - $xml = simplexml_load_file($file); - libxml_disable_entity_loader($loadEntities); - foreach ($xml->children() as $child) { - /** - * @var \SimpleXMLElement $child - */ - switch ($child->getName()) { - case 'name': - case 'create': - case 'overwrite': - case 'charset': - break; - case 'table': - $this->loadTable($schema, $child); - break; - default: - throw new \DomainException('Unknown element: ' . $child->getName()); - - } - } - return $schema; - } - - /** - * @param \Doctrine\DBAL\Schema\Schema $schema - * @param \SimpleXMLElement $xml - * @throws \DomainException - */ - private function loadTable($schema, $xml) { - $table = null; - foreach ($xml->children() as $child) { - /** - * @var \SimpleXMLElement $child - */ - switch ($child->getName()) { - case 'name': - $name = (string)$child; - $name = str_replace('*dbprefix*', $this->DBTABLEPREFIX, $name); - $name = $this->platform->quoteIdentifier($name); - $table = $schema->createTable($name); - break; - case 'create': - case 'overwrite': - case 'charset': - break; - case 'declaration': - if (is_null($table)) { - throw new \DomainException('Table declaration before table name'); - } - $this->loadDeclaration($table, $child); - break; - default: - throw new \DomainException('Unknown element: ' . $child->getName()); - - } - } - } - - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \SimpleXMLElement $xml - * @throws \DomainException - */ - private function loadDeclaration($table, $xml) { - foreach ($xml->children() as $child) { - /** - * @var \SimpleXMLElement $child - */ - switch ($child->getName()) { - case 'field': - $this->loadField($table, $child); - break; - case 'index': - $this->loadIndex($table, $child); - break; - default: - throw new \DomainException('Unknown element: ' . $child->getName()); - - } - } - } - - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \SimpleXMLElement $xml - * @throws \DomainException - */ - private function loadField($table, $xml) { - $options = [ 'notnull' => false ]; - foreach ($xml->children() as $child) { - /** - * @var \SimpleXMLElement $child - */ - switch ($child->getName()) { - case 'name': - $name = (string)$child; - $name = $this->platform->quoteIdentifier($name); - break; - case 'type': - $type = (string)$child; - switch ($type) { - case 'text': - $type = 'string'; - break; - case 'clob': - $type = 'text'; - break; - case 'timestamp': - $type = 'datetime'; - break; - case 'numeric': - $type = 'decimal'; - break; - } - break; - case 'length': - $length = (string)$child; - $options['length'] = $length; - break; - case 'unsigned': - $unsigned = $this->asBool($child); - $options['unsigned'] = $unsigned; - break; - case 'notnull': - $notnull = $this->asBool($child); - $options['notnull'] = $notnull; - break; - case 'autoincrement': - $autoincrement = $this->asBool($child); - $options['autoincrement'] = $autoincrement; - break; - case 'default': - $default = (string)$child; - $options['default'] = $default; - break; - case 'comments': - $comment = (string)$child; - $options['comment'] = $comment; - break; - case 'primary': - $primary = $this->asBool($child); - $options['primary'] = $primary; - break; - case 'precision': - $precision = (string)$child; - $options['precision'] = $precision; - break; - case 'scale': - $scale = (string)$child; - $options['scale'] = $scale; - break; - default: - throw new \DomainException('Unknown element: ' . $child->getName()); - - } - } - if (isset($name) && isset($type)) { - if (isset($options['default']) && empty($options['default'])) { - if (empty($options['notnull']) || !$options['notnull']) { - unset($options['default']); - $options['notnull'] = false; - } else { - $options['default'] = ''; - } - if ($type == 'integer' || $type == 'decimal') { - $options['default'] = 0; - } elseif ($type == 'boolean') { - $options['default'] = false; - } - if (!empty($options['autoincrement']) && $options['autoincrement']) { - unset($options['default']); - } - } - if ($type === 'integer' && isset($options['default'])) { - $options['default'] = (int)$options['default']; - } - if ($type === 'integer' && isset($options['length'])) { - $length = $options['length']; - if ($length < 4) { - $type = 'smallint'; - } elseif ($length > 4) { - $type = 'bigint'; - } - } - if ($type === 'boolean' && isset($options['default'])) { - $options['default'] = $this->asBool($options['default']); - } - if (!empty($options['autoincrement']) - && !empty($options['notnull']) - ) { - $options['primary'] = true; - } - - # not used anymore in the options argument - # see https://github.com/doctrine/dbal/commit/138eb85234a1faeaa2e6a32cd7bcc66bb51c64e8#diff-300f55366adb50a32a40882ebdc95c163b141f64cba5f45f20bda04a907b3eb3L82 - # therefore it's read before and then unset right before the addColumn call - $setPrimaryKey = false; - if (!empty($options['primary']) && $options['primary']) { - $setPrimaryKey = true; - } - unset($options['primary']); - $table->addColumn($name, $type, $options); - if ($setPrimaryKey) { - $table->setPrimaryKey([$name]); - } - } - } - - /** - * @param \Doctrine\DBAL\Schema\Table $table - * @param \SimpleXMLElement $xml - * @throws \DomainException - */ - private function loadIndex($table, $xml) { - $name = null; - $fields = []; - foreach ($xml->children() as $child) { - /** - * @var \SimpleXMLElement $child - */ - switch ($child->getName()) { - case 'name': - $name = (string)$child; - break; - case 'primary': - $primary = $this->asBool($child); - break; - case 'unique': - $unique = $this->asBool($child); - break; - case 'field': - foreach ($child->children() as $field) { - /** - * @var \SimpleXMLElement $field - */ - switch ($field->getName()) { - case 'name': - $field_name = (string)$field; - $field_name = $this->platform->quoteIdentifier($field_name); - $fields[] = $field_name; - break; - case 'sorting': - break; - default: - throw new \DomainException('Unknown element: ' . $field->getName()); - - } - } - break; - default: - throw new \DomainException('Unknown element: ' . $child->getName()); - - } - } - if (!empty($fields)) { - if (isset($primary) && $primary) { - if ($table->hasPrimaryKey()) { - return; - } - $table->setPrimaryKey($fields, $name); - } else { - if (isset($unique) && $unique) { - $table->addUniqueIndex($fields, $name); - } else { - $table->addIndex($fields, $name); - } - } - } else { - throw new \DomainException('Empty index definition: ' . $name . ' options:' . print_r($fields, true)); - } - } - - /** - * @param \SimpleXMLElement|string $xml - * @return bool - */ - private function asBool($xml) { - $result = (string)$xml; - if ($result == 'true') { - $result = true; - } elseif ($result == 'false') { - $result = false; - } - return (bool)$result; - } -} diff --git a/lib/private/Installer.php b/lib/private/Installer.php index 2a0fdab87ff..fdf9af7446b 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -46,8 +46,8 @@ use OC\App\AppStore\Fetcher\AppFetcher; use OC\AppFramework\Bootstrap\Coordinator; use OC\Archive\TAR; use OC\DB\Connection; +use OC\DB\MigrationService; use OC_App; -use OC_DB; use OC_Helper; use OCP\Http\Client\IClientService; use OCP\IConfig; @@ -114,6 +114,11 @@ class Installer { } $basedir = $app['path'].'/'.$appId; + + if (is_file($basedir . '/appinfo/database.xml')) { + throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId); + } + $info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true); $l = \OC::$server->getL10N('core'); @@ -152,16 +157,9 @@ class Installer { } //install the database - if (is_file($basedir.'/appinfo/database.xml')) { - if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) { - OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml'); - } else { - OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml'); - } - } else { - $ms = new \OC\DB\MigrationService($info['id'], \OC::$server->get(Connection::class)); - $ms->migrate('latest', true); - } + $ms = new MigrationService($info['id'], \OC::$server->get(Connection::class)); + $ms->migrate('latest', true); + if ($previousVersion) { OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']); } @@ -601,20 +599,8 @@ class Installer { $appPath = OC_App::getAppPath($app); \OC_App::registerAutoloading($app, $appPath); - if (is_file("$appPath/appinfo/database.xml")) { - try { - OC_DB::createDbFromStructure("$appPath/appinfo/database.xml"); - } catch (TableExistsException $e) { - throw new HintException( - 'Failed to enable app ' . $app, - 'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.', - 0, $e - ); - } - } else { - $ms = new \OC\DB\MigrationService($app, \OC::$server->get(Connection::class)); - $ms->migrate('latest', true); - } + $ms = new MigrationService($app, \OC::$server->get(Connection::class)); + $ms->migrate('latest', true); //run appinfo/install.php self::includeAppScript("$appPath/appinfo/install.php"); diff --git a/lib/private/legacy/OC_App.php b/lib/private/legacy/OC_App.php index aeaaf3bf1ea..65365c85e36 100644 --- a/lib/private/legacy/OC_App.php +++ b/lib/private/legacy/OC_App.php @@ -972,6 +972,11 @@ class OC_App { return false; } + if (is_file($appPath . '/appinfo/database.xml')) { + \OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId); + return false; + } + \OC::$server->getAppManager()->clearAppsCache(); $appData = self::getAppInfo($appId); @@ -987,12 +992,8 @@ class OC_App { self::registerAutoloading($appId, $appPath, true); self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']); - if (file_exists($appPath . '/appinfo/database.xml')) { - OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml'); - } else { - $ms = new MigrationService($appId, \OC::$server->get(\OC\DB\Connection::class)); - $ms->migrate(); - } + $ms = new MigrationService($appId, \OC::$server->get(\OC\DB\Connection::class)); + $ms->migrate(); self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']); self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']); diff --git a/lib/private/legacy/OC_DB.php b/lib/private/legacy/OC_DB.php index b5b6c737046..a3919fd1f17 100644 --- a/lib/private/legacy/OC_DB.php +++ b/lib/private/legacy/OC_DB.php @@ -30,8 +30,6 @@ * */ -use OCP\ILogger; - /** * This class manages the access to the database. It basically is a wrapper for * Doctrine with some adaptions. @@ -39,15 +37,6 @@ use OCP\ILogger; class OC_DB { /** - * get MDB2 schema manager - * - * @return \OC\DB\MDB2SchemaManager - */ - private static function getMDB2SchemaManager() { - return new \OC\DB\MDB2SchemaManager(\OC::$server->get(\OC\DB\Connection::class)); - } - - /** * Prepare a SQL query * @param string $query Query string * @param int|null $limit @@ -160,45 +149,6 @@ class OC_DB { } /** - * Creates tables from XML file - * @param string $file file to read structure from - * @return bool - * - * TODO: write more documentation - */ - public static function createDbFromStructure($file) { - $schemaManager = self::getMDB2SchemaManager(); - return $schemaManager->createDbFromStructure($file); - } - - /** - * update the database schema - * @param string $file file to read structure from - * @throws Exception - * @return string|boolean - * @suppress PhanDeprecatedFunction - */ - public static function updateDbFromStructure($file) { - $schemaManager = self::getMDB2SchemaManager(); - try { - $result = $schemaManager->updateDbFromStructure($file); - } catch (Exception $e) { - \OCP\Util::writeLog('core', 'Failed to update database structure ('.$e.')', ILogger::FATAL); - throw $e; - } - return $result; - } - - /** - * remove all tables defined in a database structure xml file - * @param string $file the xml file describing the tables - */ - public static function removeDBStructure($file) { - $schemaManager = self::getMDB2SchemaManager(); - $schemaManager->removeDBStructure($file); - } - - /** * check if a result is an error and throws an exception, works with \Doctrine\DBAL\Exception * @param mixed $result * @param string $message |