public function testRestore() { $path = Path::join([DATAFIXTURES_DIR, 'backups', '13-21-2016-05-29_success.zip']); $nanbando = $this->getNanbando(['uploads' => ['plugin' => 'directory', 'parameter' => ['directory' => 'uploads']]]); $filesystem = new Filesystem(new ZipArchiveAdapter($path)); $this->storage->open('13-21-45-2016-05-29')->willReturn($filesystem); $this->eventDispatcher->dispatch(Events::PRE_RESTORE_EVENT, Argument::type(PreRestoreEvent::class))->shouldBeCalled(); $this->eventDispatcher->dispatch(Events::RESTORE_EVENT, Argument::type(RestoreEvent::class))->shouldBeCalled(); $this->eventDispatcher->dispatch(Events::POST_RESTORE_EVENT, Argument::type(Event::class))->shouldBeCalled(); $nanbando->restore('13-21-45-2016-05-29'); }
/** * 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 testOpen() { $name = $this->testClose(); $path = Path::join([DATAFIXTURES_DIR, 'backups', '13-21-2016-05-29_success.zip']); $tempFile = tempnam('/tmp', 'nanbando'); $this->temporaryFileSystem->createTemporaryFile()->willReturn($tempFile); $this->localFilesystem->readStream(sprintf('%s/%s.zip', $this->name, $name))->willReturn(file_get_contents($path)); $filesystem = $this->storage->open($name); $this->assertInstanceOf(Filesystem::class, $filesystem); $this->assertInstanceOf(ReadonlyAdapter::class, $filesystem->getAdapter()); $this->assertInstanceOf(ZipArchiveAdapter::class, $filesystem->getAdapter()->getAdapter()); $this->assertEquals($tempFile, $filesystem->getAdapter()->getAdapter()->getArchive()->filename); }