コード例 #1
0
 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);
     $dbdsn = $databaseManager->getDatabase('propel')->getParameter('dsn');
     $dbusername = $databaseManager->getDatabase('propel')->getParameter('username');
     $dbpassword = $databaseManager->getDatabase('propel')->getParameter('password');
     $dbname = preg_replace('/^.*dbname=([^;=]+).*$/', '${1}', $dbdsn);
     ConfigurationHelper::load();
     $backup_method = ConfigurationHelper::getParameter('Backup', 'backup_method');
     $this->logSection('tempos', sprintf('Backup method: %s', $backup_method), 1024);
     if ($backup_method == 'ftp') {
         $backupname = 'tempos-backup.sql';
         $configname = ConfigurationHelper::getDefaultConfigurationFileName();
         $configpath = ConfigurationHelper::getDefaultConfigurationFilePath();
         copy($configpath, '/tmp/' . $configname);
         chdir('/tmp');
         system(sprintf('mysqldump --user=%s --password=%s %s > %s', escapeshellarg($dbusername), escapeshellarg($dbpassword), escapeshellarg($dbname), escapeshellarg($backupname)));
         $tmpfilename = 'tempos-backup-' . date('Y-m-d') . '.tar.gz';
         system(sprintf('tar zcf %s %s %s', escapeshellarg($tmpfilename), escapeshellarg($backupname), escapeshellarg($configname)));
         unlink($backupname);
         unlink($configname);
         try {
             FTPHelper::backupFile($tmpfilename);
         } catch (Exception $ex) {
             unlink($tmpfilename);
             throw $ex;
         }
         unlink($tmpfilename);
     }
 }
コード例 #2
0
 protected function execute($arguments = array(), $options = array())
 {
     $this->configuration = ProjectConfiguration::getApplicationConfiguration('frontend', 'prod', true);
     $this->context = sfContext::createInstance($this->configuration);
     ConfigurationHelper::load();
     if (ConfigurationHelper::getParameter('Network', '_need_update', false)) {
         $this->logSection('tempos', 'Update required.', 1024);
         if ($this->writeInterfaces()) {
             ConfigurationHelper::setParameter('Network', '_need_update', false);
             ConfigurationHelper::save();
         }
     } else {
         $this->logSection('tempos', 'No update required.', 1024);
     }
 }
コード例 #3
0
 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();
     $nb_controllers = ConfigurationHelper::get('number_of_physical_access');
     $reservations = ReservationPeer::doSelectPendingReservations($options['include-inactive'], $delayedTime);
     if (empty($reservations)) {
         $this->logSection('tempos', 'check - No reservations pending. Doing nothing.', 1024);
     } else {
         $this->logSection('tempos', sprintf('check - %d reservation(s) pending.', count($reservations)), 1024);
         $i = 0;
         foreach ($reservations as $reservation) {
             $roomprofile_id = $reservation->getRoomprofile()->getId();
             $roomprofile = RoomprofilePeer::doSelectFromId($roomprofile_id);
             $rp_controllername = $roomprofile->getConfiguredControllerName();
             $pac_infos = BasePhysicalAccessController::findPacFromNameIdentifier($rp_controllername);
             if (is_null($pac_infos) || empty($pac_infos)) {
                 $this->logSection('tempos', sprintf('check - Can\'t create a physical access controller for this reservation: id(%s)', $reservation->getId()), 1024);
                 continue;
             }
             $pac_name = $pac_infos['name'];
             // print 'pac_name: ';
             // var_dump($pac_name);
             $pac_id = $pac_infos['id'];
             // print 'pac_id: ';
             // var_dump($pac_id);
             $pac_selec = ConfigurationHelper::getParameter(null, $pac_name);
             // print 'pac_selec: ';
             // var_dump($pac_selec);
             $pac_conf = ConfigurationHelper::getNamespace($pac_selec . $pac_id);
             // print 'pac_conf: ';
             // var_dump($pac_conf);
             // var_dump($pac_infos);
             $pac = BasePhysicalAccessController::create($pac_selec, $pac_conf);
             // var_dump($pac);
             $delay = $pac->getParameter('delay');
             // print 'delay: ';
             // var_dump($delay);
             $pac->setVerbose($options['verbose']);
             $this->logSection('tempos', sprintf('check - Creating a physical access controller: %s', $pac->getName()), 1024);
             if (is_null($delay) || empty($delay)) {
                 $delay = 0;
             }
             $now = time();
             $delayedTime = time() + $delay * 60;
             // Need to add the delay in milliseconds to the time() function
             $this->logSection('tempos', sprintf('check - Checking reservations at: %s', strftime('%c', $now)), 1024);
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf('check - There is a starting delay ! Need to start reservation %s minutes before the reservation date !', $delay), 1024);
                 $this->logSection('tempos', sprintf('check - Finally looking reservations at: %s', strftime('%c', $delayedTime)), 1024);
             }
             if ($delay > 0) {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tBefore delay: %s", $i, $reservation->__toString()), 1024);
                 $reservation->updateDateWithDelay($delay);
                 $this->logSection('tempos', sprintf("check - \t(%d)\tAfter delay: %s", $i, $reservation->__toString()), 1024);
             } else {
                 $this->logSection('tempos', sprintf("check - \t(%d)\tReservation: %s", $i, $reservation->__toString()), 1024);
             }
             $results = $pac->sendReservation($reservation, $options['update-status']);
             if (empty($results)) {
                 $this->logSection('tempos', sprintf("check - \t\tSuccess."), 1024);
             } else {
                 foreach ($results as $result) {
                     $this->logSection('tempos', sprintf("check - \t\t%s: %s", $result['person'], $result['exception']->getMessage()), 1024, 'ERROR');
                 }
             }
             $i++;
         }
     }
 }
