Esempio n. 1
0
 /**
  * Executes backup for given event.
  *
  * @param BackupEvent $event
  */
 public function onBackup(BackupEvent $event)
 {
     $plugin = $this->pluginRegistry->getPlugin($event->getOption('plugin'));
     $optionsResolver = new OptionsResolver();
     $plugin->configureOptionsResolver($optionsResolver);
     $parameter = $optionsResolver->resolve($event->getOption('parameter'));
     try {
         $plugin->backup($event->getSource(), $event->getDestination(), $event->getDatabase(), $parameter);
         $event->setStatus(BackupStatus::STATE_SUCCESS);
     } catch (\Exception $exception) {
         $event->setStatus(BackupStatus::STATE_FAILED);
         $event->setException($exception);
     }
 }
Esempio n. 2
0
 public function testOnBackupException()
 {
     $this->event->getOption('parameter')->willReturn(['directory' => '/test']);
     $this->event->getOption('plugin')->willReturn('test');
     $source = $this->prophesize(Filesystem::class);
     $destination = $this->prophesize(Filesystem::class);
     $database = $this->prophesize(Database::class);
     $this->event->getSource()->willReturn($source->reveal());
     $this->event->getDestination()->willReturn($destination->reveal());
     $this->event->getDatabase()->willReturn($database->reveal());
     $exception = $this->prophesize(\Exception::class);
     $this->event->setStatus(BackupStatus::STATE_FAILED)->shouldBeCalled();
     $this->event->setException($exception->reveal())->shouldBeCalled();
     $plugin = $this->prophesize(PluginInterface::class);
     $plugin->configureOptionsResolver(Argument::type(OptionsResolver::class))->will(function ($arguments) {
         /** @var OptionsResolver $optionResolver */
         $optionsResolver = $arguments[0];
         $optionsResolver->setRequired('directory');
     });
     $plugin->backup($source->reveal(), $destination->reveal(), $database->reveal(), ['directory' => '/test'])->shouldBeCalled()->willThrow($exception->reveal());
     $this->pluginRegistry->getPlugin('test')->willReturn($plugin->reveal());
     $this->listener->onBackup($this->event->reveal());
 }
Esempio n. 3
0
 /**
  * Print info for backup-started to output.
  *
  * @param BackupEvent $event
  */
 public function onBackupStarted(BackupEvent $event)
 {
     $this->output->writeln('- ' . $event->getName() . ' (' . $event->getOption('plugin') . '):');
 }