summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorChristopher <kondou@ts.unde.re>2013-08-25 11:56:56 -0700
committerChristopher <kondou@ts.unde.re>2013-08-25 11:56:56 -0700
commitb8965c6107a908db705fde55e0606998ccbf02e4 (patch)
tree71383a8fd1a0d314e4ba5442fc2dd54a9566d1fa /lib
parent596ac40b7f7143622ce2fabf48b96b4320e8c582 (diff)
parent0ce35af02acb2fa9fe0ef401dc75345b5114e3d6 (diff)
downloadnextcloud-server-b8965c6107a908db705fde55e0606998ccbf02e4.tar.gz
nextcloud-server-b8965c6107a908db705fde55e0606998ccbf02e4.zip
Merge pull request #4331 from owncloud/improve_app-management
Improve app-management
Diffstat (limited to 'lib')
-rw-r--r--lib/app.php17
-rw-r--r--lib/installer.php53
2 files changed, 27 insertions, 43 deletions
diff --git a/lib/app.php b/lib/app.php
index f76b92cde1b..8f5dd1d685e 100644
--- a/lib/app.php
+++ b/lib/app.php
@@ -210,7 +210,8 @@ class OC_App{
/**
* @brief enables an app
* @param mixed $app app
- * @return bool
+ * @throws \Exception
+ * @return void
*
* This function set an app as enabled in appconfig.
*/
@@ -228,25 +229,25 @@ class OC_App{
}
}
}
+ $l = OC_L10N::get('core');
if($app!==false) {
// check if the app is compatible with this version of ownCloud
$info=OC_App::getAppInfo($app);
$version=OC_Util::getVersion();
if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) {
- OC_Log::write('core',
- 'App "'.$info['name'].'" can\'t be installed because it is'
- .' not compatible with this version of ownCloud',
- OC_Log::ERROR);
- return false;
+ throw new \Exception(
+ $l->t("App \"%s\" can't be installed because it is not compatible with this version of ownCloud.",
+ array($info['name'])
+ )
+ );
}else{
OC_Appconfig::setValue( $app, 'enabled', 'yes' );
if(isset($appdata['id'])) {
OC_Appconfig::setValue( $app, 'ocsid', $appdata['id'] );
}
- return true;
}
}else{
- return false;
+ throw new \Exception($l->t("No app name specified"));
}
}
diff --git a/lib/installer.php b/lib/installer.php
index c29f9ec8982..b9684eaeea0 100644
--- a/lib/installer.php
+++ b/lib/installer.php
@@ -27,6 +27,7 @@ class OC_Installer{
/**
* @brief Installs an app
* @param $data array with all information
+ * @throws \Exception
* @returns integer
*
* This function installs an app. All information needed are passed in the
@@ -56,23 +57,22 @@ class OC_Installer{
* needed to get the app working.
*/
public static function installApp( $data = array()) {
+ $l = \OC_L10N::get('lib');
+
if(!isset($data['source'])) {
- OC_Log::write('core', 'No source specified when installing app', OC_Log::ERROR);
- return false;
+ throw new \Exception($l->t("No source specified when installing app"));
}
//download the file if necesary
if($data['source']=='http') {
$path=OC_Helper::tmpFile();
if(!isset($data['href'])) {
- OC_Log::write('core', 'No href specified when installing app from http', OC_Log::ERROR);
- return false;
+ throw new \Exception($l->t("No href specified when installing app from http"));
}
copy($data['href'], $path);
}else{
if(!isset($data['path'])) {
- OC_Log::write('core', 'No path specified when installing app from local file', OC_Log::ERROR);
- return false;
+ throw new \Exception($l->t("No path specified when installing app from local file"));
}
$path=$data['path'];
}
@@ -86,8 +86,7 @@ class OC_Installer{
rename($path, $path.'.tgz');
$path.='.tgz';
}else{
- OC_Log::write('core', 'Archives of type '.$mime.' are not supported', OC_Log::ERROR);
- return false;
+ throw new \Exception($l->t("Archives of type %s are not supported", array($mime)));
}
//extract the archive in a temporary folder
@@ -97,12 +96,11 @@ class OC_Installer{
if($archive=OC_Archive::open($path)) {
$archive->extract($extractDir);
} else {
- OC_Log::write('core', 'Failed to open archive when installing app', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
- return false;
+ throw new \Exception($l->t("Failed to open archive when installing app"));
}
//load the info.xml file of the app
@@ -118,62 +116,48 @@ class OC_Installer{
}
}
if(!is_file($extractDir.'/appinfo/info.xml')) {
- OC_Log::write('core', 'App does not provide an info.xml file', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
- return false;
+ throw new \Exception($l->t("App does not provide an info.xml file"));
}
$info=OC_App::getAppInfo($extractDir.'/appinfo/info.xml', true);
// check the code for not allowed calls
if(!OC_Installer::checkCode($info['id'], $extractDir)) {
- OC_Log::write('core', 'App can\'t be installed because of not allowed code in the App', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
- return false;
+ throw new \Exception($l->t("App can't be installed because of not allowed code in the App"));
}
// check if the app is compatible with this version of ownCloud
if(
- !isset($info['require'])
- or !OC_App::isAppVersionCompatible(OC_Util::getVersion(), $info['require'])
- ) {
- OC_Log::write('core',
- 'App can\'t be installed because it is not compatible with this version of ownCloud',
- OC_Log::ERROR);
+ !isset($info['require'])
+ or !OC_App::isAppVersionCompatible(OC_Util::getVersion(), $info['require'])
+ ) {
OC_Helper::rmdirr($extractDir);
- return false;
+ throw new \Exception($l->t("App can't be installed because it is not compatible with this version of ownCloud"));
}
// check if shipped tag is set which is only allowed for apps that are shipped with ownCloud
if(isset($info['shipped']) and ($info['shipped']=='true')) {
- OC_Log::write('core',
- 'App can\'t be installed because it contains the <shipped>true</shippe>'
- .' tag which is not allowed for non shipped apps',
- OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
- return false;
+ throw new \Exception($l->t("App can't be installed because it contains the <shipped>true</shipped> tag which is not allowed for non shipped apps"));
}
// check if the ocs version is the same as the version in info.xml/version
if(!isset($info['version']) or ($info['version']<>$data['appdata']['version'])) {
- OC_Log::write('core',
- 'App can\'t be installed because the version in info.xml/version is not the same'
- .' as the version reported from the app store',
- OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
- return false;
+ throw new \Exception($l->t("App can't be installed because the version in info.xml/version is not the same as the version reported from the app store"));
}
$basedir=OC_App::getInstallPath().'/'.$info['id'];
//check if the destination directory already exists
if(is_dir($basedir)) {
- OC_Log::write('core', 'App directory already exists', OC_Log::WARN);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
- return false;
+ throw new \Exception($l->t("App directory already exists"));
}
if(isset($data['pretent']) and $data['pretent']==true) {
@@ -182,12 +166,11 @@ class OC_Installer{
//copy the app to the correct place
if(@!mkdir($basedir)) {
- OC_Log::write('core', 'Can\'t create app folder. Please fix permissions. ('.$basedir.')', OC_Log::ERROR);
OC_Helper::rmdirr($extractDir);
if($data['source']=='http') {
unlink($path);
}
- return false;
+ throw new \Exception($l->t("Can't create app folder. Please fix permissions. %s", array($basedir)));
}
OC_Helper::copyr($extractDir, $basedir);