Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- <?php
- /**
- * CronController - The central cron controller. This cron controller needs
- * to be called every minute of every day. The cron controller itself will
- * handle various cron tasks within to determine how many times a certain call
- * needs to be executed. This way only one cronjob needs to be set in the
- * administration panel on the server, while the rest will be handled by the
- * application, and new cron jobs can be added to the application easily.
- *
- * THIS CONTROLLER NEEDS TO BE CALLED EVERY MINUTE OF EVERY DAY TO ENSURE THAT
- * IT WILL LOOP THROUGH ALL THE OTHER CRON CLASSES PROPERLY
- *
- * @author Stefan van Beusekom
- * @version 1.0
- */
- class CronController extends Zend_Controller_Action {
- // Layout has been disabled
- public function init() {
- $this->_helper->layout()->disableLayout();
- $this->_helper->viewRenderer->setNoRender(true);
- }
- public function calculateTimeout($timelimit) {
- set_time_limit($timelimit);
- }
- /**
- * Index of the cron controller, which it defaults to when no action is
- * given. The index of the cron controller loops through the cron classes
- * and calls the 'execute' method to perform the cron job.
- *
- * @author Stefan van Beusekom
- * @since 1.0
- */
- public function indexAction() {
- // Retrieve all of the cronjob classes
- $list = $this->getCronClassList();
- $objectList = array();
- foreach ($list as $className) {
- $cronObject = new $className;
- if ($cronObject::CRON_ACTIVE)
- array_push($objectList, $cronObject);
- }
- // Sort the object array based on the priority of the cronjobs
- usort($objectList, function($classA, $classB) {
- return strcmp($classA::CRON_PRIORITY, $classB::CRON_PRIORITY);
- });
- // Execute the objects, ordered by priority
- foreach ($objectList as $object) {
- $object->execute();
- }
- }
- /**
- * Get a list of all the cron classes currently in the cron folder, and put
- * them into a collective array.
- *
- * @author Stefan van Beusekom
- * @since 1.0
- * @return array Array of available cron classes
- */
- private function getCronClassList() {
- $config = new Zend_Config_Ini(APPLICATION_PATH . '/configs/application.ini', 'production');
- $classPref = $config->get('appnamespace') . "_Model_Cron_";
- $classPath = APPLICATION_PATH . "/models/Cron/";
- $classList = array();
- $dirHandle = opendir($classPath);
- while (false !== ($entry = readdir($dirHandle))) {
- $info = pathinfo($classPath . $entry);
- if (!is_dir($classPath . $entry) && strtolower($info['filename']) != "abstract") {
- $tempClassName = $classPref . $info['filename'];
- array_push($classList, $tempClassName);
- }
- }
- return $classList;
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment