Skip to content

Commit

Permalink
Bye bye database.xml
Browse files Browse the repository at this point in the history
Signed-off-by: Joas Schilling <coding@schilljs.com>
  • Loading branch information
nickvergessen committed Jul 7, 2020
1 parent b156cf8 commit 2316080
Show file tree
Hide file tree
Showing 8 changed files with 29 additions and 165 deletions.
15 changes: 4 additions & 11 deletions core/Command/App/CheckCode.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,6 @@
namespace OC\Core\Command\App;

use OC\App\CodeChecker\CodeChecker;
use OC\App\CodeChecker\DatabaseSchemaChecker;
use OC\App\CodeChecker\DeprecationCheck;
use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\InfoChecker;
Expand Down Expand Up @@ -144,17 +143,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int

$errors = array_merge($errors, $languageErrors);

$databaseSchema = new DatabaseSchemaChecker();
$schemaErrors = $databaseSchema->analyse($appId);

foreach ($schemaErrors['errors'] as $schemaError) {
$output->writeln("<error>$schemaError</error>");
}
foreach ($schemaErrors['warnings'] as $schemaWarning) {
$output->writeln("<comment>$schemaWarning</comment>");
$appPath = \OC_App::getAppPath($appId);
if (file_exists($appPath . '/appinfo/database.xml')) {
$output->writeln("<error>The appinfo/database.xml file is not longer supported. Please use migrations to set up your database tables.</error>");
$errors[] = 'The appinfo/database.xml file is not longer supported. Please use migrations to set up your database tables.';
}

$errors = array_merge($errors, $schemaErrors['errors']);
}

