Skip to content

Commit

Permalink
Improved debug logging during shipped app installation
Browse files Browse the repository at this point in the history
  • Loading branch information
tomneedham authored and DeepDiver1975 committed Oct 19, 2017
1 parent f66b360 commit bc3104a
Show file tree
Hide file tree
Showing 2 changed files with 58 additions and 29 deletions.
85 changes: 56 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,38 +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'] )) {
$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" )) {
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 @@ -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;
Expand All @@ -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();
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

0 comments on commit bc3104a

Please sign in to comment.