From a59f6818ebeffa23ad1b66652179f3592bd4931d Mon Sep 17 00:00:00 2001
From: Robin Appelman <icewind@owncloud.com>
Date: Fri, 11 Apr 2014 15:10:09 +0200
Subject: [PATCH] Only quote identifiers for oracle during migration

---
 lib/private/db/mdb2schemamanager.php | 33 ++++++++++++-----------
 lib/private/db/migrator.php          | 11 +-------
 lib/private/db/oraclemigrator.php    | 40 ++++++++++++++++++++++++++++
 3 files changed, 58 insertions(+), 26 deletions(-)
 create mode 100644 lib/private/db/oraclemigrator.php

diff --git a/lib/private/db/mdb2schemamanager.php b/lib/private/db/mdb2schemamanager.php
index 0eec4d4d317..1c9b6b9d00b 100644
--- a/lib/private/db/mdb2schemamanager.php
+++ b/lib/private/db/mdb2schemamanager.php
@@ -8,8 +8,7 @@
 
 namespace OC\DB;
 
-use Doctrine\DBAL\Platforms\MySqlPlatform;
-use Doctrine\DBAL\Platforms\PostgreSqlPlatform;
+use Doctrine\DBAL\Platforms\OraclePlatform;
 use Doctrine\DBAL\Platforms\SqlitePlatform;
 
 class MDB2SchemaManager {
@@ -54,6 +53,20 @@ class MDB2SchemaManager {
 		return $this->executeSchemaChange($toSchema);
 	}
 
+	/**
+	 * @return \OC\DB\Migrator
+	 */
+	protected function getMigrator() {
+		$platform = $this->conn->getDatabasePlatform();
+		if ($platform instanceof SqlitePlatform) {
+			return new SQLiteMigrator($this->conn);
+		} else if ($platform instanceof OraclePlatform) {
+			return new OracleMigrator($this->conn);
+		} else {
+			return new Migrator($this->conn);
+		}
+	}
+
 	/**
 	 * update the database scheme
 	 * @param string $file file to read structure from
@@ -65,24 +78,12 @@ class MDB2SchemaManager {
 		$platform = $this->conn->getDatabasePlatform();
 		$schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $platform);
 		$toSchema = $schemaReader->loadSchemaFromFile($file);
-		if ($platform instanceof SqlitePlatform) {
-			$check = true;
-			$migrator = new SQLiteMigrator($this->conn);
-		} else if ($platform instanceof MySqlPlatform or $platform instanceof PostgreSqlPlatform) {
-			$check = true;
-			$migrator = new Migrator($this->conn);
-		} else {
-			// dont do the upgrade check for oracle
-			$check = false;
-			$migrator = new Migrator($this->conn);
-		}
+		$migrator = $this->getMigrator();
 
 		if ($generateSql) {
 			return $migrator->generateChangeScript($toSchema);
 		} else {
-			if ($check) {
-				$migrator->checkMigrate($toSchema);
-			}
+			$migrator->checkMigrate($toSchema);
 			$migrator->migrate($toSchema);
 			return true;
 		}
diff --git a/lib/private/db/migrator.php b/lib/private/db/migrator.php
index 917f92f64b6..5dd7735dfc6 100644
--- a/lib/private/db/migrator.php
+++ b/lib/private/db/migrator.php
@@ -144,16 +144,7 @@ class Migrator {
 		}
 
 		$comparator = new Comparator();
-		$schemaDiff = $comparator->compare($sourceSchema, $targetSchema);
-
-		foreach ($schemaDiff->changedTables as $tableDiff) {
-			$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
-			foreach ($tableDiff->changedColumns as $column) {
-				$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
-			}
-		}
-
-		return $schemaDiff;
+		return $comparator->compare($sourceSchema, $targetSchema);
 	}
 
 	/**
diff --git a/lib/private/db/oraclemigrator.php b/lib/private/db/oraclemigrator.php
new file mode 100644
index 00000000000..5494bcbac30
--- /dev/null
+++ b/lib/private/db/oraclemigrator.php
@@ -0,0 +1,40 @@
+<?php
+/**
+ * Copyright (c) 2014 Robin Appelman <icewind@owncloud.com>
+ * This file is licensed under the Affero General Public License version 3 or
+ * later.
+ * See the COPYING-README file.
+ */
+
+namespace OC\DB;
+
+use Doctrine\DBAL\Schema\Schema;
+
+class OracleMigrator extends Migrator {
+	/**
+	 * @param \Doctrine\DBAL\Schema\Schema $targetSchema
+	 * @throws \OC\DB\MigrationException
+	 *
+	 * Migration testing is skipped for oracle
+	 */
+	public function checkMigrate(Schema $targetSchema) {}
+
+	/**
+	 * @param Schema $targetSchema
+	 * @param \Doctrine\DBAL\Connection $connection
+	 * @return \Doctrine\DBAL\Schema\SchemaDiff
+	 */
+	protected function getDiff(Schema $targetSchema, \Doctrine\DBAL\Connection $connection) {
+		$schemaDiff = parent::getDiff($targetSchema, $connection);
+
+		// oracle forces us to quote the identifiers
+		foreach ($schemaDiff->changedTables as $tableDiff) {
+			$tableDiff->name = $this->connection->quoteIdentifier($tableDiff->name);
+			foreach ($tableDiff->changedColumns as $column) {
+				$column->oldColumnName = $this->connection->quoteIdentifier($column->oldColumnName);
+			}
+		}
+
+		return $schemaDiff;
+	}
+}
-- 
GitLab