Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[stable10] install order #29267

Merged
merged 2 commits into from
Oct 23, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
86 changes: 57 additions & 29 deletions lib/private/Installer.php
Original file line number Diff line number Diff line change
Expand Up @@ -38,9 +38,8 @@

namespace OC;

use OC\App\CodeChecker\CodeChecker;
use OC\App\CodeChecker\EmptyCheck;
use OC\App\CodeChecker\PrivateCheck;
use Doctrine\DBAL\Exception\TableExistsException;
use OC\DB\MigrationService;
use OC_App;
use OC_DB;
use OC_Helper;
Expand Down Expand Up @@ -420,8 +419,9 @@ public static function isDownloaded( $name ) {

/**
* Removes an app
* @param string $name name of the application to remove
* @param string $appId name of the application to remove
* @return boolean
* @throws AppAlreadyInstalledException
*
*
* This function works as follows
Expand Down Expand Up @@ -451,37 +451,20 @@ public static function removeApp($appId) {
return false;
}

/**
* Installs shipped apps
*
* This function installs all apps found in the 'apps' directory that should be enabled by default;
* @param bool $softErrors When updating we ignore errors and simply log them, better to have a
* working ownCloud at the end instead of an aborted update.
* @return array Array of error messages (appid => Exception)
*/
public static function installShippedApps($softErrors = false) {
$errors = [];
protected static function getShippedApps() {
$shippedApps = [];
foreach(\OC::$APPSROOTS as $app_dir) {
if($dir = opendir( $app_dir['path'] )) {
while( false !== ( $filename = readdir( $dir ))) {
$nodes = scandir($app_dir['path']);
foreach($nodes as $filename) {
if( substr( $filename, 0, 1 ) != '.' and is_dir($app_dir['path']."/$filename") ) {
if( file_exists( $app_dir['path']."/$filename/appinfo/info.xml" )) {
if(!Installer::isInstalled($filename)) {
$info=OC_App::getAppInfo($filename);
$enabled = isset($info['default_enable']);
if (($enabled || in_array($filename, \OC::$server->getAppManager()->getAlwaysEnabledApps()))
&& \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
if ($softErrors) {
try {
Installer::installShippedApp($filename);
} catch (\Doctrine\DBAL\Exception\TableExistsException $e) {
$errors[$filename] = $e;
continue;
}
} else {
Installer::installShippedApp($filename);
}
\OC::$server->getConfig()->setAppValue($filename, 'enabled', 'yes');
&& \OC::$server->getConfig()->getAppValue($filename, 'enabled') !== 'no') {
$shippedApps[] = $filename;
}
}
}
Expand All @@ -491,16 +474,56 @@ public static function installShippedApps($softErrors = false) {
}
}


// Fix the order - make files first
$shippedApps = array_diff($shippedApps,['files', 'dav']);
array_unshift($shippedApps, 'dav');
array_unshift($shippedApps, 'files');
return $shippedApps;
}

/**
* Installs shipped apps
*
* This function installs all apps found in the 'apps' directory that should be enabled by default;
* @param bool $softErrors When updating we ignore errors and simply log them, better to have a
* working ownCloud at the end instead of an aborted update.
* @return array Array of error messages (appid => Exception)
*/
public static function installShippedApps($softErrors = false) {
$errors = [];
$appsToInstall = Installer::getShippedApps();

foreach($appsToInstall as $appToInstall) {
if(!Installer::isInstalled($appToInstall)) {
if ($softErrors) {
try {
Installer::installShippedApp($appToInstall);
} catch (TableExistsException $e) {
\OC::$server->getLogger()->logException($e, ['app' => __CLASS__]);
$errors[$appToInstall] = $e;
continue;
}
} else {
Installer::installShippedApp($appToInstall);
}
\OC::$server->getConfig()->setAppValue($appToInstall, 'enabled', 'yes');
}
}

return $errors;

}

/**
* install an app already placed in the app folder
* @param string $app id of the app to install
* @return integer
* @return integer|false
*/
public static function installShippedApp($app) {

\OC::$server->getLogger()->info('Attempting to install shipped app: '.$app);

$info = OC_App::getAppInfo($app);
if (is_null($info)) {
return false;
Expand All @@ -509,20 +532,25 @@ public static function installShippedApp($app) {
//install the database
$appPath = OC_App::getAppPath($app);
if (isset($info['use-migrations']) && $info['use-migrations'] === 'true') {
$ms = new \OC\DB\MigrationService($app, \OC::$server->getDatabaseConnection());
\OC::$server->getLogger()->debug('Running app database migrations');
$ms = new MigrationService($app, \OC::$server->getDatabaseConnection());
$ms->migrate();
} else {
if(is_file($appPath.'/appinfo/database.xml')) {
\OC::$server->getLogger()->debug('Create app database from schema file');
OC_DB::createDbFromStructure($appPath . '/appinfo/database.xml');
}
}

//run appinfo/install.php
\OC_App::registerAutoloading($app, $appPath);

\OC::$server->getLogger()->debug('Running app install script');
self::includeAppScript("$appPath/appinfo/install.php");

\OC_App::setupBackgroundJobs($info['background-jobs']);

\OC::$server->getLogger()->debug('Running app install repair steps');
OC_App::executeRepairSteps($app, $info['repair-steps']['install']);

$config = \OC::$server->getConfig();
Expand Down
2 changes: 2 additions & 0 deletions lib/private/Setup.php
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,8 @@ class Setup {
* @param IConfig $config
* @param IniGetWrapper $iniWrapper
* @param \OC_Defaults $defaults
* @param ILogger $logger
* @param ISecureRandom $random
*/
function __construct(IConfig $config,
IniGetWrapper $iniWrapper,
Expand Down