$this->analyseUpdateFile($appId, $output);
Expand Down
18 changes: 7 additions & 11 deletions core/Command/Db/ConvertType.php
Original file line number Diff line number Diff line change
Expand Up @@ -242,17 +242,13 @@ protected function createSchema(Connection $fromDB, Connection $toDB, InputInter
$schemaManager = new \OC\DB\MDB2SchemaManager($toDB);
$apps = $input->getOption('all-apps') ? \OC_App::getAllApps() : \OC_App::getEnabledApps();
foreach ($apps as $app) {
if (file_exists(\OC_App::getAppPath($app).'/appinfo/database.xml')) {
$schemaManager->createDbFromStructure(\OC_App::getAppPath($app).'/appinfo/database.xml');
} else {
// Make sure autoloading works...
\OC_App::loadApp($app);
$fromMS = new MigrationService($app, $fromDB);
$currentMigration = $fromMS->getMigration('current');
if ($currentMigration !== '0') {
$toMS = new MigrationService($app, $toDB);
$toMS->migrate($currentMigration, true);
}
// Make sure autoloading works...
\OC_App::loadApp($app);
$fromMS = new MigrationService($app, $fromDB);
$currentMigration = $fromMS->getMigration('current');
if ($currentMigration !== '0') {
$toMS = new MigrationService($app, $toDB);
$toMS->migrate($currentMigration, true);
}
}
}
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_classmap.php
Original file line number Diff line number Diff line change
Expand Up @@ -609,7 +609,6 @@
'OC\\App\\AppStore\\Version\\VersionParser' => $baseDir . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => $baseDir . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => $baseDir . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DatabaseSchemaChecker' => $baseDir . '/lib/private/App/CodeChecker/DatabaseSchemaChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => $baseDir . '/lib/private/App/CodeChecker/DeprecationCheck.php',
'OC\\App\\CodeChecker\\EmptyCheck' => $baseDir . '/lib/private/App/CodeChecker/EmptyCheck.php',
'OC\\App\\CodeChecker\\ICheck' => $baseDir . '/lib/private/App/CodeChecker/ICheck.php',
Expand Down
1 change: 0 additions & 1 deletion lib/composer/composer/autoload_static.php
Original file line number Diff line number Diff line change
Expand Up @@ -638,7 +638,6 @@ class ComposerStaticInit53792487c5a8370acc0b06b1a864ff4c
'OC\\App\\AppStore\\Version\\VersionParser' => __DIR__ . '/../../..' . '/lib/private/App/AppStore/Version/VersionParser.php',
'OC\\App\\CodeChecker\\AbstractCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/AbstractCheck.php',
'OC\\App\\CodeChecker\\CodeChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/CodeChecker.php',
'OC\\App\\CodeChecker\\DatabaseSchemaChecker' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/DatabaseSchemaChecker.php',
'OC\\App\\CodeChecker\\DeprecationCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/DeprecationCheck.php',
'OC\\App\\CodeChecker\\EmptyCheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/EmptyCheck.php',
'OC\\App\\CodeChecker\\ICheck' => __DIR__ . '/../../..' . '/lib/private/App/CodeChecker/ICheck.php',
Expand Down
106 changes: 0 additions & 106 deletions lib/private/App/CodeChecker/DatabaseSchemaChecker.php

This file was deleted.

36 changes: 11 additions & 25 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,8 @@
use OC\App\AppStore\Bundles\Bundle;
use OC\App\AppStore\Fetcher\AppFetcher;
use OC\Archive\TAR;
use OC\DB\MigrationService;
use OC_App;
use OC_DB;
use OC_Helper;
use OCP\Http\Client\IClientService;
use OCP\IConfig;
Expand Down Expand Up @@ -111,6 +111,11 @@ public function installApp(string $appId, bool $forceEnable = false): string {
}

$basedir = $app['path'].'/'.$appId;

if (is_file($basedir . '/appinfo/database.xml')) {
throw new \Exception('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
}

$info = OC_App::getAppInfo($basedir.'/appinfo/info.xml', true);

$l = \OC::$server->getL10N('core');
Expand Down Expand Up @@ -146,16 +151,9 @@ public function installApp(string $appId, bool $forceEnable = false): string {
}

//install the database
if (is_file($basedir.'/appinfo/database.xml')) {
if (\OC::$server->getConfig()->getAppValue($info['id'], 'installed_version') === null) {
OC_DB::createDbFromStructure($basedir.'/appinfo/database.xml');
} else {
OC_DB::updateDbFromStructure($basedir.'/appinfo/database.xml');
}
} else {
$ms = new \OC\DB\MigrationService($info['id'], \OC::$server->getDatabaseConnection());
$ms->migrate();
}
$ms = new MigrationService($info['id'], \OC::$server->getDatabaseConnection());
$ms->migrate();

if ($previousVersion) {
OC_App::executeRepairSteps($appId, $info['repair-steps']['post-migration']);
}
Expand Down Expand Up @@ -572,20 +570,8 @@ public static function installShippedApp($app) {
$appPath = OC_App::getAppPath($app);
\OC_App::registerAutoloading($app, $appPath);

if (is_file("$appPath/appinfo/database.xml")) {
try {
OC_DB::createDbFromStructure("$appPath/appinfo/database.xml");
} catch (TableExistsException $e) {
throw new HintException(
'Failed to enable app ' . $app,
'Please ask for help via one of our <a href="https://nextcloud.com/support/" target="_blank" rel="noreferrer noopener">support channels</a>.',
0, $e
);
}
} else {
$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
$ms->migrate();
}
$ms = new MigrationService($app, \OC::$server->getDatabaseConnection());
$ms->migrate();

//run appinfo/install.php
self::includeAppScript("$appPath/appinfo/install.php");
Expand Down
4 changes: 0 additions & 4 deletions lib/private/Updater.php
Original file line number Diff line number Diff line change
Expand Up @@ -322,10 +322,6 @@ protected function checkAppUpgrade($version) {
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/preupdate.php')) {
$this->includePreUpdate($appId);
}
if (file_exists(\OC_App::getAppPath($appId) . '/appinfo/database.xml')) {
$this->emit('\OC\Updater', 'appSimulateUpdate', [$appId]);
\OC_DB::simulateUpdateDbFromStructure(\OC_App::getAppPath($appId) . '/appinfo/database.xml');
}
}
}

Expand Down
13 changes: 7 additions & 6 deletions lib/private/legacy/OC_App.php
Original file line number Diff line number Diff line change
Expand Up @@ -910,18 +910,19 @@ public static function updateApp(string $appId): bool {
return false;
}

if (is_file($appPath . '/appinfo/database.xml')) {
\OC::$server->getLogger()->error('The appinfo/database.xml file is not longer supported. Used in ' . $appId);
return false;
}

\OC::$server->getAppManager()->clearAppsCache();
$appData = self::getAppInfo($appId);

self::registerAutoloading($appId, $appPath, true);
self::executeRepairSteps($appId, $appData['repair-steps']['pre-migration']);

if (file_exists($appPath . '/appinfo/database.xml')) {
OC_DB::updateDbFromStructure($appPath . '/appinfo/database.xml');
} else {
$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
$ms->migrate();
}
$ms = new MigrationService($appId, \OC::$server->getDatabaseConnection());
$ms->migrate();

self::executeRepairSteps($appId, $appData['repair-steps']['post-migration']);
self::setupLiveMigrations($appId, $appData['repair-steps']['live-migration']);
Expand Down

0 comments on commit 2316080

Please sign in to comment.