Author: Gawain Lynch (gawain.lynch@gmail.com)
Inheritance: extends Bolt\Storage\Migration\AbstractMigration
Exemple #1
0
 protected function execute(InputInterface $input, OutputInterface $output)
 {
     // Warn that this is experimental
     $output->writeln("<error>\n\nWARNING THIS IS AN EXPERIMENTAL FEATURE\n</error>\n");
     // Check if export file can be created
     $file = $input->getOption('file');
     if (empty($file)) {
         throw new \RuntimeException('The --file option is required.');
     }
     // See if we're going to continue
     if ($this->checkContinue($input, $output) === false) {
         return;
     }
     // Get the Bolt Export migration object
     $export = new Export($this->app);
     // Check the file extension is valid and writeable
     $export->setMigrationFiles($file)->checkMigrationFilesValid(false)->checkMigrationFilesExist('export')->checkMigrationFilesWriteable()->checkContenttypeValid($input->getOption('contenttypes'))->exportContenttypesRecords();
     if ($export->getError()) {
         foreach ($export->getErrorMessages() as $error) {
             $output->writeln("<error>{$error}</error>");
         }
         $output->writeln("\n<error>Aborting export!</error>\n");
         return 1;
     }
     $output->writeln("<info>Database exported to {$file}</info>");
 }
Exemple #2
0
 /**
  * @see \Bolt\Storage\Migration\File\MigrationFileInterface::addRecord()
  */
 public function addRecord(array $data, $last)
 {
     // Generate the YAML string
     try {
         // Add the record as an indexed array of itself as we're writing @author gawain
         // recorc/row at a time and… YAML.
         $yaml = $this->dumper->dump([$data], 4);
     } catch (\Exception $e) {
         $this->export->setError(true)->setErrorMessage('Unable to generate valid YAML data!');
         return false;
     }
     $file = (string) $this->file;
     if (file_put_contents($file, $yaml, FILE_APPEND) === false) {
         $this->export->setError(true)->setErrorMessage("Unable to write YAML data to '{$file}'!");
         return false;
     }
     return true;
 }
Exemple #3
0
 /**
  * @see \Bolt\Storage\Migration\File\MigrationFileInterface::addRecord()
  */
 public function addRecord(array $data, $last)
 {
     if (!$this->open) {
         $this->openJsonArray();
     }
     // Generate the JSON string
     $json = json_encode($data, JSON_PRETTY_PRINT);
     if ($json === false) {
         $this->export->setError(true)->setErrorMessage('Unable to generate valid JSON data!');
         return false;
     } elseif (!$last) {
         $json .= ",\n";
     }
     $file = (string) $this->file;
     if (file_put_contents($file, $json, FILE_APPEND) === false) {
         $this->export->setError(true)->setErrorMessage("Unable to write JSON data to '{$file}'!");
         return false;
     }
     return true;
 }