/**
  * Parse and execute the scheduled tasks in the specified file.
  * @param $file string
  */
 function parseTasks($file)
 {
     $xmlParser = new XMLParser();
     $tree = $xmlParser->parse($file);
     if (!$tree) {
         $xmlParser->destroy();
         printf("Unable to parse file \"%s\"!\n", $file);
         exit(1);
     }
     foreach ($tree->getChildren() as $task) {
         $className = $task->getAttribute('class');
         $frequency = $task->getChildByName('frequency');
         if (isset($frequency)) {
             $canExecute = ScheduledTaskHelper::checkFrequency($className, $frequency);
         } else {
             // Always execute if no frequency is specified
             $canExecute = true;
         }
         if ($canExecute) {
             $this->executeTask($className, ScheduledTaskHelper::getTaskArgs($task));
         }
     }
     $xmlParser->destroy();
 }
 /**
  * Parse all scheduled tasks files and
  * save the result object in database.
  */
 function _parseCrontab()
 {
     $xmlParser = new XMLParser();
     $taskFilesPath = array();
     // Load all plugins so any plugin can register a crontab.
     PluginRegistry::loadAllPlugins();
     // Let plugins register their scheduled tasks too.
     HookRegistry::call('AcronPlugin::parseCronTab', array(&$taskFilesPath));
     // Reference needed.
     // Add the default tasks file.
     $taskFilesPath[] = 'registry/scheduledTasks.xml';
     // TODO: make this a plugin setting, rather than assuming.
     $tasks = array();
     foreach ($taskFilesPath as $filePath) {
         $tree = $xmlParser->parse($filePath);
         if (!$tree) {
             $xmlParser->destroy();
             // TODO: graceful error handling
             fatalError('Error parsing scheduled tasks XML file: ' . $filePath);
         }
         foreach ($tree->getChildren() as $task) {
             $frequency = $task->getChildByName('frequency');
             $args = ScheduledTaskHelper::getTaskArgs($task);
             // Tasks without a frequency defined, or defined to zero, will run on every request.
             // To avoid that happening (may cause performance problems) we
             // setup a default period of time.
             $setDefaultFrequency = true;
             $minHoursRunPeriod = 24;
             if ($frequency) {
                 $frequencyAttributes = $frequency->getAttributes();
                 if (is_array($frequencyAttributes)) {
                     foreach ($frequencyAttributes as $key => $value) {
                         if ($value != 0) {
                             $setDefaultFrequency = false;
                             break;
                         }
                     }
                 }
             }
             $tasks[] = array('className' => $task->getAttribute('class'), 'frequency' => $setDefaultFrequency ? array('hour' => $minHoursRunPeriod) : $frequencyAttributes, 'args' => $args);
         }
         $xmlParser->destroy();
     }
     // Store the object.
     $this->updateSetting(0, 'crontab', $tasks, 'object');
 }