diff options
author | blizzz <blizzz@arthur-schiwon.de> | 2019-01-03 14:18:13 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-01-03 14:18:13 +0100 |
commit | 68952306aa3309286b6cd685976c2cdee674268a (patch) | |
tree | c37fb65becf5e85ad97a1e657ef67d4d16e14140 /lib | |
parent | c7399379c9f56d95eb62ebcebd4b5f950d412bce (diff) | |
parent | 85a0e10b4f3caec73de26e26e71bd6895358c916 (diff) | |
download | nextcloud-server-68952306aa3309286b6cd685976c2cdee674268a.tar.gz nextcloud-server-68952306aa3309286b6cd685976c2cdee674268a.zip |
Merge pull request #10555 from nextcloud/bugfix/10518/only-check-added-items
Only enforce schema limits for supported apps
Diffstat (limited to 'lib')
-rw-r--r-- | lib/private/DB/MigrationService.php | 52 |
1 files changed, 39 insertions, 13 deletions
diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index f584cb351d2..97f1dd269d1 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -25,11 +25,12 @@ namespace OC\DB; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; -use Doctrine\DBAL\Schema\Column; use Doctrine\DBAL\Schema\Index; use Doctrine\DBAL\Schema\Schema; use Doctrine\DBAL\Schema\SchemaException; use Doctrine\DBAL\Schema\Sequence; +use Doctrine\DBAL\Schema\Table; +use OC\App\InfoParser; use OC\IntegrityCheck\Helpers\AppLocator; use OC\Migration\SimpleOutput; use OCP\AppFramework\App; @@ -51,6 +52,8 @@ class MigrationService { private $connection; /** @var string */ private $appName; + /** @var bool */ + private $checkOracle; /** * MigrationService constructor. @@ -72,6 +75,7 @@ class MigrationService { if ($appName === 'core') { $this->migrationsPath = \OC::$SERVERROOT . '/core/Migrations'; $this->migrationsNamespace = 'OC\\Core\\Migrations'; + $this->checkOracle = true; } else { if (null === $appLocator) { $appLocator = new AppLocator(); @@ -80,6 +84,21 @@ class MigrationService { $namespace = App::buildAppNamespace($appName); $this->migrationsPath = "$appPath/lib/Migration"; $this->migrationsNamespace = $namespace . '\\Migration'; + + $infoParser = new InfoParser(); + $info = $infoParser->parse($appPath . '/appinfo/info.xml'); + if (!isset($info['dependencies']['database'])) { + $this->checkOracle = true; + } else { + $this->checkOracle = false; + foreach ($info['dependencies']['database'] as $database) { + if (\is_string($database) && $database === 'oci') { + $this->checkOracle = true; + } else if (\is_array($database) && isset($database['@value']) && $database['@value'] === 'oci') { + $this->checkOracle = true; + } + } + } } } @@ -457,8 +476,10 @@ class MigrationService { if ($toSchema instanceof SchemaWrapper) { $targetSchema = $toSchema->getWrappedSchema(); - // TODO re-enable once stable14 is branched of: https://github.com/nextcloud/server/issues/10518 - // $this->ensureOracleIdentifierLengthLimit($targetSchema, strlen($this->connection->getPrefix())); + if ($this->checkOracle) { + $sourceSchema = $this->connection->createSchema(); + $this->ensureOracleIdentifierLengthLimit($sourceSchema, $targetSchema, strlen($this->connection->getPrefix())); + } $this->connection->migrateToSchema($targetSchema); $toSchema->performDropTableCalls(); } @@ -472,34 +493,39 @@ class MigrationService { $this->markAsExecuted($version); } - public function ensureOracleIdentifierLengthLimit(Schema $schema, int $prefixLength) { - $sequences = $schema->getSequences(); + public function ensureOracleIdentifierLengthLimit(Schema $sourceSchema, Schema $targetSchema, int $prefixLength) { + $sequences = $targetSchema->getSequences(); - foreach ($schema->getTables() as $table) { - if (\strlen($table->getName()) - $prefixLength > 27) { - throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.'); + foreach ($targetSchema->getTables() as $table) { + try { + $sourceTable = $sourceSchema->getTable($table->getName()); + } catch (SchemaException $e) { + if (\strlen($table->getName()) - $prefixLength > 27) { + throw new \InvalidArgumentException('Table name "' . $table->getName() . '" is too long.'); + } + $sourceTable = null; } foreach ($table->getColumns() as $thing) { - if (\strlen($thing->getName()) - $prefixLength > 27) { + if ((!$sourceTable instanceof Table || !$sourceTable->hasColumn($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) { throw new \InvalidArgumentException('Column name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); } } foreach ($table->getIndexes() as $thing) { - if (\strlen($thing->getName()) - $prefixLength > 27) { + if ((!$sourceTable instanceof Table || !$sourceTable->hasIndex($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) { throw new \InvalidArgumentException('Index name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); } } foreach ($table->getForeignKeys() as $thing) { - if (\strlen($thing->getName()) - $prefixLength > 27) { + if ((!$sourceTable instanceof Table || !$sourceTable->hasForeignKey($thing->getName())) && \strlen($thing->getName()) - $prefixLength > 27) { throw new \InvalidArgumentException('Foreign key name "' . $table->getName() . '"."' . $thing->getName() . '" is too long.'); } } $primaryKey = $table->getPrimaryKey(); - if ($primaryKey instanceof Index) { + if ($primaryKey instanceof Index && (!$sourceTable instanceof Table || !$sourceTable->hasPrimaryKey())) { $indexName = strtolower($primaryKey->getName()); $isUsingDefaultName = $indexName === 'primary'; @@ -528,7 +554,7 @@ class MigrationService { } foreach ($sequences as $sequence) { - if (\strlen($sequence->getName()) - $prefixLength > 27) { + if (!$sourceSchema->hasSequence($sequence->getName()) && \strlen($sequence->getName()) - $prefixLength > 27) { throw new \InvalidArgumentException('Sequence name "' . $sequence->getName() . '" is too long.'); } } |