/** * Create a tar or zip I/O driver * * @param string $filename Path to database file * @param ArchiveType $archive_type Tar or zip archive * @param Compression $compression Compression not supported by zip archives */ public function __construct($filename, ArchiveType $archive_type, Compression $compression = null) { $this->filename = $filename; $this->archive = new \PharData($filename, null, null, $archive_type->value()); $this->compression = $compression ?: Compression::NONE(); if ($archive_type == ArchiveType::ZIP() && $this->compression != Compression::NONE()) { throw new NotSupportedException("You cannot use compression with zip databases"); } }
/** * @param InputInterface $input * @param OutputInterface $output * @param bool $export * @return void */ protected function port(InputInterface $input, OutputInterface $output, $export = true) { $entities = $this->getEntities($input->getOption('list')); $em = $this->getContainer()->get('orm.em'); $porter = new Porter(new OutputLogger($output)); $porter->registerManager('PRIMARY', $em); $io = new PharIoDriver($input->getOption($export ? 'output' : 'input'), ArchiveType::memberByKey(strtoupper($input->getOption('format')))); $driver = new FilesystemDriver($io); $aux = EntityManager::build($driver, $em->getMapper(), $em->getSerialiserMap()); $porter->registerManager('AUX', $aux); $batch_size = max(1, min(1000, (int) $input->getOption('batch'))); $term = $export ? 'Exporting' : 'Importing'; foreach ($entities as $class_name) { $output->writeln($term . " <info>" . $class_name . "</info>.."); try { if ($export) { $porter->portTable($class_name, 'PRIMARY', 'AUX', $batch_size); } else { $porter->portTable($class_name, 'AUX', 'PRIMARY', $batch_size); } } catch (\Exception $e) { $output->writeln("<error>ERROR:</error> " . $e->getMessage()); } } if ($export) { $output->writeln("<comment>EXPORT COMPLETE</comment>"); } else { $output->writeln("<comment>IMPORT COMPLETE</comment>"); } }
protected function getZipDriver() { $fn = sys_get_temp_dir() . '/bravo3-orm/zip.db'; if (file_exists($fn)) { unlink($fn); } return new FilesystemDriver(new PharIoDriver($fn, ArchiveType::ZIP())); }