diff --git a/CHANGELOG.md b/CHANGELOG.md
index d2a27aca8..88377e193 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -4,6 +4,8 @@
1. [](#new)
* Auto-Escape enabled by default. Manually enable **Twig Compatibility** and disable **Auto-Escape** to use the old setting.
* Updated unit tests to use codeception 4.1
+1. [](#improved)
+ * Improved `bin/grav install` command
1. [](#bugfix)
* Fixed potential error when upgrading Grav
* Fixed broken list in `bin/gpm index` [#3092](https://github.com/getgrav/grav/issues/3092)
diff --git a/system/src/Grav/Console/Cli/InstallCommand.php b/system/src/Grav/Console/Cli/InstallCommand.php
index 01a98276b..5cc17e0f4 100644
--- a/system/src/Grav/Console/Cli/InstallCommand.php
+++ b/system/src/Grav/Console/Cli/InstallCommand.php
@@ -119,8 +119,8 @@ class InstallCommand extends ConsoleCommand
$this->output->writeln('');
$error = 0;
+ $this->destination = rtrim($this->destination, DS);
foreach ($this->config['git'] as $repo => $data) {
- $this->destination = rtrim($this->destination, DS);
$path = $this->destination . DS . $data['path'];
if (!file_exists($path)) {
exec('cd "' . $this->destination . '" && git clone -b ' . $data['branch'] . ' --depth 1 ' . $data['url'] . ' ' . $data['path'], $output, $return);
@@ -134,7 +134,7 @@ class InstallCommand extends ConsoleCommand
$this->output->writeln('');
} else {
- $this->output->writeln('' . $path . ' already exists, skipping...');
+ $this->output->writeln('' . $path . ' already exists, skipping...');
$this->output->writeln('');
}
}
@@ -162,30 +162,45 @@ class InstallCommand extends ConsoleCommand
}
$error = 0;
- exec('cd ' . $this->destination);
- foreach ($this->config['links'] as $repo => $data) {
- $repos = (array) $this->local_config[$data['scm'] . '_repos'];
- $from = false;
- $to = $this->destination . $data['path'];
+ $this->destination = rtrim($this->destination, DS);
+ foreach ($this->config['links'] as $name => $data) {
+ $scm = $data['scm'] ?? null;
+ $src = $data['src'] ?? null;
+ $path = $data['path'] ?? null;
+ if (!isset($scm, $src, $path)) {
+ $this->output->writeln("Dependency '$name' has broken configuration, skipping...");
+ $this->output->writeln('');
+ $error = 1;
- foreach ($repos as $repo) {
- $path = $repo . $data['src'];
- if (file_exists($path)) {
- $from = $path;
+ continue;
+ }
+
+ $locations = (array) $this->local_config["{$scm}_repos"];
+ $to = $this->destination . DS . $path;
+
+ $from = null;
+ foreach ($locations as $location) {
+ $test = rtrim($location, '\\/') . DS . $src;
+ if (file_exists($test)) {
+ $from = $test;
continue;
}
}
- if (!$from) {
- $this->output->writeln('source for ' . $data['src'] . ' does not exists, skipping...');
+ if (is_link($to) && !is_file("{$to}/{$name}.yaml")) {
+ $this->output->writeln('Removed broken symlink '. $path .'');
+ unlink($to);
+ }
+ if (null === $from) {
+ $this->output->writeln('source for ' . $src . ' does not exists, skipping...');
$this->output->writeln('');
$error = 1;
} elseif (!file_exists($to)) {
symlink($from, $to);
- $this->output->writeln('SUCCESS symlinked ' . $data['src'] . ' -> ' . $data['path'] . '');
+ $this->output->writeln('SUCCESS symlinked ' . $src . ' -> ' . $path . '');
$this->output->writeln('');
} else {
- $this->output->writeln('destination: ' . $to . ' already exists, skipping...');
+ $this->output->writeln('destination: ' . $path . ' already exists, skipping...');
$this->output->writeln('');
}
}