0012062: allow to omit minor version number for apps
authorPhilipp Schüle <p.schuele@metaways.de>
Tue, 19 Jul 2016 16:25:53 +0000 (18:25 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Thu, 21 Jul 2016 15:09:42 +0000 (17:09 +0200)
* and improves minor/major version fetching
 in Application model

https://forge.tine20.org/view.php?id=12062

Change-Id: Ib4d8e59b94f2610ae1b54dbbe53db793ee68ebf5
Reviewed-on: http://gerrit.tine20.com/customers/3371
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Setup/Controller.php
tine20/Tinebase/Model/Application.php

index 27a0580..bd554c3 100644 (file)
@@ -501,9 +501,8 @@ class Setup_Controller
                 $messages[] = $message;
                 Setup_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' ' . $message);
 
-                list($fromMajorVersion, $fromMinorVersion) = explode('.', $_application->version);
-        
-                $minor = $fromMinorVersion;
+                $version = $_application->getMajorAndMinorVersion();
+                $minor = $version['minor'];
                 
                 $className = ucfirst($_application->name) . '_Setup_Update_Release' . $_majorVersion;
                 if(! class_exists($className)) {
index f638351..a2f1851 100644 (file)
@@ -106,19 +106,36 @@ class Tinebase_Model_Application extends Tinebase_Record_Abstract
     }    
     
     /**
-     * return the major version of the appliaction
+     * return the version of the application
      *
-     * @return  int the major version
+     * @return  array with minor and major version
      * @throws  Tinebase_Exception_InvalidArgument
      */
-    public function getMajorVersion()
+    public function getMajorAndMinorVersion()
     {
-        if(empty($this->version)) {
+        if (empty($this->version)) {
             throw new Tinebase_Exception_InvalidArgument('No version set.');
         }
-        
-        list($majorVersion, $minorVersion) = explode('.', $this->version);
-        
-        return $majorVersion;
+
+        if (strpos($this->version, '.') === false) {
+            $minorVersion = 0;
+            $majorVersion = $this->version;
+        } else {
+            list($majorVersion, $minorVersion) = explode('.', $this->version);
+        }
+
+        return array('major' => $majorVersion, 'minor' => $minorVersion);
+    }
+
+    /**
+     * get major app version
+     *
+     * @return string
+     * @throws Tinebase_Exception_InvalidArgument
+     */
+    public function getMajorVersion()
+    {
+        $versions = $this->getMajorAndMinorVersion();
+        return $versions['major'];
     }
 }