diff options
author | Thomas Müller <thomas.mueller@tmit.eu> | 2016-03-30 23:38:26 +0200 |
---|---|---|
committer | Thomas Müller <thomas.mueller@tmit.eu> | 2016-04-04 12:34:18 +0200 |
commit | 1bf4c75e8bfd32160ee7316c492ddc436f673f37 (patch) | |
tree | 123945f135aaebc0617318ef18b50fa7be125c13 /lib | |
parent | 53c19027069707576f43fa9fc4c79324188a98de (diff) | |
download | nextcloud-server-1bf4c75e8bfd32160ee7316c492ddc436f673f37.tar.gz nextcloud-server-1bf4c75e8bfd32160ee7316c492ddc436f673f37.zip |
Show individual sql schema migration steps during upgrade - on web as well as on the command line
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 | 26 |
3 files changed, 34 insertions, 12 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..f477da3bad0 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,15 +53,23 @@ class Migrator { /** @var IConfig */ protected $config; + /** @var EventDispatcher */ + private $dispatcher; + /** - * @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; } /** @@ -215,7 +225,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 +267,11 @@ class Migrator { protected function getFilterExpression() { return '/^' . preg_quote($this->config->getSystemValue('dbtableprefix', 'oc_')) . '/'; } + + protected function emit($sql, $step, $max) { + if(is_null($this->dispatcher)) { + return; + } + $this->dispatcher->dispatch('\OC\DB\Migrator::executeSql', new GenericEvent($sql, [$step+1, $max])); + } } |