mirror of
https://github.com/getgrav/grav.git
synced 2026-05-06 09:57:49 +02:00
Add overwrite option for update
This commit is contained in:
@@ -47,6 +47,10 @@ class UpdateCommand extends ConsoleCommand
|
||||
*/
|
||||
protected $gpm;
|
||||
|
||||
protected $all_yes;
|
||||
|
||||
protected $overwrite;
|
||||
|
||||
/**
|
||||
*
|
||||
*/
|
||||
@@ -73,6 +77,12 @@ class UpdateCommand extends ConsoleCommand
|
||||
InputOption::VALUE_NONE,
|
||||
'Assumes yes (or best approach) instead of prompting'
|
||||
)
|
||||
->addOption(
|
||||
'overwrite',
|
||||
'o',
|
||||
InputOption::VALUE_NONE,
|
||||
'Option to overwrite packages if they already exist'
|
||||
)
|
||||
->addOption(
|
||||
'plugins',
|
||||
'p',
|
||||
@@ -101,31 +111,40 @@ class UpdateCommand extends ConsoleCommand
|
||||
{
|
||||
$this->gpm = new GPM($this->input->getOption('force'));
|
||||
|
||||
$this->all_yes = $this->input->getOption('all-yes');
|
||||
$this->overwrite = $this->input->getOption('overwrite');
|
||||
|
||||
$this->displayGPMRelease();
|
||||
|
||||
$this->destination = realpath($this->input->getOption('destination'));
|
||||
$skip_prompt = $this->input->getOption('all-yes');
|
||||
|
||||
if (!Installer::isGravInstance($this->destination)) {
|
||||
$this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
|
||||
exit;
|
||||
}
|
||||
if ($this->input->getOption('plugins') === false and $this->input->getOption('themes') === false) {
|
||||
$list_type_update = ['plugins' => true, 'themes' => true];
|
||||
$list_type = ['plugins' => true, 'themes' => true];
|
||||
} else {
|
||||
$list_type_update['plugins'] = $this->input->getOption('plugins');
|
||||
$list_type_update['themes'] = $this->input->getOption('themes');
|
||||
$list_type['plugins'] = $this->input->getOption('plugins');
|
||||
$list_type['themes'] = $this->input->getOption('themes');
|
||||
}
|
||||
|
||||
if ($this->overwrite) {
|
||||
$this->data = $this->gpm->getInstallable($list_type);
|
||||
$description = " can be overwritten";
|
||||
} else {
|
||||
$this->data = $this->gpm->getUpdatable($list_type);
|
||||
$description = " need updating";
|
||||
}
|
||||
|
||||
$this->data = $this->gpm->getUpdatable($list_type_update);
|
||||
$only_packages = array_map('strtolower', $this->input->getArgument('package'));
|
||||
|
||||
if (!$this->data['total']) {
|
||||
if (!$this->overwrite && !$this->data['total']) {
|
||||
$this->output->writeln("Nothing to update.");
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->write("Found <green>" . $this->gpm->countInstalled() . "</green> extensions installed of which <magenta>" . $this->data['total'] . "</magenta> need updating");
|
||||
$this->output->write("Found <green>" . $this->gpm->countInstalled() . "</green> packages installed of which <magenta>" . $this->data['total'] . "</magenta>" . $description);
|
||||
|
||||
$limit_to = $this->userInputPackages($only_packages);
|
||||
|
||||
@@ -145,19 +164,23 @@ class UpdateCommand extends ConsoleCommand
|
||||
continue;
|
||||
}
|
||||
|
||||
if (!$package->available) {
|
||||
$package->available = $package->version;
|
||||
}
|
||||
|
||||
$this->output->writeln(
|
||||
// index
|
||||
str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " .
|
||||
// name
|
||||
"<cyan>" . str_pad($package->name, 15) . "</cyan> " .
|
||||
// version
|
||||
"[v<magenta>" . $package->version . "</magenta> ➜ v<green>" . $package->available . "</green>]"
|
||||
"[v<magenta>" . $package->version . "</magenta> -> v<green>" . $package->available . "</green>]"
|
||||
);
|
||||
$slugs[] = $slug;
|
||||
}
|
||||
}
|
||||
|
||||
if (!$skip_prompt) {
|
||||
if (!$this->all_yes) {
|
||||
// prompt to continue
|
||||
$this->output->writeln("");
|
||||
$questionHelper = $this->getHelper('question');
|
||||
@@ -165,7 +188,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
$answer = $questionHelper->ask($this->input, $this->output, $question);
|
||||
|
||||
if (!$answer) {
|
||||
$this->output->writeln("Update aborted. Exiting...");
|
||||
$this->output->writeln("<red>Update aborted. Exiting...</red>");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -183,7 +206,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
$command_exec = $install_command->run($args, $this->output);
|
||||
|
||||
if ($command_exec != 0) {
|
||||
$this->output->writeln("<red>Error:</red> An error occurred while trying to install the extensions");
|
||||
$this->output->writeln("<red>Error:</red> An error occurred while trying to install the packages");
|
||||
exit;
|
||||
}
|
||||
}
|
||||
@@ -204,7 +227,7 @@ class UpdateCommand extends ConsoleCommand
|
||||
foreach ($only_packages as $only_package) {
|
||||
$find = $this->gpm->findPackage($only_package);
|
||||
|
||||
if (!$find || !$this->gpm->isUpdatable($find->slug)) {
|
||||
if (!$find || (!$this->overwrite && !$this->gpm->isUpdatable($find->slug))) {
|
||||
$name = isset($find->slug) ? $find->slug : $only_package;
|
||||
$ignore[$name] = $name;
|
||||
} else {
|
||||
|
||||
Reference in New Issue
Block a user