File indexing completed on 2024-05-12 05:58:32

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_SearchController extends Local_Controller_Action_CliAbstract
0024 {
0025 
0026     public function runAction()
0027     {
0028         $storeId = (int)$this->getParam('store_id');
0029         $indexId = $this->getParam('index_id');
0030 
0031         if (isset($storeId) AND isset($indexId)) {
0032             $this->createStoreIndex($storeId, $indexId);
0033         } else {
0034             Zend_Registry::get('logger')->warn(__METHOD__ . ' - storeId and/or indexId is missing.');
0035         }
0036     }
0037 
0038     protected function createStoreIndex($storeId, $indexId)
0039     {
0040         $queue = Local_Queue_Factory::getQueue('search');
0041         $command = new Backend_Commands_CreateStoreIndex($storeId, $indexId);
0042         $msg = $queue->send(serialize($command));
0043     }
0044 
0045     public function initAction()
0046     {
0047         $storeId = (int)$this->getParam('store_id');
0048         $indexId = $this->getParam('index_id');
0049 
0050         //$this->createCronJob($storeId, $indexId);
0051 
0052         $this->createStoreIndex($storeId, $indexId);
0053     }
0054 
0055     /**
0056      * @param int    $storeId
0057      * @param string $indexId
0058      *
0059      * @throws Zend_Exception
0060      */
0061     protected function createCronJob($storeId, $indexId)
0062     {
0063         try {
0064             $manager = new Crontab_Manager_CrontabManager();
0065             //           $manager->user = 'www-data';
0066             $newJob = $manager->newJob('*/3 * * * * php /var/www/projects/pling/httpdocs/cron.php -a /backend/search/run/store_id/'
0067                 . $storeId . '/index_id/' . $indexId . '/ >> /var/www/projects/logs/search.log 2>&1', 'www-data');
0068             if (false == $manager->jobExists($newJob)) {
0069                 $manager->add($newJob);
0070                 $manager->save();
0071             }
0072         } catch (Exception $e) {
0073             Zend_Registry::get('logger')->err(__METHOD__ . ' - ' . print_r($e, true));
0074             exit();
0075         }
0076     }
0077 
0078 }