/** * Initializes the available CRON configurations and returns them. * * @return array The array with the available CRON configurations */ public function findAll() { try { // initialize the array with the CRON instances $cronInstances = array(); // load the service necessary to validate CRON configuration files /** @var \AppserverIo\Appserver\Core\Api\ConfigurationService $configurationService */ $configurationService = $this->newService('AppserverIo\\Appserver\\Core\\Api\\ConfigurationService'); // load the base CRON configuration file $baseCronPath = $this->getConfdDir('cron.xml'); // we will need to test our CRON configuration files $configurationService->validateFile($baseCronPath, null); // validate the base CRON file and load it as default if validation succeeds $cronInstance = new CronNode(); $cronInstance->initFromFile($baseCronPath); // iterate over all jobs to configure the directory where they has to be executed /** @var \AppserverIo\Appserver\Core\Api\Node\JobNodeInterface $jobNode */ foreach ($cronInstance->getJobs() as $job) { // load the execution information $execute = $job->getExecute(); // query whether or not a base directory has been specified if ($execute && $execute->getDirectory() == null) { // set the directory where the cron.xml file located as base directory, if not $execute->setDirectory(dirname($baseCronPath)); } } // add the default CRON configuration $cronInstances[] = $cronInstance; // iterate over the configured containers /** @var \AppserverIo\Appserver\Core\Api\Node\ContainerNodeInterface $containerNode */ foreach ($this->getSystemConfiguration()->getContainers() as $containerNode) { // iterate over all applications and create the CRON configuration foreach (glob($this->getWebappsDir($containerNode) . '/*', GLOB_ONLYDIR) as $webappPath) { // iterate through all CRON configurations (cron.xml), validate and merge them foreach ($this->globDir(AppEnvironmentHelper::getEnvironmentAwareGlobPattern($webappPath, 'META-INF/cron')) as $cronFile) { try { // validate the file, but skip it if validation fails $configurationService->validateFile($cronFile, null); // load the system properties $properties = $this->getSystemProperties($containerNode); // append the application specific properties $properties->add(SystemPropertyKeys::WEBAPP, $webappPath); $properties->add(SystemPropertyKeys::WEBAPP_NAME, basename($webappPath)); // create a new CRON node instance and replace the properties $cronInstance = new CronNode(); $cronInstance->initFromFile($cronFile); $cronInstance->replaceProperties($properties); // append it to the other CRON configurations $cronInstances[] = $cronInstance; } catch (ConfigurationException $ce) { // load the logger and log the XML validation errors $systemLogger = $this->getInitialContext()->getSystemLogger(); $systemLogger->error($ce->__toString()); // additionally log a message that CRON configuration will be missing $systemLogger->critical(sprintf('Will skip app specific CRON configuration %s, configuration might be faulty.', $cronFile)); } } } } } catch (ConfigurationException $ce) { // load the logger and log the XML validation errors $systemLogger = $this->getInitialContext()->getSystemLogger(); $systemLogger->error($ce->__toString()); // additionally log a message that DS will be missing $systemLogger->critical(sprintf('Problems validating base CRON file %s, this might affect app configurations badly.', $baseCronPath)); } // return the array with the CRON instances return $cronInstances; }
/** * This method merges the passed CRON node with this one * * @param \AppserverIo\Appserver\Core\Api\Node\CronNodeInterface $cronNode The node to merge * * @return void */ public function merge(CronNode $cronNode) { $this->setJobs(array_merge($this->getJobs(), $cronNode->getJobs())); }