Ejemplo n.º 1
0
 /**
  * {@inheritdoc}
  */
 public function execute(ProfileInterface $profile)
 {
     if (empty($this->eventDispatcher) || empty($this->logger)) {
         throw new \LogicException('Workflow can not be executed without provided Logger and EventDispatcher.');
     }
     $backup = new Backup($profile->getName());
     $this->logger->info(sprintf('About to execute backup for profile: "%s".', $profile->getName()));
     $this->eventDispatcher->dispatch(BackupEvents::BEGIN, new BackupEvent($this, $profile, $backup));
     $terminate = function () use($profile) {
         try {
             $this->eventDispatcher->dispatch(BackupEvents::TERMINATE, new BackupEvent($profile));
             $this->logger->info(sprintf('Backup for profile "%s" successfully terminated.', $profile->getName()));
         } catch (\Exception $e) {
             $this->logger->alert(sprintf('Could not terminate backup process for profile "%s".', $profile->getName()));
         }
     };
     \Closure::bind($terminate, $this);
     try {
         /**
          * @var WorkflowActivityInterface $activity
          */
         foreach ($this->activities as $activity) {
             $this->executeActivity($activity, $profile, $backup);
         }
         $terminate();
     } catch (EmptySourceException $e) {
         $this->logger->info(sprintf('Backup for profile "%s" didn\'t yield any file for backup.', $profile->getName()));
         $terminate();
     } catch (\Exception $e) {
         $this->eventDispatcher->dispatch(BackupEvents::ERROR, new BackupEvent($this, $profile));
         $this->logger->critical(sprintf('There has been an error while executing backup profile "%s".', $profile->getName()), array('message' => $e->getMessage(), 'code' => $e->getCode(), 'file' => $e->getFile(), 'line' => $e->getLine(), 'trace' => $e->getTrace()));
         $terminate();
     }
 }
Ejemplo n.º 2
0
 /**
  * {@inheritdoc}
  */
 public function add(ProfileInterface $profile)
 {
     $this->profiles[$profile->getName()] = $profile;
     return $this;
 }