From 194ef1a1715038c2193cee65a74372f07bc4eee6 Mon Sep 17 00:00:00 2001 From: Joas Schilling Date: Fri, 2 Jun 2017 13:54:09 +0200 Subject: Adjust the code to use our interface and abstract Signed-off-by: Joas Schilling --- lib/private/DB/MigrationService.php | 28 +++++++++++++++------------- 1 file changed, 15 insertions(+), 13 deletions(-) (limited to 'lib/private/DB') diff --git a/lib/private/DB/MigrationService.php b/lib/private/DB/MigrationService.php index 8a4980d1118..c81fe0f4332 100644 --- a/lib/private/DB/MigrationService.php +++ b/lib/private/DB/MigrationService.php @@ -22,10 +22,12 @@ namespace OC\DB; +use Doctrine\DBAL\Schema\Schema; use OC\IntegrityCheck\Helpers\AppLocator; use OC\Migration\SimpleOutput; use OCP\AppFramework\QueryException; use OCP\IDBConnection; +use OCP\Migration\IMigrationStep; use OCP\Migration\IOutput; use OCP\Migration\ISchemaMigration; use OCP\Migration\ISimpleMigration; @@ -373,23 +375,23 @@ class MigrationService { * @param string $version */ public function executeStep($version) { - - // FIXME our interface $instance = $this->createInstance($version); - if ($instance instanceof ISimpleMigration) { - $instance->run($this->output); - } - if ($instance instanceof ISqlMigration) { - $sqls = $instance->sql($this->connection); - foreach ($sqls as $s) { - $this->connection->executeQuery($s); - } + if (!$instance instanceof IMigrationStep) { + throw new \RuntimeException('Not a valid migration'); } - if ($instance instanceof ISchemaMigration) { - $toSchema = $this->connection->createSchema(); - $instance->changeSchema($toSchema, ['tablePrefix' => $this->connection->getPrefix()]); + + $instance->preSchemaChange($this->output); + + $toSchema = $instance->changeSchema(function() { + return $this->connection->createSchema(); + }, ['tablePrefix' => $this->connection->getPrefix()]); + + if ($toSchema instanceof Schema) { $this->connection->migrateToSchema($toSchema); } + + $instance->postSchemaChange($this->output); + $this->markAsExecuted($version); } -- cgit v1.2.3