protected function execute($arguments = array(), $options = array()) { $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true); $this->context = sfContext::createInstance($this->configuration); $databaseManager = new sfDatabaseManager($this->configuration); ConfigurationHelper::load(); $now = time(); $this->logSection('tempos', sprintf('Checking energy actions at: %s.', strftime('%c', $now)), 1024); // Creates physical access controller /* $hac = BaseHomeAutomationController::create(); $hac->setVerbose($options['verbose']); $hac->setUpdateStatus($options['update-status']); $this->logSection('tempos', sprintf('Creating a home automation controller: %s', $hac->getName()), 1024); */ // Refresh statuses $actions = EnergyactionPeer::doSelect(new Criteria()); if (empty($actions)) { $this->logSection('tempos', sprintf('Refreshing statuses for all actions: no actions.'), 1024); } else { $this->logSection('tempos', sprintf('Refreshing statuses for all actions: %d action(s) to refresh.', count($actions)), 1024); foreach ($actions as $action) { $hac = self::findHac($action); if (is_null($hac)) { $this->logSection('tempos', sprintf('Can\'t create a home automation controller for this action: id(%s) HAC is null', $action->getId()), 1024); continue; } $hac->setVerbose($options['verbose']); $hac->setUpdateStatus($options['update-status']); $this->logSection('tempos', sprintf('Creating a home automation controller: %s for action: %s', $hac->getName(), $action->getId(), 1024)); $this->refreshAction($hac, $action); } } // Check out of period actions $actions = EnergyactionPeer::doSelectOutOfPeriod(true, $now); if (empty($actions)) { $this->logSection('tempos', sprintf('Checking out-of-period active actions: no action is out-of-period.'), 1024); } else { $this->logSection('tempos', sprintf('Checking out-of-period active actions: %d action(s) to shut down.', count($actions)), 1024); foreach ($actions as $action) { $hac = self::findHac($action); if (is_null($hac)) { $this->logSection('tempos', sprintf('Can\'t check out-of-period with this action: id(%s) HAC is null', $action->getId()), 1024); continue; } $this->updateAction($hac, $action, false, $options['force']); } } // Check the ready actions $actions = EnergyactionPeer::doSelectReady($now); if (empty($actions)) { $this->logSection('tempos', sprintf('Checking reservation ready actions: no action must be triggered.'), 1024); } else { $this->logSection('tempos', sprintf('Checking reservation ready actions: %d action(s) to power on.', count($actions)), 1024); foreach ($actions as $action) { $hac = self::findHac($action); if (is_null($hac)) { $this->logSection('tempos', sprintf('Can\'t update this action: id(%s) HAC is null', $action->getId()), 1024); continue; } $this->updateAction($hac, $action, true, $options['force']); } } // Check the over actions $actions = EnergyactionPeer::doSelectOver($now, $actions); if (empty($actions)) { $this->logSection('tempos', sprintf('Checking reservation over actions: no action must be triggered.'), 1024); } else { $this->logSection('tempos', sprintf('Checking reservation over actions: %d action(s) to shut down.', count($actions)), 1024); foreach ($actions as $action) { $hac = self::findHac($action); if (is_null($hac)) { $this->logSection('tempos', sprintf('Can\'t update this action: id(%s) HAC is null', $action->getId()), 1024); continue; } $this->updateAction($hac, $action, false, $options['force']); } } }