Crm_Setup_DemoData limited addresses used to create Leads to 100
authorPaul Mehrer <p.mehrer@metaways.de>
Thu, 3 Dec 2015 14:20:44 +0000 (15:20 +0100)
committerPhilipp Schüle <p.schuele@metaways.de>
Wed, 20 Jan 2016 14:17:29 +0000 (15:17 +0100)
added functionality to unset singleton instances of *_DemoData

Change-Id: Ic7e96c0b16f7dd04ee54418951a079d89520adc5
Reviewed-on: http://gerrit.tine20.com/customers/2470
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Addressbook/Setup/DemoData.php
tine20/Admin/Setup/DemoData.php
tine20/Calendar/Setup/DemoData.php
tine20/Crm/Setup/DemoData.php
tine20/HumanResources/Setup/DemoData.php
tine20/Sales/Setup/DemoData.php
tine20/Setup/Frontend/Cli.php
tine20/Timetracker/Setup/DemoData.php
tine20/Tinebase/Frontend/Cli.php
tine20/Tinebase/Frontend/Cli/Abstract.php

index 1b96cc5..11f79fb 100644 (file)
@@ -99,6 +99,17 @@ class Addressbook_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
         return self::$_instance;
     }
+
+    /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
     
     /**
      * this is required for other applications needing demo data of this application
index b6d8cca..818dd23 100644 (file)
@@ -97,6 +97,17 @@ class Admin_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
     }
 
     /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
+
+    /**
      * creates the groups if not created already
      */
     protected function _createGroups()
index 41a503f..abf98cd 100644 (file)
@@ -76,6 +76,17 @@ class Calendar_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
     }
 
     /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
+
+    /**
      * this is required for other applications needing demo data of this application
      * if this returns true, this demodata has been run already
      * 
index e78d867..98461dd 100644 (file)
@@ -77,6 +77,17 @@ class Crm_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
         return self::$_instance;
     }
+
+    /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
     
     /**
      * this is required for other applications needing demo data of this application
@@ -295,6 +306,10 @@ class Crm_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
     {
         $contacts = Addressbook_Controller_Contact::getInstance()->getAll();
         $addresses = $contacts->filter('type', 'contact');
+        $pagination = new Tinebase_Model_Pagination();
+        $pagination->start = 0;
+        $pagination->limit = 100;
+        $addresses->limitByPagination($pagination);
         $users = $contacts->filter('type', 'user');
         
         unset($contacts);
index c7c7541..ee83c12 100644 (file)
@@ -109,6 +109,17 @@ class HumanResources_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
         return self::$_instance;
     }
+
+    /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
     
     /**
      * this is required for other applications needing demo data of this application
index 5940696..5a8c99d 100644 (file)
@@ -81,6 +81,17 @@ class Sales_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
 
         return self::$_instance;
     }
+
+    /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
     
     /**
      * this is required for other applications needing demo data of this application
index 16cbd6e..0d67d1f 100644 (file)
@@ -357,6 +357,7 @@ class Setup_Frontend_Cli
                 }
             }
         }
+        unset($containers);
         echo "Successfully cleand up containers.\n";
         
         //remove state
index 36f5c09..1be1df0 100644 (file)
@@ -135,6 +135,17 @@ class Timetracker_Setup_DemoData extends Tinebase_Setup_DemoData_Abstract
     }
 
     /**
+     * unsets the instance to save memory, be aware that hasBeenRun still needs to work after unsetting!
+     *
+     */
+    public function unsetInstance()
+    {
+        if (self::$_instance !== NULL) {
+            self::$_instance = null;
+        }
+    }
+
+    /**
      * this is required for other applications needing demo data of this application
      * if this returns true, this demodata has been run already
      * 
index a624a42..8b82be5 100644 (file)
@@ -816,6 +816,7 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
                 echo 'DemoData in application "' . $appName . '" not found.' . PHP_EOL . PHP_EOL;
             }
         }
+        unset($applications);
         
         foreach($this->_applicationsToWorkOn as $app => $cfg) {
             $this->_createDemoDataRecursive($app, $cfg, $_opts);
index a2ad834..1899f20 100644 (file)
@@ -196,8 +196,12 @@ class Tinebase_Frontend_Cli_Abstract
             }
             
 
-            if ($className::getInstance()->createDemoData($options)) {
+            $setupDemoData = $className::getInstance();
+            if ($setupDemoData->createDemoData($options)) {
                 echo 'Demo Data was created successfully' . chr(10) . chr(10);
+                if (method_exists($setupDemoData, 'unsetInstance')) {
+                    $setupDemoData->unsetInstance();
+                }
             } else {
                 echo 'No Demo Data has been created' . chr(10) . chr(10);
             }