File indexing completed on 2024-06-23 05:51:18

0001 <?php
0002 
0003 /**
0004  *  ocs-webserver
0005  *
0006  *  Copyright 2016 by pling GmbH.
0007  *
0008  *    This file is part of ocs-webserver.
0009  *
0010  *    This program is free software: you can redistribute it and/or modify
0011  *    it under the terms of the GNU Affero General Public License as
0012  *    published by the Free Software Foundation, either version 3 of the
0013  *    License, or (at your option) any later version.
0014  *
0015  *    This program is distributed in the hope that it will be useful,
0016  *    but WITHOUT ANY WARRANTY; without even the implied warranty of
0017  *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
0018  *    GNU Affero General Public License for more details.
0019  *
0020  *    You should have received a copy of the GNU Affero General Public License
0021  *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
0022  **/
0023 class Backend_Commands_InitCacheStoreCategories implements Local_Queue_CommandInterface
0024 {
0025 
0026     protected $storeId;
0027     protected $options;
0028 
0029     /**
0030      * PHP 5 allows developers to declare constructor methods for classes.
0031      * Classes which have a constructor method call this method on each newly-created object,
0032      * so it is suitable for any initialization that the object may need before it is used.
0033      *
0034      * Note: Parent constructors are not called implicitly if the child class defines a constructor.
0035      * In order to run a parent constructor, a call to parent::__construct() within the child constructor is required.
0036      *
0037      * param [ mixed $args [, $... ]]
0038      *
0039      * @param int    $storeId
0040      * @param string $indexId
0041      *
0042      * @link http://php.net/manual/en/language.oop5.decon.php
0043      */
0044     public function __construct($storeId)
0045     {
0046         $this->storeId = $storeId;
0047         $this->options = Zend_Registry::get('config')->settings->toArray();
0048     }
0049 
0050     public function doCommand()
0051     {
0052 
0053         return $this->callInitCache($this->storeId);
0054     }
0055 
0056     protected function callInitCache($storeId)
0057     {
0058         $webCache = $this->initWebCacheAccess($this->options);
0059         $modelPCat = new Default_Model_ProjectCategory();
0060         $tree = $modelPCat->fetchCategoryTreeForStore($storeId, true);
0061         $webCache->save($tree,Default_Model_ProjectCategory::CACHE_TREE_STORE. "_{$storeId}", array(), 28800);
0062 
0063         $modelConfigStore = new Default_Model_DbTable_ConfigStore();
0064         $storesCat = $modelConfigStore->fetchAllStoresAndCategories(true);
0065         $webCache->save($storesCat,Default_Model_DbTable_ConfigStore::CACHE_STORES_CATEGORIES, array(), 28800);
0066     }
0067 
0068     protected function initWebCacheAccess($options)
0069     {
0070         $cache = Zend_Cache::factory(
0071             $options['cache']['frontend']['type'],
0072             $options['cache']['backend']['type'],
0073             $options['cache']['frontend']['options'],
0074             $options['cache']['backend']['options']
0075         );
0076         return $cache;
0077     }
0078 
0079 }