Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
70 changes: 48 additions & 22 deletions .vortex/installer/src/Command/InstallCommand.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
namespace DrevOps\VortexInstaller\Command;

use DrevOps\VortexInstaller\Downloader\Downloader;
use DrevOps\VortexInstaller\Downloader\RepositoryDownloader;
use DrevOps\VortexInstaller\Prompts\Handlers\Starter;
use DrevOps\VortexInstaller\Prompts\PromptManager;
use DrevOps\VortexInstaller\Runner\CommandRunnerAwareInterface;
Expand Down Expand Up @@ -75,9 +76,14 @@ class InstallCommand extends Command implements CommandRunnerAwareInterface, Exe
protected PromptManager $promptManager;

/**
* The downloader.
* The repository downloader.
*/
protected ?Downloader $downloader = NULL;
protected ?RepositoryDownloader $repositoryDownloader = NULL;

/**
* The file downloader.
*/
protected ?Downloader $fileDownloader = NULL;

/**
* {@inheritdoc}
Expand Down Expand Up @@ -147,11 +153,11 @@ protected function execute(InputInterface $input, OutputInterface $output): int
Task::action(
label: 'Downloading Vortex',
action: function (): string {
$version = $this->getDownloader()->download($this->config->get(Config::REPO), $this->config->get(Config::REF), $this->config->get(Config::TMP));
$version = $this->getRepositoryDownloader()->download($this->config->get(Config::REPO), $this->config->get(Config::REF), $this->config->get(Config::TMP));
$this->config->set(Config::VERSION, $version);
return $version;
},
hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...Downloader::parseUri($this->config->get(Config::REPO))),
hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...RepositoryDownloader::parseUri($this->config->get(Config::REPO))),
success: fn(string $return): string => sprintf('Vortex downloaded (%s)', $return)
);
Comment on lines 153 to 162

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Fix download hint to show the actual configured reference

The download task hint currently derives its repo/ref using:

hint: fn(): string => sprintf(
  'Downloading from "%s" repository at commit "%s"',
  ...RepositoryDownloader::parseUri($this->config->get(Config::REPO)),
),

Config::REPO already stores the repo URL/path without the @ref part, and Config::REF stores the actual reference. Re‑parsing just the repo URL makes the hint always show HEAD as the ref, even when the user selected stable or a specific commit. This is misleading but does not affect the actual download, which correctly uses both config values.

You can simplify and make the hint accurate by using the stored config directly:

-        hint: fn(): string => sprintf('Downloading from "%s" repository at commit "%s"', ...RepositoryDownloader::parseUri($this->config->get(Config::REPO))),
+        hint: fn(): string => sprintf(
+          'Downloading from "%s" repository at commit "%s"',
+          $this->config->get(Config::REPO),
+          $this->config->get(Config::REF),
+        ),
🤖 Prompt for AI Agents
.vortex/installer/src/Command/InstallCommand.php around lines 153 to 162: the
task hint re-parses Config::REPO which omits the configured ref and thus always
shows HEAD; replace the hint so it uses the stored repo and the actual ref from
Config::REF (i.e., use $this->config->get(Config::REPO) for the repository and
$this->config->get(Config::REF) for the reference) so the message accurately
reflects the selected reference.


Expand Down Expand Up @@ -234,7 +240,6 @@ protected function execute(InputInterface $input, OutputInterface $output): int
protected function checkRequirements(): void {
$required_commands = [
'git',
'curl',
'tar',
'composer',
];
Expand Down Expand Up @@ -296,7 +301,7 @@ protected function resolveOptions(array $arguments, array $options): void {
Env::putFromDotenv($dest_env_file);
}

[$repo, $ref] = Downloader::parseUri($options[static::OPTION_URI] ?: 'https://github.com/drevops/vortex.git@stable');
[$repo, $ref] = RepositoryDownloader::parseUri($options[static::OPTION_URI] ?: 'https://github.com/drevops/vortex.git@stable');
$this->config->set(Config::REPO, $repo);
$this->config->set(Config::REF, $ref);

Expand Down Expand Up @@ -425,10 +430,8 @@ protected function prepareDemo(): array|string {
$messages[] = sprintf('Created data directory "%s".', $data_dir);
}

$command = sprintf('curl -s -L "%s" -o "%s/%s"', $url, $data_dir, $db_file);
if (passthru($command) === FALSE) {
throw new \RuntimeException(sprintf('Unable to download demo database from %s.', $url));
}
$destination = $data_dir . DIRECTORY_SEPARATOR . $db_file;
$this->getFileDownloader()->download($url, $destination);

$messages[] = sprintf('No database dump file was found in "%s" directory.', $data_dir);
$messages[] = sprintf('Downloaded demo database from %s.', $url);
Expand Down Expand Up @@ -506,10 +509,10 @@ protected function header(): void {
$content = '';

$ref = $this->config->get(Config::REF);
if ($ref == Downloader::REF_STABLE) {
if ($ref == RepositoryDownloader::REF_STABLE) {
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('stable') . ' version of Vortex into your project.' . PHP_EOL;
}
elseif ($ref == Downloader::REF_HEAD) {
elseif ($ref == RepositoryDownloader::REF_HEAD) {
$content .= 'This tool will guide you through installing the latest ' . Tui::underscore('development') . ' version of Vortex into your project.' . PHP_EOL;
}
else {
Expand Down Expand Up @@ -713,26 +716,49 @@ public function cleanup(): void {
}

/**
* Get the downloader.
* Get the repository downloader.
*
* Provides a default RepositoryDownloader instance or returns the injected
* one. This allows tests to inject mocks via setRepositoryDownloader().
*
* @return \DrevOps\VortexInstaller\Downloader\RepositoryDownloader
* The repository downloader.
*/
protected function getRepositoryDownloader(): RepositoryDownloader {
return $this->repositoryDownloader ??= new RepositoryDownloader();
}

/**
* Set the repository downloader.
*
* @param \DrevOps\VortexInstaller\Downloader\RepositoryDownloader $repositoryDownloader
* The repository downloader.
*/
public function setRepositoryDownloader(RepositoryDownloader $repositoryDownloader): void {
$this->repositoryDownloader = $repositoryDownloader;
}

/**
* Get the file downloader.
*
* Provides a default Downloader instance or returns the injected one.
* This allows tests to inject mocks via setDownloader().
* This allows tests to inject mocks via setFileDownloader().
*
* @return \DrevOps\VortexInstaller\Downloader\Downloader
* The downloader.
* The file downloader.
*/
protected function getDownloader(): Downloader {
return $this->downloader ??= new Downloader();
protected function getFileDownloader(): Downloader {
return $this->fileDownloader ??= new Downloader();
}

/**
* Set the downloader.
* Set the file downloader.
*
* @param \DrevOps\VortexInstaller\Downloader\Downloader $downloader
* The downloader.
* @param \DrevOps\VortexInstaller\Downloader\Downloader $fileDownloader
* The file downloader.
*/
public function setDownloader(Downloader $downloader): void {
$this->downloader = $downloader;
public function setFileDownloader(Downloader $fileDownloader): void {
$this->fileDownloader = $fileDownloader;
}

}
Loading