Skip to content

Commit

Permalink
Copy over the path processing from AMA.
Browse files Browse the repository at this point in the history
  • Loading branch information
wimleers committed Jun 16, 2023
1 parent c656169 commit d8034fe
Showing 1 changed file with 26 additions and 3 deletions.
29 changes: 26 additions & 3 deletions src/Command/App/NewFromDrupal7Command.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,7 +53,7 @@ protected function configure(): void {
$this->setDescription('Generate a new Drupal 9+ project from a Drupal 7 application using the default Acquia Migrate Accelerate recommendations.')
->addOption('drupal7-directory', 'source', InputOption::VALUE_OPTIONAL, 'The root of the Drupal 7 application.')
->addOption('drupal7-uri', 'uri', InputOption::VALUE_OPTIONAL, 'Only necessary in case of a multisite. If a single site, this will be computed automatically.')
->addOption('recommendations', 'recommendations', InputOption::VALUE_OPTIONAL, 'Currently still optional, will become required.')
->addOption('recommendations', 'recommendations', InputOption::VALUE_OPTIONAL, 'Overrides the default recommendations.')
->addOption('directory', 'destination', InputOption::VALUE_OPTIONAL, 'The directory where to generate the new application.')
->setAliases([
// Currently only "from Drupal 7", more to potentially follow.
Expand Down Expand Up @@ -185,6 +185,23 @@ private function getInspector(InputInterface $input): SiteInspectorInterface {
return new Drupal7SiteInspector($d7_root, $uri);
}

private function getLocation(string $location, bool $should_exist = TRUE): string {
if (strpos($location, '://') === FALSE) {
$file_exists = file_exists($location);
if ($file_exists && !$should_exist) {
throw new ValidatorException(sprintf('The %s directory already exists.', $location));
}
elseif (!$file_exists && $should_exist) {
throw new ValidatorException(sprintf('%s could not be located. Check that the path is correct and try again.', $location));
}
if (strpos($location, '.') === 0 || strpos($location, '/') !== 0) {
$absolute = getcwd() . '/' . $location;
$location = $should_exist ? realpath($absolute) : $absolute;
}
}
return $location;
}

protected function execute(InputInterface $input, OutputInterface $output): int {
try {
$inspector = $this->getInspector($input);
Expand Down Expand Up @@ -215,9 +232,15 @@ protected function execute(InputInterface $input, OutputInterface $output): int

// Parse recommendations for project builder.
$recommendations_location = __DIR__ . '/../../../config/from_d7_recommendations.json';
// @todo Make this a required option.
if ($input->getOption('recommendations') !== NULL) {
$recommendations_location = $input->getOption('recommendations');
$raw_recommendations_location = $input->getOption('recommendations');
try {
$recommendations_location = $this->getLocation($raw_recommendations_location);
}
catch (\InvalidArgumentException $e) {
$this->io->error($e->getMessage());
return Command::FAILURE;
}
}
$recommendations_resource = fopen($recommendations_location, 'r');
$recommendations = Recommendations::createFromResource($recommendations_resource);
Expand Down

0 comments on commit d8034fe

Please sign in to comment.