File indexing completed on 2024-12-22 05:37:18
0001 #!/usr/bin/php -f 0002 <?php 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 0024 date_default_timezone_set('EST'); 0025 0026 $time = microtime(true); 0027 $memory = memory_get_usage(); 0028 set_time_limit(0); 0029 0030 // Define if APC extension is loaded 0031 define('APC_EXTENSION_LOADED', 0032 extension_loaded('apc') && ini_get('apc.enabled') && (PHP_SAPI !== 'cli' || ini_get('apc.enable_cli'))); 0033 0034 // Define if APC extension is loaded 0035 define('MEMCACHED_EXTENSION_LOADED', extension_loaded('memcached')); 0036 0037 // Define if APC extension is loaded 0038 define('MEMCACHE_EXTENSION_LOADED', extension_loaded('memcache')); 0039 0040 // Define path to application directory 0041 defined('APPLICATION_PATH') 0042 || define('APPLICATION_PATH', realpath(dirname(__FILE__) . '/../application')); 0043 0044 defined('APPLICATION_DATA') 0045 || define('APPLICATION_DATA', realpath(dirname(__FILE__) . '/../data')); 0046 0047 // Define path to application cache 0048 defined('APPLICATION_CACHE') 0049 || define('APPLICATION_CACHE', realpath(dirname(__FILE__) . '/../data/cache/cli')); 0050 0051 // Define path to application library 0052 defined('APPLICATION_LIB') 0053 || define('APPLICATION_LIB', realpath(dirname(__FILE__) . '/../library')); 0054 0055 // Define application environment 0056 define('APPLICATION_ENV', 'cronjob'); 0057 define('CRONJOB_RUNNING', true); 0058 0059 // Ensure library/ is on include_path 0060 set_include_path(implode(PATH_SEPARATOR, array( 0061 APPLICATION_LIB, 0062 get_include_path(), 0063 ))); 0064 0065 // Initialising Autoloader 0066 require APPLICATION_LIB . '/Zend/Loader/SplAutoloader.php'; 0067 require APPLICATION_LIB . '/Zend/Loader/StandardAutoloader.php'; 0068 require APPLICATION_LIB . '/Zend/Loader/AutoloaderFactory.php'; 0069 Zend_Loader_AutoloaderFactory::factory(array( 0070 'Zend_Loader_StandardAutoloader' => array( 0071 'autoregister_zf' => true, 0072 'namespaces' => array( 0073 'Application' => APPLICATION_PATH, 0074 ) 0075 ) 0076 )); 0077 0078 // Including plugin cache file 0079 if (file_exists(APPLICATION_CACHE . DIRECTORY_SEPARATOR . 'pluginLoaderCache.php')) { 0080 include_once APPLICATION_CACHE . DIRECTORY_SEPARATOR . 'pluginLoaderCache.php'; 0081 } 0082 Zend_Loader_PluginLoader::setIncludeFileCache(APPLICATION_CACHE . DIRECTORY_SEPARATOR . 'pluginLoaderCache.php'); 0083 0084 0085 // Set configuration 0086 $configuration = APPLICATION_PATH . '/configs/application.ini'; 0087 // Merge an existing local configuration file (application.local.ini) with global config 0088 if (file_exists(APPLICATION_PATH . '/configs/application.local.ini')) { 0089 $configuration = array( 0090 'config' => array( 0091 APPLICATION_PATH . '/configs/application.ini', 0092 APPLICATION_PATH . '/configs/application.local.ini' 0093 ) 0094 ); 0095 } 0096 0097 // Create application, bootstrap, and run 0098 //require_once APPLICATION_LIB . 'Zend/Application.php'; 0099 //$application = new Zend_Application( 0100 // APPLICATION_ENV, 0101 // $configuration 0102 //); 0103 require_once APPLICATION_LIB . '/Local/Application.php'; 0104 // Create application, bootstrap, and run 0105 $application = new Local_Application( 0106 APPLICATION_ENV, 0107 $configuration 0108 ); 0109 0110 $application->bootstrap(array( 0111 'Autoload', 0112 'Config', 0113 'Cache', 0114 'Locale', 0115 'DbAdapter', 0116 'Logger', 0117 'Globals', 0118 'ThirdParty', 0119 'FrontController', 0120 'Modules', 0121 'Db', 0122 'GlobalApplicationVars', 0123 'Mail' 0124 )); 0125 0126 $consoleOptions = new Zend_Console_Getopt(array( 0127 'action|a=s' => 'action to perform in format of "module/controller/action"', 0128 'help|h' => 'displays usage information', 0129 'list|l' => 'List available jobs', 0130 )); 0131 0132 try { 0133 $consoleOptions->parse(); 0134 } catch (Zend_Console_Getopt_Exception $e) { 0135 // Bad options passed: report usage 0136 echo $e->getUsageMessage(); 0137 return false; 0138 } 0139 0140 if ($consoleOptions->getOption('l')) { 0141 // add help messages.. 0142 } 0143 0144 if ($consoleOptions->getOption('h')) { 0145 echo $consoleOptions->getUsageMessage(); 0146 return true; 0147 } 0148 0149 if ($consoleOptions->getOption('a')) { 0150 $front = $application->getBootstrap()->getResource('frontcontroller'); 0151 0152 $parameter = array_reverse(array_filter(explode('/', $consoleOptions->getOption('a')))); 0153 $module = array_pop($parameter); 0154 $controller = array_pop($parameter); 0155 $action = array_pop($parameter); 0156 0157 $passParam = array(); 0158 0159 if (count($parameter)) { 0160 for ($i = 0; $i < count($parameter); $i = $i + 2) { 0161 $passParam[$parameter[$i + 1]] = $parameter[$i]; 0162 } 0163 } 0164 0165 $front->registerPlugin(new Zend_Controller_Plugin_ErrorHandler(array( 0166 'module' => $module, 0167 'controller' => $controller, 0168 'action' => 'error' 0169 ))); 0170 0171 $request = new Zend_Controller_Request_Simple($action, $controller, $module, $passParam); 0172 0173 $front->setRequest($request) 0174 ->setResponse(new Zend_Controller_Response_Cli()) 0175 ->setRouter(new Local_Controller_Router_Cli()); 0176 0177 0178 $application->run(); 0179 0180 0181 $endTime = microtime(true); 0182 $endMemory = memory_get_usage(); 0183 $runAtDate = new DateTime(); 0184 0185 echo 'Run At: ' . $runAtDate->format(DateTime::ISO8601) . ' Time [' . ($endTime - $time) . 's] Memory [' 0186 . number_format(($endMemory - $memory) / 1024) . 'Kb]' . PHP_EOL; 0187 }