Adding repair steps for install and uninstall - fixes #24306

This commit is contained in:
Thomas Müller 2016-04-28 10:07:29 +02:00
parent a323111bd1
commit 54f45f95f5
No known key found for this signature in database
GPG Key ID: A943788A3BBEC44C
4 changed files with 33 additions and 36 deletions

View File

@ -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;
}

View File

@ -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;
}

View File

@ -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));

View File

@ -69,8 +69,10 @@
}
},
"repair-steps": {
"install": [],
"pre-migration": [],
"post-migration": [],
"live-migration": []
"live-migration": [],
"uninstall": []
}
}