summaryrefslogtreecommitdiffstats
path: root/lib/private/db
diff options
context:
space:
mode:
Diffstat (limited to 'lib/private/db')
-rw-r--r--lib/private/db/mdb2schemamanager.php19
-rw-r--r--lib/private/db/migrator.php26
2 files changed, 33 insertions, 12 deletions
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]));
+ }
}