diff --git a/core/Migrations/Version20170213215145.php b/core/Migrations/Version20170213215145.php index ea967f0a3b99..4e534e151be5 100644 --- a/core/Migrations/Version20170213215145.php +++ b/core/Migrations/Version20170213215145.php @@ -13,12 +13,13 @@ public function changeSchema(Schema $schema, array $options) { $prefix = $options['tablePrefix']; if ($schema->hasTable("${prefix}jobs")) { $table = $schema->getTable("${prefix}jobs"); - - $table->addColumn('execution_duration', 'integer', [ - 'notnull' => true, - 'length' => 5, - 'default' => -1, - ]); + if (!$table->hasColumn('execution_duration')) { + $table->addColumn('execution_duration', 'integer', [ + 'notnull' => true, + 'length' => 5, + 'default' => -1, + ]); + } } } } diff --git a/lib/private/Repair/Apps.php b/lib/private/Repair/Apps.php index f4dd8b6c6755..6a5e1eede602 100644 --- a/lib/private/Repair/Apps.php +++ b/lib/private/Repair/Apps.php @@ -1,6 +1,6 @@ + * @author Viktar Dubiniuk * * @copyright Copyright (c) 2018, ownCloud GmbH * @license AGPL-3.0 @@ -21,6 +21,8 @@ namespace OC\Repair; +use Doctrine\DBAL\Schema\Schema; +use Doctrine\DBAL\Types\Type; use OC\RepairException; use OC_App; use OCP\App\AppAlreadyInstalledException; @@ -326,6 +328,12 @@ private function fixMarketAppState(IOutput $output) { // Then we need to enable the market app to support app updates / downloads during upgrade $output->info('Enabling market app to assist with update'); try { + // Prepare oc_jobs for older ownCloud version fixes https://github.com/owncloud/update-testing/issues/5 + $connection = \OC::$server->getDatabaseConnection(); + $toSchema = $connection->createSchema(); + $this->changeSchema($toSchema, ['tablePrefix' => $connection->getPrefix()]); + $connection->migrateToSchema($toSchema); + $this->appManager->enableApp('market'); return true; } catch (\Exception $ex) { @@ -333,4 +341,50 @@ private function fixMarketAppState(IOutput $output) { return false; } } + + /** + * DB update for oc_jobs table + * it is intentionally duplicates 20170213215145 and a part of 20170101215145 + * to allow seamless market app installation + * + * @param Schema $schema + * @param array $options + * @throws \Doctrine\DBAL\Schema\SchemaException + */ + private function changeSchema(Schema $schema, array $options) { + $prefix = $options['tablePrefix']; + if ($schema->hasTable("${prefix}jobs")) { + $jobsTable = $schema->getTable("${prefix}jobs"); + + if (!$jobsTable->hasColumn('last_checked')) { + $jobsTable->addColumn( + 'last_checked', + Type::INTEGER, + [ + 'default' => 0, + 'notnull' => false + ] + ); + } + + if (!$jobsTable->hasColumn('reserved_at')) { + $jobsTable->addColumn( + 'reserved_at', + Type::INTEGER, + [ + 'default' => 0, + 'notnull' => false + ] + ); + } + + if (!$jobsTable->hasColumn('execution_duration')) { + $jobsTable->addColumn('execution_duration', Type::INTEGER, [ + 'notnull' => true, + 'length' => 5, + 'default' => -1, + ]); + } + } + } }