diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-05 09:39:35 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-05 09:39:35 +0200 |
commit | 961bb4c3e3cb944cb61c7331399a1d2bc9e51f6d (patch) | |
tree | 43bf9a22c6315e533190417774063d915d40bb16 /lib | |
parent | 808a25bc5d4f80d985bc458475b56ebd1b39e69f (diff) | |
parent | 4b79fb10a28d9edbace8ec44dfb43861c5570a64 (diff) | |
download | nextcloud-server-961bb4c3e3cb944cb61c7331399a1d2bc9e51f6d.tar.gz nextcloud-server-961bb4c3e3cb944cb61c7331399a1d2bc9e51f6d.zip |
Merge pull request #23677 from owncloud/db-schema-migration-feedback
Show individual sql schema migration steps during upgrade - on web as…
Diffstat (limited to 'lib')
-rw-r--r-- | lib/base.php | 1 | ||||
-rw-r--r-- | lib/private/db/mdb2schemamanager.php | 19 | ||||
-rw-r--r-- | lib/private/db/migrator.php | 47 |
3 files changed, 52 insertions, 15 deletions
diff --git a/lib/base.php b/lib/base.php index f3076a1181a..706322fb542 100644 --- a/lib/base.php +++ b/lib/base.php @@ -365,6 +365,7 @@ class OC { $systemConfig->setValue('theme', ''); \OCP\Util::addScript('config'); // needed for web root \OCP\Util::addScript('update'); + \OCP\Util::addStyle('update'); // check whether this is a core update or apps update $installedVersion = $systemConfig->getValue('version', '0.0.0'); diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php index bcabb6fe57a..f73f6b4351a 100644 --- a/lib/private/db/mdb2schemamanager.php +++ b/lib/private/db/mdb2schemamanager.php @@ -32,15 +32,14 @@ use Doctrine\DBAL\Platforms\MySqlPlatform; use Doctrine\DBAL\Platforms\OraclePlatform; use Doctrine\DBAL\Platforms\PostgreSqlPlatform; use Doctrine\DBAL\Platforms\SqlitePlatform; +use OCP\IDBConnection; class MDB2SchemaManager { - /** - * @var \OC\DB\Connection $conn - */ + /** @var \OC\DB\Connection $conn */ protected $conn; /** - * @param \OCP\IDBConnection $conn + * @param IDBConnection $conn */ public function __construct($conn) { $this->conn = $conn; @@ -77,16 +76,17 @@ class MDB2SchemaManager { $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, $random, $config); + return new SQLiteMigrator($this->conn, $random, $config, $dispatcher); } else if ($platform instanceof OraclePlatform) { - return new OracleMigrator($this->conn, $random, $config); + return new OracleMigrator($this->conn, $random, $config, $dispatcher); } else if ($platform instanceof MySqlPlatform) { - return new MySQLMigrator($this->conn, $random, $config); + return new MySQLMigrator($this->conn, $random, $config, $dispatcher); } else if ($platform instanceof PostgreSqlPlatform) { - return new Migrator($this->conn, $random, $config); + return new Migrator($this->conn, $random, $config, $dispatcher); } else { - return new NoCheckMigrator($this->conn, $random, $config); + return new NoCheckMigrator($this->conn, $random, $config, $dispatcher); } } @@ -94,6 +94,7 @@ class MDB2SchemaManager { * 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(); diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php index 7ca3f981358..8b8a34d9865 100644 --- a/lib/private/db/migrator.php +++ b/lib/private/db/migrator.php @@ -35,6 +35,8 @@ use \Doctrine\DBAL\Schema\SchemaConfig; use \Doctrine\DBAL\Schema\Comparator; use OCP\IConfig; use OCP\Security\ISecureRandom; +use Symfony\Component\EventDispatcher\EventDispatcher; +use Symfony\Component\EventDispatcher\GenericEvent; class Migrator { @@ -51,21 +53,33 @@ class Migrator { /** @var IConfig */ protected $config; + /** @var EventDispatcher */ + private $dispatcher; + + /** @var bool */ + private $noEmit = false; + /** - * @param Connection $connection + * @param \Doctrine\DBAL\Connection|Connection $connection * @param ISecureRandom $random * @param IConfig $config + * @param EventDispatcher $dispatcher */ - public function __construct(\Doctrine\DBAL\Connection $connection, ISecureRandom $random, IConfig $config) { + public function __construct(\Doctrine\DBAL\Connection $connection, + ISecureRandom $random, + IConfig $config, + EventDispatcher $dispatcher = null) { $this->connection = $connection; $this->random = $random; $this->config = $config; + $this->dispatcher = $dispatcher; } /** * @param \Doctrine\DBAL\Schema\Schema $targetSchema */ public function migrate(Schema $targetSchema) { + $this->noEmit = true; $this->applySchema($targetSchema); } @@ -90,21 +104,22 @@ class Migrator { * @throws \OC\DB\MigrationException */ public function checkMigrate(Schema $targetSchema) { - /** - * @var \Doctrine\DBAL\Schema\Table[] $tables - */ + $this->noEmit = true; + /**@var \Doctrine\DBAL\Schema\Table[] $tables */ $tables = $targetSchema->getTables(); $filterExpression = $this->getFilterExpression(); $this->connection->getConfiguration()-> setFilterSchemaAssetsExpression($filterExpression); $existingTables = $this->connection->getSchemaManager()->listTableNames(); + $step = 0; foreach ($tables as $table) { if (strpos($table->getName(), '.')) { list(, $tableName) = explode('.', $table->getName()); } else { $tableName = $table->getName(); } + $this->emitCheckStep($tableName, $step++, count($tables)); // don't need to check for new tables if (array_search($tableName, $existingTables) !== false) { $this->checkTableMigrate($table); @@ -215,7 +230,10 @@ class Migrator { $schemaDiff = $this->getDiff($targetSchema, $connection); $connection->beginTransaction(); - foreach ($schemaDiff->toSql($connection->getDatabasePlatform()) as $sql) { + $sqls = $schemaDiff->toSql($connection->getDatabasePlatform()); + $step = 0; + foreach ($sqls as $sql) { + $this->emit($sql, $step++, count($sqls)); $connection->query($sql); } $connection->commit(); @@ -254,4 +272,21 @@ class Migrator { protected function getFilterExpression() { return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; } + + protected function emit($sql, $step, $max) { + if ($this->noEmit) { + return; + } + if(is_null($this->dispatcher)) { + return; + } + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); + } + + private function emitCheckStep($tableName, $step, $max) { + if(is_null($this->dispatcher)) { + return; + } + $this->dispatcher->dispatch('\OC\DB\Migrator::checkTable', new GenericEvent($tableName, [$step+1, $max])); + } } |