コード例 #4
0
 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']);
         }
     }
 }
コード例 #5
0
 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();
     $nb_controllers = ConfigurationHelper::get('number_of_physical_access');
     $now = time();
     $startCheckTime = $now + $delay * 60;
     // Need to add the delay in milliseconds to the time() function
     $stopCheckTime = $startCheckTime + $options['hours'] * 60 * 60;
     $this->logSection('tempos', sprintf("check-for-next-hours - Checking reservations started at: %s", strftime('%c', $now)), 1024);
     $this->logSection('tempos', sprintf("check-for-next-hours - Start delay (%s) minutes --> Start date reservation is: %s", $delay, strftime('%c', $startCheckTime)), 1024);
     $this->logSection('tempos', sprintf("check-for-next-hours - NB hours to check (%s) --> End date reservation check: %s", $options['hours'], strftime('%c', $stopCheckTime)), 1024);
     $reservations = ReservationPeer::doSelectPendingReservationsForNextHours($options['include-inactive'], $startCheckTime, $stopCheckTime);
     if (empty($reservations)) {
         $this->logSection('tempos', "check-for-next-hours - No reservations pending. Doing nothing.", 1024);
     } else {
         $this->logSection('tempos', sprintf("check-for-next-hours - %d reservation(s) pending.", count($reservations)), 1024);
         $uniquePersonsArray = array();
         $i = 0;
         foreach ($reservations as $reservation) {
             $roomprofile_id = $reservation->getRoomprofile()->getId();
             $roomprofile = RoomprofilePeer::doSelectFromId($roomprofile_id);
             $rp_controllername = $roomprofile->getConfiguredControllerName();
             $pac_infos = BasePhysicalAccessController::findPacFromNameIdentifier($rp_controllername);
             if (is_null($pac_infos) || empty($pac_infos)) {
                 continue;
             }
             $pac_name = $pac_infos['name'];
             // print 'pac_name';
             // var_dump($pac_name);
             $pac_id = $pac_infos['id'];
             // print 'pac_id';
             // var_dump($pac_id);
             $pac_selec = ConfigurationHelper::getParameter(null, $pac_name);
             // print 'pac_selec';
             // var_dump($pac_selec);
             $pac_conf = ConfigurationHelper::getNamespace($pac_selec . $pac_id);
             // print 'pac_conf';
             // var_dump($pac_conf);
             // var_dump($pac_infos);
             $pac = BasePhysicalAccessController::create($pac_selec, $pac_conf);
             // var_dump($pac);
             $delay = $pac->getParameter('delay');
             // print 'delay';
             // var_dump($delay);
             $pac->setVerbose($options['verbose']);
             if (is_null($delay) || empty($delay)) {
                 $delay = 0;
             }
             $this->logSection('tempos', sprintf('check - Creating a physical access controller: %s', $pac->getName()), 1024);
             $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tProcessing reservation: %s...", $i, $reservation->__toString()), 1024);
             $persons = $reservation->getAllPersons();
             $finalPersons = array();
             // Filter the list of persons. We only send the first reservation for each member.
             // If the user is already in the list, we remove him from the reservation.
             foreach ($persons as $person) {
                 $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tProcessing user (%s)...", $i, $person), 1024);
                 $uniqueId = $person->getUniqueId();
                 if (isset($uniquePersonsArray[$uniqueId])) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tUser (%s) had already a reservation... Ignoring him...", $i, $person->__toString()), 1024);
                 } else {
                     $uniquePersonsArray[$uniqueId] = 1;
                     $finalPersons[] = $person;
                 }
             }
             if (!empty($finalPersons)) {
                 if ($delay > 0) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tDelay required ! Before delay: %s", $i, $reservation->getDateString()), 1024);
                     $reservation->updateDateWithDelay($delay);
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t(%d)\tAfter delay: %s", $i, $reservation->getDateString()), 1024);
                 }
                 $results = $pac->sendReservation($reservation, $options['update-status'], $finalPersons);
                 if (empty($results)) {
                     $this->logSection('tempos', sprintf("check-for-next-hours - \t\tSuccess."), 1024);
                 } else {
                     foreach ($results as $result) {
                         $this->logSection('tempos', sprintf("check-for-next-hours - \t\t%s: %s", $result['person'], $result['exception']->getMessage()), 1024, 'ERROR');
                     }
                 }
             } else {
                 $this->logSection('tempos', sprintf("check-for-next-hours - \t\tNo more user in the reservation. Doing nothing."), 1024);
             }
             $i++;
         }
     }
 }