0013250: setup.php --install should only install available apps on demand
authorPhilipp Schüle <p.schuele@metaways.de>
Thu, 22 Jun 2017 07:16:36 +0000 (09:16 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Fri, 23 Jun 2017 09:13:53 +0000 (11:13 +0200)
https://forge.tine20.org/view.php?id=13250

Change-Id: Ibb54ee29d14521330242095cbb0af399b95a8f0a
Reviewed-on: http://gerrit.tine20.com/customers/4926
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tests/setup/Setup/ControllerTest.php
tine20/Setup/Controller.php
tine20/Setup/Frontend/Cli.php
tine20/Setup/Server/Cli.php

index c62bf8c..c5d51a9 100644 (file)
@@ -220,7 +220,7 @@ class Setup_ControllerTest extends PHPUnit_Framework_TestCase
         
         // checks
         $this->assertTrue(isset($activeSyncApp));
-        $this->assertTrue(isset($activeSyncApp['id']));
+        $this->assertTrue(isset($activeSyncApp['id']), 'ActiveSync ID missing ' . print_r($apps['results'], true));
         $this->assertEquals('uptodate', $activeSyncApp['install_status']);
     }
     
index 1eb1198..96a85eb 100644 (file)
@@ -376,12 +376,15 @@ class Setup_Controller
     /**
      * get list of applications as found in the filesystem
      *
+     * @param boolean $getInstalled applications, too
      * @return array appName => setupXML
      */
-    public function getInstallableApplications()
+    public function getInstallableApplications($getInstalled = false)
     {
         // create Tinebase tables first
-        $applications = array('Tinebase' => $this->getSetupXml('Tinebase'));
+        $applications = $getInstalled || ! $this->isInstalled('Tinebase')
+            ? array('Tinebase' => $this->getSetupXml('Tinebase'))
+            : array();
         
         try {
             $dirIterator = new DirectoryIterator($this->_baseDir);
@@ -392,9 +395,9 @@ class Setup_Controller
         
         foreach ($dirIterator as $item) {
             $appName = $item->getFileName();
-            if($appName{0} != '.' && $appName != 'Tinebase' && $item->isDir()) {
+            if ($appName{0} != '.' && $appName != 'Tinebase' && $item->isDir()) {
                 $fileName = $this->_baseDir . $appName . '/Setup/setup.xml' ;
-                if(file_exists($fileName)) {
+                if (file_exists($fileName) && ($getInstalled || ! $this->isInstalled($appName))) {
                     $applications[$appName] = $this->getSetupXml($appName);
                 }
             }
@@ -637,7 +640,7 @@ class Setup_Controller
     public function searchApplications()
     {
         // get installable apps
-        $installable = $this->getInstallableApplications();
+        $installable = $this->getInstallableApplications(/* $getInstalled */ true);
         
         // get installed apps
         if (Setup_Core::get(Setup_Core::CHECKDB)) {
index 3440d57..c7eae5d 100644 (file)
@@ -51,7 +51,7 @@ class Setup_Frontend_Cli
 
         $result = 0;
         if (isset($_opts->install)) {
-            $this->_install($_opts);
+            $result = $this->_install($_opts);
         } elseif(isset($_opts->update)) {
             $result = $this->_update($_opts);
         } elseif(isset($_opts->uninstall)) {
@@ -95,31 +95,41 @@ class Setup_Frontend_Cli
      * install new applications
      *
      * @param Zend_Console_Getopt $_opts
+     * @return integer
      */
     protected function _install(Zend_Console_Getopt $_opts)
     {
         $controller = Setup_Controller::getInstance();
-        
-        if($_opts->install === true) {
+
+        $options = $this->_parseRemainingArgs($_opts->getRemainingArgs());
+
+        if ($_opts->install === true) {
+            if (Setup_Controller::getInstance()->isInstalled('Tinebase')) {
+                // nothing to do
+                return 0;
+            }
             $applications = $controller->getInstallableApplications();
             $applications = array_keys($applications);
         } else {
             $applications = array();
             $applicationNames = explode(',', $_opts->install);
-            foreach($applicationNames as $applicationName) {
-                $applicationName = ucfirst(trim($applicationName));
-                try {
-                    $controller->getSetupXml($applicationName);
-                    $applications[] = $applicationName;
-                } catch (Setup_Exception_NotFound $e) {
-                    echo "Application $applicationName not found! Skipped...\n";
+            if (count($applicationNames) === 1 && strtolower($applicationNames[0]) === 'all') {
+                $applications = $controller->getInstallableApplications();
+                $applications = array_keys($applications);
+            } else {
+                foreach ($applicationNames as $applicationName) {
+                    $applicationName = ucfirst(trim($applicationName));
+                    try {
+                        $controller->getSetupXml($applicationName);
+                        $applications[] = $applicationName;
+                    } catch (Setup_Exception_NotFound $e) {
+                        echo "Application $applicationName not found! Skipped...\n";
+                    }
                 }
             }
         }
-        
-        $options = $this->_parseRemainingArgs($_opts->getRemainingArgs());
+
         $this->_promptRemainingOptions($applications, $options);
-        
         $controller->installApplications($applications, $options);
         
         if ((isset($options['acceptedTermsVersion']) || array_key_exists('acceptedTermsVersion', $options))) {
@@ -127,6 +137,7 @@ class Setup_Frontend_Cli
         }
         
         echo "Successfully installed " . count($applications) . " applications.\n";
+        return 0;
     }
 
     /**
@@ -138,7 +149,8 @@ class Setup_Frontend_Cli
      * 
      * @todo add required version server side
      */
-    protected function _promptRemainingOptions($_applications, &$_options) {
+    protected function _promptRemainingOptions($_applications, &$_options)
+    {
         if (in_array('Tinebase', $_applications)) {
             
             if (! isset($_options['acceptedTermsVersion'])) {
index 0749bc6..c7b5d25 100644 (file)
@@ -38,7 +38,7 @@ class Setup_Server_Cli implements Tinebase_Server_Interface
                 'getconfig'                 => 'Get Config value for a specify the key \' -- configkey="your_key"\'',
                 'check_requirements'        => 'Check if all requirements are met to install and run tine20',
                 'create_admin'              => 'Create new admin user (or reactivate if already exists)',
-                'install-s'                 => 'Install applications [All] or comma separated list;'
+                'install-s'                 => 'Install applications [all if nothing installed yet] or comma separated list (use "all" as parameter to install all available apps);'
                     . ' To specify the login name and login password of the admin user that is created during installation, append \' -- adminLoginName="admin" adminPassword="password"\''
                     . ' To add imap or smtp settings, append (for example) \' -- imap="host:mail.example.org,port:143,dbmail_host:localhost" smtp="ssl:tls"\'',
                 'update-s'                  => 'Update applications [All] or comma separated list',