/** * Bypasses failed backup in restore process. * * @param RestoreEvent $event */ public function onRestoreStarted(RestoreEvent $event) { $database = $event->getDatabase(); if ($database->getWithDefault('state', BackupStatus::STATE_SUCCESS) === BackupStatus::STATE_FAILED) { $this->output->writeln(' <info>Bypassed</info>'); $event->stopPropagation(); } }
/** * Executes restore for given event. * * @param RestoreEvent $event */ public function onRestore(RestoreEvent $event) { $plugin = $this->pluginRegistry->getPlugin($event->getOption('plugin')); $optionsResolver = new OptionsResolver(); $plugin->configureOptionsResolver($optionsResolver); $parameter = $optionsResolver->resolve($event->getOption('parameter')); try { $plugin->restore($event->getSource(), $event->getDestination(), $event->getDatabase(), $parameter); $event->setStatus(BackupStatus::STATE_SUCCESS); } catch (\Exception $exception) { $event->setStatus(BackupStatus::STATE_FAILED); $event->setException($exception); } }
public function testOnRestoreFail() { $exception = $this->prophesize(\Exception::class); $this->event->getOption('parameter')->willReturn(['directory' => '/test']); $this->event->getOption('plugin')->willReturn('test'); $this->event->setStatus(BackupStatus::STATE_FAILED)->shouldBeCalled(); $this->event->setException($exception->reveal())->shouldBeCalled(); $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()); $plugin = $this->prophesize(PluginInterface::class); $plugin->configureOptionsResolver(Argument::type(OptionsResolver::class))->will(function ($arguments) { /** @var OptionsResolver $optionResolver */ $optionsResolver = $arguments[0]; $optionsResolver->setRequired('directory'); }); $plugin->restore($source->reveal(), $destination->reveal(), $database->reveal(), ['directory' => '/test'])->shouldBeCalled()->willThrow($exception->reveal()); $this->pluginRegistry->getPlugin('test')->willReturn($plugin->reveal()); $this->listener->onRestore($this->event->reveal()); }
/** * Print info for restore-started to output. * * @param RestoreEvent $event */ public function onRestoreStarted(RestoreEvent $event) { $this->output->writeln('- ' . $event->getName() . ' (' . $event->getOption('plugin') . '):'); }