Add Reset_Demodata Cli function
authorsstamer <s.stamer@metaways.de>
Fri, 10 Apr 2015 11:15:24 +0000 (13:15 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 15 Apr 2015 16:06:05 +0000 (18:06 +0200)
- remove everything + install all demodata
- disabled random pictures for demodata

Change-Id: If65f1ff38a94d183a7aa11d7d0c21d3afc7187c4
Reviewed-on: http://gerrit.tine20.com/customers/1812
Tested-by: Jenkins CI (http://ci.tine20.com/)
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Setup/DemoData.php
tine20/Setup/Frontend/Cli.php
tine20/Setup/Server/Cli.php

index 573dbaa..1b96cc5 100644 (file)
@@ -147,7 +147,7 @@ class Addressbook_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
                         $this->_addresses[$i]['salutation'] = 'MR';
                     } else {
                         $isMan = false;
-                        $this->_addresses[$i]['salutation'] = 'MRS';
+                        $this->_addresses[$i]['salutation'] = 'MS';
                     }
                 } else {
                     $this->_addresses[$i][$indexes[$index]] = $field;
@@ -194,7 +194,8 @@ class Addressbook_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
         try {
             $record = $this->_controller->create($record);
             if ($imageData) {
-                $be->_saveImage($record->getId(), $imageData);
+                // @todo We should not use copyrighted/random pictures for demo data
+                //$be->_saveImage($record->getId(), $imageData);
             }
         } catch (Exception $e) {
             echo 'Skipping: ' . $data['n_given'] .' ' . $data['n_family'] . ($data['org_name'] ? ' ('.$data['org_name'].') ' : '') . $e->getMessage() . PHP_EOL;
index 633e9ac..af28b6d 100644 (file)
@@ -72,6 +72,8 @@ class Setup_Frontend_Cli
             $this->_createAdminUser($_opts);
         } elseif(isset($_opts->getconfig)) {
             $this->_getConfig($_opts);
+        } elseif(isset($_opts->reset_demodata)) {
+            $this->_resetDemodata($_opts);
         }
         
         if ($exitAfterHandle) {
@@ -267,6 +269,77 @@ class Setup_Frontend_Cli
         
         echo "Successfully uninstalled " . count($applications) . " applications.\n";
     }
+    
+    /**
+     * reinstall applications
+     * and reset Demodata
+     * php setup.php --reset_demodata USERNAME
+     * 
+     * @param Zend_Console_Getopt $_opts
+     */
+    protected function _resetDemodata(Zend_Console_Getopt $_opts)
+    {
+        $controller = Setup_Controller::getInstance();
+        $userController = Admin_Controller_User::getInstance();
+        $containerController = Tinebase_Container::getInstance();
+        $cli = new Tinebase_Frontend_Cli();
+        
+        //Don't reset this applications
+        $fixedApplications = array('Tinebase', 'Admin', 'Addressbook');
+        
+        //Log in
+        $opts = $_opts->getRemainingArgs();
+        $username = $opts[0];
+        if (empty($username)) {
+            echo "Username is missing!\n";
+            exit;
+        }
+        $user = Tinebase_User::getInstance()->getUserByLoginName($username);
+        Tinebase_Core::set(Tinebase_Core::USER, $user);
+        
+        //get all applications and remove some
+        $applications = Tinebase_Application::getInstance()->getApplications(NULL, 'id');
+        
+        foreach ($applications as $key => &$application) {
+            if (in_array($application, $fixedApplications)) {
+                unset($applications[$key]);
+            }
+        }
+        
+        //Uninstall Applications
+        try {
+            $controller->uninstallApplications($applications->name);
+            echo "Successfully uninstalled " . count($applications) . " applications.\n";
+        } catch (Tinebase_Exception_NotFound $e) {
+        }
+        //Install Applications
+        try {
+            $controller->installApplications($applications->name);
+            echo "Successfully installed " . count($applications) . " applications.\n";
+        } catch (Tinebase_Exception_NotFound $e) {
+        }
+        
+        //Clean up addressbooks
+        $internalContacts = $userController->getDefaultInternalAddressbook();
+        $containers = $containerController->getAll();
+        foreach ($containers as $key => &$container) {
+            if ($container->id == $internalContacts) {
+                // Do nothing
+            } else {
+                try {
+                    $containerController->deleteContainer($container, true);
+                } catch (Tinebase_Exception_NotFound $e) {
+                }
+            }
+        }
+        
+        echo "Successfully cleand up containers.\n";
+        
+        //Get Demodata
+        $cli->createAllDemoData();
+        
+        echo "Every thing done!\n";
+    }
 
     /**
      * list installed apps
index f293be3..2abf182 100644 (file)
@@ -50,7 +50,9 @@ class Setup_Server_Cli implements Tinebase_Server_Interface
                 'sync_passwords_from_ldap'  => 'Synchronize user passwords from ldap',
                 'egw14import'               => 'Import user and groups from egw14
                          Examples: 
-                          setup.php --egw14import /path/to/config.ini'
+                          setup.php --egw14import /path/to/config.ini',
+                'reset_demodata USERNAME'            => 'reinstall applications and install Demodata (Needs Admin user)'
+                    
             ));
             $opts->parse();
         } catch (Zend_Console_Getopt_Exception $e) {
@@ -68,6 +70,7 @@ class Setup_Server_Cli implements Tinebase_Server_Interface
             empty($opts->sync_passwords_from_ldap) && 
             empty($opts->egw14import) && 
             empty($opts->check_requirements) && 
+            empty($opts->reset_demodata) &&
             empty($opts->create_admin) && 
             empty($opts->setconfig) && 
             empty($opts->getconfig)))