summaryrefslogtreecommitdiffstats
path: root/lib/private/app.php
diff options
context:
space:
mode:
authorVincent Petry <pvince81@owncloud.com>2014-05-27 11:54:12 +0200
committerVincent Petry <pvince81@owncloud.com>2014-05-27 11:54:12 +0200
commitd43a7c5f6ec2806c43c374d598c756a116c3d95b (patch)
treebc4cfd0a51ab46a2248439bef0b11aefbd7dc167 /lib/private/app.php
parenta79f3fd1c0ddf9b8ac4d59ce2affccd4aabf83a0 (diff)
downloadnextcloud-server-d43a7c5f6ec2806c43c374d598c756a116c3d95b.tar.gz
nextcloud-server-d43a7c5f6ec2806c43c374d598c756a116c3d95b.zip
Added requiremin/requiremax fields for apps
Apps can now specify a minimum and maximum version of ownCloud in which they are supported.
Diffstat (limited to 'lib/private/app.php')
-rw-r--r--lib/private/app.php84
1 files changed, 62 insertions, 22 deletions
diff --git a/lib/private/app.php b/lib/private/app.php
index 575cc9f41af..50065197eb4 100644
--- a/lib/private/app.php
+++ b/lib/private/app.php
@@ -231,7 +231,7 @@ class OC_App{
// 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'])) {
+ if(!self::isAppCompatible($version, $info)) {
throw new \Exception(
$l->t("App \"%s\" can't be installed because it is not compatible with this version of ownCloud.",
array($info['name'])
@@ -898,7 +898,7 @@ class OC_App{
foreach($apps as $app) {
// check if the app is compatible with this version of ownCloud
$info = OC_App::getAppInfo($app);
- if(!isset($info['require']) or !self::isAppVersionCompatible($version, $info['require'])) {
+ if(!self::isAppCompatible($version, $info)) {
OC_Log::write('core',
'App "'.$info['name'].'" ('.$app.') can\'t be used because it is'
.' not compatible with this version of ownCloud',
@@ -909,38 +909,78 @@ class OC_App{
}
}
+ /**
+ * Ajust the number of version parts of $version1 to match
+ * the number of version parts of $version2.
+ *
+ * @param string $version1 version to adjust
+ * @param string $version2 version to take the number of parts from
+ * @return string shortened $version1
+ */
+ private static function adjustVersionParts($version1, $version2) {
+ $version1 = explode('.', $version1);
+ $version2 = explode('.', $version2);
+ // reduce $version1 to match the number of parts in $version2
+ while (count($version1) > count($version2)) {
+ array_pop($version1);
+ }
+ // if $version1 does not have enough parts, add some
+ while (count($version1) < count($version2)) {
+ $version1[] = '0';
+ }
+ return implode('.', $version1);
+ }
/**
- * Compares the app version with the owncloud version to see if the app
- * requires a newer version than the currently active one
- * @param array $owncloudVersions array with 3 entries: major minor bugfix
- * @param string $appRequired the required version from the xml
- * major.minor.bugfix
+ * Check whether the current ownCloud version matches the given
+ * application's version requirements.
+ *
+ * The comparison is made based on the number of parts that the
+ * app info version has. For example for ownCloud 6.0.3 if the
+ * app info version is expecting version 6.0, the comparison is
+ * made on the first two parts of the ownCloud version.
+ * This means that it's possible to specify "requiremin" => 6
+ * and "requiremax" => 6 and it will still match ownCloud 6.0.3.
+ *
+ * @param string $ocVersion ownCloud version to check against
+ * @param array $appInfo app info (from xml)
+ *
* @return boolean true if compatible, otherwise false
*/
- public static function isAppVersionCompatible($owncloudVersions, $appRequired){
- $appVersions = explode('.', $appRequired);
+ public static function isAppCompatible($ocVersion, $appInfo){
+ $requireMin = '';
+ $requireMax = '';
+ if (isset($appInfo['requiremin'])) {
+ $requireMin = $appInfo['requiremin'];
+ } else if (isset($appInfo['require'])) {
+ $requireMin = $appInfo['require'];
+ }
- for($i=0; $i<count($appVersions); $i++){
- $appVersion = (int) $appVersions[$i];
+ if (isset($appInfo['requiremax'])) {
+ $requireMax = $appInfo['requiremax'];
+ }
- if(isset($owncloudVersions[$i])){
- $owncloudVersion = $owncloudVersions[$i];
- } else {
- $owncloudVersion = 0;
- }
+ if (is_array($ocVersion)) {
+ $ocVersion = implode('.', $ocVersion);
+ }
- if($owncloudVersion < $appVersion){
- return false;
- } elseif ($owncloudVersion > $appVersion) {
- return true;
- }
+ if (!empty($requireMin)
+ && version_compare(self::adjustVersionParts($ocVersion, $requireMin), $requireMin, '<')
+ ) {
+
+ return false;
+ }
+
+ if (!empty($requireMax)
+ && version_compare(self::adjustVersionParts($ocVersion, $requireMax), $requireMax, '>')
+ ) {
+
+ return false;
}
return true;
}
-
/**
* get the installed version of all apps
*/