Merge pull request #8878 from owncloud/update-checkmigrationforapps
Simulate apps database schema update on upgrade
This commit is contained in:
commit
71b86136c2
|
@ -15,6 +15,9 @@ if (OC::checkUpgrade(false)) {
|
||||||
$updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
|
$updater->listen('\OC\Updater', 'dbUpgrade', function () use ($eventSource, $l) {
|
||||||
$eventSource->send('success', (string)$l->t('Updated database'));
|
$eventSource->send('success', (string)$l->t('Updated database'));
|
||||||
});
|
});
|
||||||
|
$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use ($eventSource, $l) {
|
||||||
|
$eventSource->send('success', (string)$l->t('Checked database schema update'));
|
||||||
|
});
|
||||||
$updater->listen('\OC\Updater', 'disabledApps', function ($appList) use ($eventSource, $l) {
|
$updater->listen('\OC\Updater', 'disabledApps', function ($appList) use ($eventSource, $l) {
|
||||||
$list = array();
|
$list = array();
|
||||||
foreach ($appList as $appId) {
|
foreach ($appList as $appId) {
|
||||||
|
|
|
@ -56,6 +56,9 @@ class Upgrade extends Command {
|
||||||
$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
|
$updater->listen('\OC\Updater', 'dbUpgrade', function () use($output) {
|
||||||
$output->writeln('<info>Updated database</info>');
|
$output->writeln('<info>Updated database</info>');
|
||||||
});
|
});
|
||||||
|
$updater->listen('\OC\Updater', 'dbSimulateUpgrade', function () use($output) {
|
||||||
|
$output->writeln('<info>Checked database schema update</info>');
|
||||||
|
});
|
||||||
$updater->listen('\OC\Updater', 'disabledApps', function ($appList) use($output) {
|
$updater->listen('\OC\Updater', 'disabledApps', function ($appList) use($output) {
|
||||||
$output->writeln('<info>Disabled incompatible apps: ' . implode(', ', $appList) . '</info>');
|
$output->writeln('<info>Disabled incompatible apps: ' . implode(', ', $appList) . '</info>');
|
||||||
});
|
});
|
||||||
|
|
|
@ -28,7 +28,7 @@
|
||||||
this.addMessage(t(
|
this.addMessage(t(
|
||||||
'core',
|
'core',
|
||||||
'Updating {productName} to version {version}, this may take a while.', {
|
'Updating {productName} to version {version}, this may take a while.', {
|
||||||
productName: OC.theme.name,
|
productName: OC.theme.name || 'ownCloud',
|
||||||
version: OC.config.versionstring
|
version: OC.config.versionstring
|
||||||
}),
|
}),
|
||||||
'bold'
|
'bold'
|
||||||
|
|
|
@ -730,7 +730,7 @@ class OC {
|
||||||
|
|
||||||
if (!self::$CLI and (!isset($_GET["logout"]) or ($_GET["logout"] !== 'true'))) {
|
if (!self::$CLI and (!isset($_GET["logout"]) or ($_GET["logout"] !== 'true'))) {
|
||||||
try {
|
try {
|
||||||
if (!OC_Config::getValue('maintenance', false)) {
|
if (!OC_Config::getValue('maintenance', false) && !self::needUpgrade()) {
|
||||||
OC_App::loadApps();
|
OC_App::loadApps();
|
||||||
}
|
}
|
||||||
self::checkSingleUserMode();
|
self::checkSingleUserMode();
|
||||||
|
|
|
@ -875,6 +875,18 @@ class OC_App {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public static function shouldUpgrade($app) {
|
||||||
|
$versions = self::getAppVersions();
|
||||||
|
$currentVersion = OC_App::getAppVersion($app);
|
||||||
|
if ($currentVersion) {
|
||||||
|
$installedVersion = $versions[$app];
|
||||||
|
if (version_compare($currentVersion, $installedVersion, '>')) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* check if the app needs updating and update when needed
|
* check if the app needs updating and update when needed
|
||||||
*
|
*
|
||||||
|
@ -885,26 +897,27 @@ class OC_App {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
self::$checkedApps[] = $app;
|
self::$checkedApps[] = $app;
|
||||||
$versions = self::getAppVersions();
|
if (!self::shouldUpgrade($app)) {
|
||||||
$currentVersion = OC_App::getAppVersion($app);
|
return;
|
||||||
if ($currentVersion) {
|
|
||||||
$installedVersion = $versions[$app];
|
|
||||||
if (version_compare($currentVersion, $installedVersion, '>')) {
|
|
||||||
$info = self::getAppInfo($app);
|
|
||||||
OC_Log::write($app,
|
|
||||||
'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion,
|
|
||||||
OC_Log::DEBUG);
|
|
||||||
try {
|
|
||||||
OC_App::updateApp($app);
|
|
||||||
OC_Hook::emit('update', 'success', 'Updated ' . $info['name'] . ' app');
|
|
||||||
} catch (Exception $e) {
|
|
||||||
OC_Hook::emit('update', 'failure', 'Failed to update ' . $info['name'] . ' app: ' . $e->getMessage());
|
|
||||||
$l = OC_L10N::get('lib');
|
|
||||||
throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
|
|
||||||
}
|
|
||||||
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
$versions = self::getAppVersions();
|
||||||
|
$installedVersion = $versions[$app];
|
||||||
|
$currentVersion = OC_App::getAppVersion($app);
|
||||||
|
OC_Log::write(
|
||||||
|
$app,
|
||||||
|
'starting app upgrade from ' . $installedVersion . ' to ' . $currentVersion,
|
||||||
|
OC_Log::DEBUG
|
||||||
|
);
|
||||||
|
$info = self::getAppInfo($app);
|
||||||
|
try {
|
||||||
|
OC_App::updateApp($app);
|
||||||
|
OC_Hook::emit('update', 'success', 'Updated ' . $info['name'] . ' app');
|
||||||
|
} catch (Exception $e) {
|
||||||
|
OC_Hook::emit('update', 'failure', 'Failed to update ' . $info['name'] . ' app: ' . $e->getMessage());
|
||||||
|
$l = OC_L10N::get('lib');
|
||||||
|
throw new RuntimeException($l->t('Failed to upgrade "%s".', array($app)), 0, $e);
|
||||||
|
}
|
||||||
|
OC_Appconfig::setValue($app, 'installed_version', OC_App::getAppVersion($app));
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
@ -321,6 +321,23 @@ class OC_DB {
|
||||||
return $result;
|
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;
|
||||||
|
}
|
||||||
|
return $result;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* drop a table - the database prefix will be prepended
|
* drop a table - the database prefix will be prepended
|
||||||
* @param string $tableName the table to drop
|
* @param string $tableName the table to drop
|
||||||
|
|
|
@ -73,6 +73,17 @@ 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
|
||||||
|
@ -80,21 +91,28 @@ class MDB2SchemaManager {
|
||||||
* @return string|boolean
|
* @return string|boolean
|
||||||
*/
|
*/
|
||||||
public function updateDbFromStructure($file, $generateSql = 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 {
|
||||||
$migrator->checkMigrate($toSchema);
|
|
||||||
$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
|
||||||
|
|
|
@ -125,29 +125,63 @@ class Updater extends BasicEmitter {
|
||||||
* STOP CONFIG CHANGES FOR OLDER VERSIONS
|
* STOP CONFIG CHANGES FOR OLDER VERSIONS
|
||||||
*/
|
*/
|
||||||
|
|
||||||
|
$canUpgrade = false;
|
||||||
|
|
||||||
|
// simulate DB upgrade
|
||||||
try {
|
try {
|
||||||
\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
// simulate core DB upgrade
|
||||||
$this->emit('\OC\Updater', 'dbUpgrade');
|
\OC_DB::simulateUpdateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||||
|
|
||||||
|
// simulate apps DB upgrade
|
||||||
|
$version = \OC_Util::getVersion();
|
||||||
|
$apps = \OC_App::getEnabledApps();
|
||||||
|
foreach ($apps as $appId) {
|
||||||
|
$info = \OC_App::getAppInfo($appId);
|
||||||
|
if (\OC_App::isAppCompatible($version, $info) && \OC_App::shouldUpgrade($appId)) {
|
||||||
|
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
|
||||||
|
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
$this->emit('\OC\Updater', 'dbSimulateUpgrade');
|
||||||
|
|
||||||
|
$canUpgrade = true;
|
||||||
} catch (\Exception $exception) {
|
} catch (\Exception $exception) {
|
||||||
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
||||||
}
|
}
|
||||||
\OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
|
|
||||||
$disabledApps = \OC_App::checkAppsRequirements();
|
if ($canUpgrade) {
|
||||||
if (!empty($disabledApps)) {
|
// proceed with real upgrade
|
||||||
$this->emit('\OC\Updater', 'disabledApps', array($disabledApps));
|
try {
|
||||||
|
// do the real upgrade
|
||||||
|
\OC_DB::updateDbFromStructure(\OC::$SERVERROOT . '/db_structure.xml');
|
||||||
|
$this->emit('\OC\Updater', 'dbUpgrade');
|
||||||
|
|
||||||
|
} catch (\Exception $exception) {
|
||||||
|
$this->emit('\OC\Updater', 'failure', array($exception->getMessage()));
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
// TODO: why not do this at the end ?
|
||||||
|
\OC_Config::setValue('version', implode('.', \OC_Util::getVersion()));
|
||||||
|
$disabledApps = \OC_App::checkAppsRequirements();
|
||||||
|
if (!empty($disabledApps)) {
|
||||||
|
$this->emit('\OC\Updater', 'disabledApps', array($disabledApps));
|
||||||
|
}
|
||||||
|
// load all apps to also upgrade enabled apps
|
||||||
|
\OC_App::loadApps();
|
||||||
|
|
||||||
|
$repair = new Repair();
|
||||||
|
$repair->run();
|
||||||
|
|
||||||
|
//Invalidate update feed
|
||||||
|
\OC_Appconfig::setValue('core', 'lastupdatedat', 0);
|
||||||
}
|
}
|
||||||
// load all apps to also upgrade enabled apps
|
|
||||||
\OC_App::loadApps();
|
|
||||||
|
|
||||||
$repair = new Repair();
|
|
||||||
$repair->run();
|
|
||||||
|
|
||||||
//Invalidate update feed
|
|
||||||
\OC_Appconfig::setValue('core', 'lastupdatedat', 0);
|
|
||||||
\OC_Config::setValue('maintenance', false);
|
\OC_Config::setValue('maintenance', false);
|
||||||
$this->emit('\OC\Updater', 'maintenanceEnd');
|
$this->emit('\OC\Updater', 'maintenanceEnd');
|
||||||
|
|
||||||
|
return $canUpgrade;
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue