/** * 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 testPushNotExists() { $file = '123-123-123'; $path = sprintf('%s/%s.zip', $this->name, $file); $this->localFilesystem->readStream($path)->willReturn(false); $this->remoteFilesystem->putStream($path, Argument::any())->shouldNotBeCalled(); $this->storage->push($file); }
public function testBackupCancelOnBackupGoOn() { $nanbando = $this->getNanbando(['uploads' => ['plugin' => 'directory', 'parameter' => ['directory' => 'uploads']]]); $filesystem = new Filesystem(new MemoryAdapter()); $this->storage->start()->willReturn($filesystem); $this->storage->close($filesystem)->shouldBeCalled(); $this->eventDispatcher->dispatch(Events::PRE_BACKUP_EVENT, Argument::type(PreBackupEvent::class))->shouldBeCalled(); $this->eventDispatcher->dispatch(Events::BACKUP_EVENT, Argument::type(BackupEvent::class))->will(function ($arguments) { $arguments[1]->setStatus(BackupStatus::STATE_FAILED); }); $this->eventDispatcher->dispatch(Events::POST_BACKUP_EVENT, Argument::type(PostBackupEvent::class))->shouldBeCalled(); $this->assertEquals(BackupStatus::STATE_PARTIALLY, $nanbando->backup()); $files = $filesystem->listContents('', true); $fileNames = array_map(function ($item) { return $item['path']; }, $files); $this->assertEquals(['database', 'database/backup', 'database/backup/uploads.json', 'database/system.json'], $fileNames); }