/** * @see \Bolt\Storage\Migration\Input\InputFileInterface::readFile() */ public function readFile() { $filename = (string) $this->file; if ($this->file->isReadable()) { try { $data = $this->parser->parse(file_get_contents($filename) . "\n"); $this->import->setData($data); return true; } catch (ParseException $e) { $this->import->setError(true)->setErrorMessage("File '{$filename}' has invalid YAML!"); return false; } } else { $this->import->setError(true)->setErrorMessage("File '{$filename}' not readable!"); return false; } }
/** * @see \Bolt\Storage\Migration\Input\InputFileInterface::readFile() */ public function readFile() { $filename = (string) $this->file; if ($this->file->isReadable()) { try { $data = $this->parser->parse(file_get_contents($filename)); $this->import->setData($data); return true; } catch (ParsingException $e) { $this->import->setError(true)->setErrorMessage("File '{$filename}' has invalid JSON!"); $details = $e->getDetails(); foreach ($details as $detail) { $this->import->setErrorMessage($detail); } return false; } } else { $this->import->setError(true)->setErrorMessage("File '{$filename}' not readable!"); return false; } }
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 $files = $input->getOption('file'); if (empty($files)) { 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 Import migration object $import = new Import($this->app); $import->setMigrationFiles($files)->checkMigrationFilesValid(true)->checkMigrationFilesExist('import')->importMigrationFiles(); if ($import->getError()) { foreach ($import->getErrorMessages() as $error) { $output->writeln("<error>{$error}</error>"); } $output->writeln("\n<error>Aborting import!</error>\n"); return; } if ($import->getWarning()) { foreach ($import->getWarningMessages() as $warning) { $output->writeln("<comment>{$warning}</comment>"); } return; } if ($import->getNotice()) { foreach ($import->getNoticeMessages() as $notice) { $output->writeln("<info>{$notice}</info>"); } return; } // Report finish $filenames = join(', ', $files); $output->writeln("\n<info>Records imported from {$filenames}</info>"); }