moves rebuildPaths to Tinebase_Controller
authorPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Mar 2017 15:19:13 +0000 (17:19 +0200)
committerPhilipp Schüle <p.schuele@metaways.de>
Mon, 27 Mar 2017 15:18:47 +0000 (17:18 +0200)
see 0012032: path filter with fulltext search

Change-Id: I2f30938a0dfde763d227157224cc5e62fcf5bc9f
Reviewed-on: http://gerrit.tine20.com/customers/4440
Reviewed-by: Philipp Schüle <p.schuele@metaways.de>
Tested-by: Philipp Schüle <p.schuele@metaways.de>
tine20/Tinebase/Controller.php
tine20/Tinebase/Frontend/Cli.php
tine20/Tinebase/Setup/Update/Release10.php

index 171a43c..e2beb77 100644 (file)
@@ -761,4 +761,61 @@ class Tinebase_Controller extends Tinebase_Controller_Event
                 ? $session->userAccountChanged
                 : false;
     }
+
+    /**
+     * rebuild paths
+     *
+     * @return bool
+     * @throws Tinebase_Exception_AccessDenied
+     * @throws Tinebase_Exception_NotFound
+     */
+    public function rebuildPaths()
+    {
+        if (true !== Tinebase_Config::getInstance()->featureEnabled(Tinebase_Config::FEATURE_SEARCH_PATH)) {
+            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' search paths are not enabled');
+            return false;
+        }
+
+        $applications = Tinebase_Application::getInstance()->getApplications();
+        foreach($applications as $application) {
+            try {
+                $app = Tinebase_Core::getApplicationInstance($application, '', true);
+            } catch (Tinebase_Exception_NotFound $tenf) {
+                continue;
+            }
+
+            if (! $app instanceof Tinebase_Controller_Abstract) {
+                continue;
+            }
+
+            $pathModels = $app->getModelsUsingPaths();
+            if (!is_array($pathModels)) {
+                $pathModels = array();
+            }
+            foreach($pathModels as $pathModel) {
+                $controller = Tinebase_Core::getApplicationInstance($pathModel, '', true);
+
+                $_filter = $pathModel . 'Filter';
+                $_filter = new $_filter();
+
+                $iterator = new Tinebase_Record_Iterator(array(
+                    'iteratable' => $this,
+                    'controller' => $controller,
+                    'filter' => $_filter,
+                    'options' => array('getRelations' => true),
+                    'function' => 'rebuildPathsIteration',
+                ));
+                $result = $iterator->iterate($controller);
+
+                if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
+                    if (false === $result) {
+                        $result['totalcount'] = 0;
+                    }
+                    Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Build paths for ' . $result['totalcount'] . ' records of ' . $pathModel);
+                }
+            }
+        }
+
+        return true;
+    }
 }
index 8eaf406..a906ac4 100644 (file)
@@ -63,8 +63,10 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
     }
 
     /**
+     * rebuildPaths
+     *
     * @param Zend_Console_Getopt $_opts
-    * @return boolean success
+    * @return integer success
     */
     public function rebuildPaths($opts)
     {
@@ -72,50 +74,9 @@ class Tinebase_Frontend_Cli extends Tinebase_Frontend_Cli_Abstract
             return -1;
         }
 
-        if (true !== Tinebase_Config::getInstance()->featureEnabled(Tinebase_Config::FEATURE_SEARCH_PATH)) {
-            Tinebase_Core::getLogger()->crit(__METHOD__ . '::' . __LINE__ . ' search paths are not enabled');
-            return -1;
-        }
-
-        $applications = Tinebase_Application::getInstance()->getApplications();
-        foreach($applications as $application) {
-            try {
-                $app = Tinebase_Core::getApplicationInstance($application, '', true);
-            } catch (Tinebase_Exception_NotFound $tenf) {
-                continue;
-            }
-
-            if (! $app instanceof Tinebase_Controller_Abstract) {
-                continue;
-            }
-
-            $pathModels = $app->getModelsUsingPaths();
-            if (!is_array($pathModels)) {
-                $pathModels = array();
-            }
-            foreach($pathModels as $pathModel) {
-                $controller = Tinebase_Core::getApplicationInstance($pathModel, '', true);
-
-                $_filter = $pathModel . 'Filter';
-                $_filter = new $_filter();
-
-                $iterator = new Tinebase_Record_Iterator(array(
-                    'iteratable' => $this,
-                    'controller' => $controller,
-                    'filter' => $_filter,
-                    'options' => array('getRelations' => true),
-                    'function' => 'rebuildPathsIteration',
-                ));
-                $result = $iterator->iterate($controller);
+        $result = Tinebase_Controller::getInstance()->rebuildPaths();
 
-                if (Tinebase_Core::isLogLevel(Zend_Log::INFO)) {
-                    if (false === $result) {
-                        $result['totalcount'] = 0;
-                    }
-                    Tinebase_Core::getLogger()->info(__METHOD__ . '::' . __LINE__ . ' Build paths for ' . $result['totalcount'] . ' records of ' . $pathModel);
-                }
-            }
-        }
+        return $result ? true : -1;
     }
 
     /**
index 44f30cc..6bb0066 100644 (file)
@@ -436,8 +436,7 @@ class Tinebase_Setup_Update_Release10 extends Setup_Update_Abstract
 
         $this->createTable('path', $declaration, 'Tinebase', 2);
 
-        $frontend = new Tinebase_Frontend_Cli();
-        $frontend->rebuildPaths(null);
+        Tinebase_Controller::getInstance()->rebuildPaths();
 
         $this->setApplicationVersion('Tinebase', '10.10');
     }