/** * Restore process. * * @param string $name */ public function restore($name) { $source = $this->storage->open($name); $destination = new Filesystem(new Local(realpath('.'), LOCK_EX, null)); $destination->addPlugin(new ListFiles()); $destination->addPlugin(new HashPlugin()); $systemData = json_decode($source->read('database/system.json'), true); $systemDatabase = $this->databaseFactory->createReadonly($systemData); $event = new PreRestoreEvent($this->backup, $systemDatabase, $source, $destination); $this->eventDispatcher->dispatch(Events::PRE_RESTORE_EVENT, $event); if ($event->isCanceled()) { return; } $backupConfig = $event->getBackup(); foreach ($backupConfig as $backupName => $backup) { $backupSource = new Filesystem(new PrefixAdapter('backup/' . $backupName, $source->getAdapter())); $backupSource->addPlugin(new ListFiles()); $backupSource->addPlugin(new HashPlugin()); $data = json_decode($source->read(sprintf('database/backup/%s.json', $backupName)), true); $database = $this->databaseFactory->createReadonly($data); $event = new RestoreEvent($systemDatabase, $database, $backupSource, $destination, $backupName, $backup); $this->eventDispatcher->dispatch(Events::RESTORE_EVENT, $event); } $this->eventDispatcher->dispatch(Events::POST_RESTORE_EVENT, new Event()); }
public function testCreateReadonlyWithData() { $factory = new DatabaseFactory(); $this->assertEquals(['test' => 1], $factory->createReadonly(['test' => 1])->getAll()); }
protected function getNanbando(array $backup) { return new Nanbando($backup, $this->storage->reveal(), $this->databaseFactory->reveal(), $this->eventDispatcher->reveal()); }