From 54f45f95f51dc14d6a7126170b3277a3ad57b608 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Thomas=20M=C3=BCller?= Date: Thu, 28 Apr 2016 10:07:29 +0200 Subject: [PATCH] Adding repair steps for install and uninstall - fixes #24306 --- lib/private/App/InfoParser.php | 12 ++++++++ lib/private/legacy/app.php | 2 +- lib/private/legacy/installer.php | 51 +++++++++++-------------------- tests/data/app/expected-info.json | 4 ++- 4 files changed, 33 insertions(+), 36 deletions(-) diff --git a/lib/private/App/InfoParser.php b/lib/private/App/InfoParser.php index b7540c0424..21422d4060 100644 --- a/lib/private/App/InfoParser.php +++ b/lib/private/App/InfoParser.php @@ -74,6 +74,9 @@ class InfoParser { if (!array_key_exists('repair-steps', $array)) { $array['repair-steps'] = []; } + if (!array_key_exists('install', $array['repair-steps'])) { + $array['repair-steps']['install'] = []; + } if (!array_key_exists('pre-migration', $array['repair-steps'])) { $array['repair-steps']['pre-migration'] = []; } @@ -83,6 +86,9 @@ class InfoParser { if (!array_key_exists('live-migration', $array['repair-steps'])) { $array['repair-steps']['live-migration'] = []; } + if (!array_key_exists('uninstall', $array['repair-steps'])) { + $array['repair-steps']['uninstall'] = []; + } if (array_key_exists('documentation', $array) && is_array($array['documentation'])) { foreach ($array['documentation'] as $key => $url) { @@ -107,6 +113,9 @@ class InfoParser { $array['types'] = []; } } + if (isset($array['repair-steps']['install']['step']) && is_array($array['repair-steps']['install']['step'])) { + $array['repair-steps']['install'] = $array['repair-steps']['install']['step']; + } if (isset($array['repair-steps']['pre-migration']['step']) && is_array($array['repair-steps']['pre-migration']['step'])) { $array['repair-steps']['pre-migration'] = $array['repair-steps']['pre-migration']['step']; } @@ -116,6 +125,9 @@ class InfoParser { if (isset($array['repair-steps']['live-migration']['step']) && is_array($array['repair-steps']['live-migration']['step'])) { $array['repair-steps']['live-migration'] = $array['repair-steps']['live-migration']['step']; } + if (isset($array['repair-steps']['uninstall']['step']) && is_array($array['repair-steps']['uninstall']['step'])) { + $array['repair-steps']['uninstall'] = $array['repair-steps']['uninstall']['step']; + } return $array; } diff --git a/lib/private/legacy/app.php b/lib/private/legacy/app.php index 246bf97ee9..a1d4b7ce26 100644 --- a/lib/private/legacy/app.php +++ b/lib/private/legacy/app.php @@ -1187,7 +1187,7 @@ class OC_App { * @param string[] $steps * @throws \OC\NeedsUpdateException */ - private static function executeRepairSteps($appId, array $steps) { + public static function executeRepairSteps($appId, array $steps) { if (empty($steps)) { return; } diff --git a/lib/private/legacy/installer.php b/lib/private/legacy/installer.php index 24c79b2dd8..2bf95f3319 100644 --- a/lib/private/legacy/installer.php +++ b/lib/private/legacy/installer.php @@ -45,7 +45,7 @@ use OC\OCSClient; /** * This class provides the functionality needed to install, update and remove plugins/apps */ -class OC_Installer{ +class OC_Installer { /** * @@ -134,16 +134,19 @@ class OC_Installer{ self::includeAppScript($basedir . '/appinfo/install.php'); } + $appData = OC_App::getAppInfo($appId); + OC_App::executeRepairSteps($appId, $appData['repair-steps']['install']); + //set the installed version \OC::$server->getAppConfig()->setValue($info['id'], 'installed_version', OC_App::getAppVersion($info['id'])); \OC::$server->getAppConfig()->setValue($info['id'], 'enabled', 'no'); //set remote/public handelers foreach($info['remote'] as $name=>$path) { - OCP\CONFIG::setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); + OCP\Config::setAppValue('core', 'remote_'.$name, $info['id'].'/'.$path); } foreach($info['public'] as $name=>$path) { - OCP\CONFIG::setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); + OCP\Config::setAppValue('core', 'public_'.$name, $info['id'].'/'.$path); } OC_App::setAppTypes($info['id']); @@ -474,52 +477,30 @@ class OC_Installer{ /** * Removes an app * @param string $name name of the application to remove - * @param array $options options * @return boolean * - * This function removes an app. $options is an associative array. The - * following keys are optional:ja - * - keeppreferences: boolean, if true the user preferences won't be deleted - * - keepappconfig: boolean, if true the config will be kept - * - keeptables: boolean, if true the database will be kept - * - keepfiles: boolean, if true the user files will be kept * * This function works as follows - * -# including appinfo/remove.php + * -# call uninstall repair steps * -# removing the files * * The function will not delete preferences, tables and the configuration, * this has to be done by the function oc_app_uninstall(). */ - public static function removeApp( $name, $options = array()) { + public static function removeApp($appId) { - if(isset($options['keeppreferences']) and $options['keeppreferences']==false ) { - // todo - // remove preferences + $appData = OC_App::getAppInfo($appId); + if (!is_null($appData)) { + OC_App::executeRepairSteps($appId, $appData['repair-steps']['uninstall']); } - if(isset($options['keepappconfig']) and $options['keepappconfig']==false ) { - // todo - // remove app config - } - - if(isset($options['keeptables']) and $options['keeptables']==false ) { - // todo - // remove app database tables - } - - if(isset($options['keepfiles']) and $options['keepfiles']==false ) { - // todo - // remove user files - } - - if(OC_Installer::isDownloaded( $name )) { - $appdir=OC_App::getInstallPath().'/'.$name; - OC_Helper::rmdirr($appdir); + if(OC_Installer::isDownloaded( $appId )) { + $appDir=OC_App::getInstallPath() . '/' . $appId; + OC_Helper::rmdirr($appDir); return true; }else{ - \OCP\Util::writeLog('core', 'can\'t remove app '.$name.'. It is not installed.', \OCP\Util::ERROR); + \OCP\Util::writeLog('core', 'can\'t remove app '.$appId.'. It is not installed.', \OCP\Util::ERROR); return false; } @@ -590,6 +571,8 @@ class OC_Installer{ return false; } + OC_App::executeRepairSteps($app, $info['repair-steps']['install']); + $config = \OC::$server->getConfig(); $config->setAppValue($app, 'installed_version', OC_App::getAppVersion($app)); diff --git a/tests/data/app/expected-info.json b/tests/data/app/expected-info.json index 51d0c00cce..cef7a7fdab 100644 --- a/tests/data/app/expected-info.json +++ b/tests/data/app/expected-info.json @@ -69,8 +69,10 @@ } }, "repair-steps": { + "install": [], "pre-migration": [], "post-migration": [], - "live-migration": [] + "live-migration": [], + "uninstall": [] } }