Skip to content

Commit

Permalink
Merge pull request #32573 from owncloud/fix-migration-from-909-and-below
Browse files Browse the repository at this point in the history
[Stable10] Fix update cases from 9.0.9 and below
  • Loading branch information
Vincent Petry authored Sep 4, 2018
2 parents b5d785f + 56adfe7 commit 74d158c
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
13 changes: 7 additions & 6 deletions core/Migrations/Version20170213215145.php
Original file line number Diff line number Diff line change
Expand Up @@ -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,
]);
}
}
}
}
56 changes: 55 additions & 1 deletion lib/private/Repair/Apps.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php
/**
* @author Victor Dubiniuk <dubiniuk@aheadworks.com>
* @author Viktar Dubiniuk <dubiniuk@owncloud.com>
*
* @copyright Copyright (c) 2018, ownCloud GmbH
* @license AGPL-3.0
Expand All @@ -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;
Expand Down Expand Up @@ -326,11 +328,63 @@ 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) {
$output->warning($ex->getMessage());
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,
]);
}
}
}
}

0 comments on commit 74d158c

Please sign in to comment.