Removed simulate db update flag and split into separate methods
This commit is contained in:
parent
5b97369b00
commit
d4ffafe467
|
@ -307,21 +307,32 @@ class OC_DB {
|
||||||
/**
|
/**
|
||||||
* update the database schema
|
* update the database schema
|
||||||
* @param string $file file to read structure from
|
* @param string $file file to read structure from
|
||||||
* @param bool $simulate whether to simulate the upgrade on separate tables
|
|
||||||
* @throws Exception
|
* @throws Exception
|
||||||
* @return string|boolean
|
* @return string|boolean
|
||||||
*/
|
*/
|
||||||
public static function updateDbFromStructure($file, $simulate = false) {
|
public static function updateDbFromStructure($file) {
|
||||||
$schemaManager = self::getMDB2SchemaManager();
|
$schemaManager = self::getMDB2SchemaManager();
|
||||||
try {
|
try {
|
||||||
$result = $schemaManager->updateDbFromStructure($file, false, $simulate);
|
$result = $schemaManager->updateDbFromStructure($file);
|
||||||
} catch (Exception $e) {
|
} catch (Exception $e) {
|
||||||
if ($simulate) {
|
|
||||||
OC_Log::write('core', 'Database structure update simulation failed ('.$e.')', OC_Log::FATAL);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
OC_Log::write('core', 'Failed to update database structure ('.$e.')', OC_Log::FATAL);
|
OC_Log::write('core', 'Failed to update database structure ('.$e.')', OC_Log::FATAL);
|
||||||
|
throw $e;
|
||||||
}
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* simulate the database schema update
|
||||||
|
* @param string $file file to read structure from
|
||||||
|
* @throws Exception
|
||||||
|
* @return string|boolean
|
||||||
|
*/
|
||||||
|
public static function simulateUpdateDbFromStructure($file) {
|
||||||
|
$schemaManager = self::getMDB2SchemaManager();
|
||||||
|
try {
|
||||||
|
$result = $schemaManager->simulateUpdateDbFromStructure($file);
|
||||||
|
} catch (Exception $e) {
|
||||||
|
OC_Log::write('core', 'Simulated database structure update failed ('.$e.')', OC_Log::FATAL);
|
||||||
throw $e;
|
throw $e;
|
||||||
}
|
}
|
||||||
return $result;
|
return $result;
|
||||||
|
|
|
@ -73,33 +73,46 @@ class MDB2SchemaManager {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Reads database schema from file
|
||||||
|
*
|
||||||
|
* @param string $file file to read from
|
||||||
|
*/
|
||||||
|
private function readSchemaFromFile($file) {
|
||||||
|
$platform = $this->conn->getDatabasePlatform();
|
||||||
|
$schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $platform);
|
||||||
|
return $schemaReader->loadSchemaFromFile($file);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* update the database scheme
|
* update the database scheme
|
||||||
* @param string $file file to read structure from
|
* @param string $file file to read structure from
|
||||||
* @param bool $generateSql only return the sql needed for the upgrade
|
* @param bool $generateSql only return the sql needed for the upgrade
|
||||||
* @param bool $simulate whether to simulate on separate tables instead of the real onces
|
|
||||||
* @return string|boolean
|
* @return string|boolean
|
||||||
*/
|
*/
|
||||||
public function updateDbFromStructure($file, $generateSql = false, $simulate = false) {
|
public function updateDbFromStructure($file, $generateSql = false) {
|
||||||
|
$toSchema = $this->readSchemaFromFile($file);
|
||||||
$platform = $this->conn->getDatabasePlatform();
|
|
||||||
$schemaReader = new MDB2SchemaReader(\OC_Config::getObject(), $platform);
|
|
||||||
$toSchema = $schemaReader->loadSchemaFromFile($file);
|
|
||||||
$migrator = $this->getMigrator();
|
$migrator = $this->getMigrator();
|
||||||
|
|
||||||
if ($generateSql) {
|
if ($generateSql) {
|
||||||
return $migrator->generateChangeScript($toSchema);
|
return $migrator->generateChangeScript($toSchema);
|
||||||
} else {
|
} else {
|
||||||
if ($simulate) {
|
|
||||||
$migrator->checkMigrate($toSchema);
|
|
||||||
}
|
|
||||||
else {
|
|
||||||
$migrator->migrate($toSchema);
|
$migrator->migrate($toSchema);
|
||||||
}
|
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* update the database scheme
|
||||||
|
* @param string $file file to read structure from
|
||||||
|
* @return string|boolean
|
||||||
|
*/
|
||||||
|
public function simulateUpdateDbFromStructure($file) {
|
||||||
|
$toSchema = $this->readSchemaFromFile($file);
|
||||||
|
$migrator = $this->getMigrator()->checkMigrate($toSchema);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @param \Doctrine\DBAL\Schema\Schema $schema
|
* @param \Doctrine\DBAL\Schema\Schema $schema
|
||||||
* @return string
|
* @return string
|
||||||
|
|
|
@ -130,7 +130,7 @@ class Updater extends BasicEmitter {
|
||||||
// simulate DB upgrade
|
// simulate DB upgrade
|
||||||
try {
|
try {
|
||||||
// simulate core DB upgrade
|
// simulate core DB upgrade
|
||||||
\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml', true);
|
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||||
|
|
||||||
// simulate apps DB upgrade
|
// simulate apps DB upgrade
|
||||||
$version = \OC_Util::getVersion();
|
$version = \OC_Util::getVersion();
|
||||||
|
@ -139,7 +139,7 @@ class Updater extends BasicEmitter {
|
||||||
$info = \OC_App::getAppInfo($appId);
|
$info = \OC_App::getAppInfo($appId);
|
||||||
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
||||||
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
||||||
\OC_DB::updateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml', true);
|
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue