From bc3104a64eb01701f5716ffdd0800be3fc9f972b Mon Sep 17 00:00:00 2001 From: Tom Needham Date: Mon, 9 Oct 2017 14:54:19 +0200 Subject: [PATCH] Improved debug logging during shipped app installation --- lib/private/Installer.php | 85 ++++++++++++++++++++++++++------------- lib/private/Setup.php | 2 + 2 files changed, 58 insertions(+), 29 deletions(-) diff --git a/lib/private/Installer.php b/lib/private/Installer.php index ce8ac5e15378..c408766e0882 100644 --- a/lib/private/Installer.php +++ b/lib/private/Installer.php @@ -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; @@ -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 @@ -451,19 +451,11 @@ 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'] )) { - $nodes = scandir($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" )) { @@ -471,18 +463,8 @@ public static function installShippedApps($softErrors = false) { $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; } } } @@ -492,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; @@ -510,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(); diff --git a/lib/private/Setup.php b/lib/private/Setup.php index b54d2e3f0cc3..6ee6c359004e 100644 --- a/lib/private/Setup.php +++ b/lib/private/Setup.php @@ -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,