diff --git a/system/src/Grav/Common/GPM/Remote/Grav.php b/system/src/Grav/Common/GPM/Remote/Grav.php
index c83611dbc..8e6510060 100644
--- a/system/src/Grav/Common/GPM/Remote/Grav.php
+++ b/system/src/Grav/Common/GPM/Remote/Grav.php
@@ -9,6 +9,10 @@ class Grav extends Collection
private $version;
private $date;
+ /**
+ * @param bool $refresh
+ * @param null $callback
+ */
public function __construct($refresh = false, $callback = null)
{
parent::__construct($this->repository);
@@ -19,9 +23,7 @@ public function __construct($refresh = false, $callback = null)
$this->version = @$this->data->version ?: '-';
$this->date = @$this->data->date ?: '-';
- $this->data = $this->data->assets;
-
- foreach ($this->data as $slug => $data) {
+ foreach ($this->data->assets as $slug => $data) {
$this->items[$slug] = new Package($data);
}
}
@@ -32,7 +34,31 @@ public function __construct($refresh = false, $callback = null)
*/
public function getAssets()
{
- return $this->data;
+ return $this->data->assets;
+ }
+
+ /**
+ * Returns the changelog list for each version of Grav
+ * @param string $diff the version number to start the diff from
+ *
+ * @return array changelog list for each version
+ */
+ public function getChangelog($diff = null)
+ {
+ if (!$diff) {
+ return $this->data->changelog;
+ }
+
+ $diffLog = [];
+ foreach ($this->data->changelog as $version => $changelog) {
+ preg_match("/[\d\.]+/", $version, $cleanVersion);
+
+ if (!$cleanVersion || version_compare($diff, $cleanVersion[0], ">=")) { continue; }
+
+ $diffLog[$version] = $changelog;
+ }
+
+ return $diffLog;
}
/**
diff --git a/system/src/Grav/Common/GPM/Upgrader.php b/system/src/Grav/Common/GPM/Upgrader.php
index 312e77bb2..7d1adeffc 100644
--- a/system/src/Grav/Common/GPM/Upgrader.php
+++ b/system/src/Grav/Common/GPM/Upgrader.php
@@ -64,6 +64,17 @@ public function getAssets()
return $this->remote->getAssets();
}
+ /**
+ * Returns the changelog list for each version of Grav
+ * @param string $diff the version number to start the diff from
+ *
+ * @return array return the chagenlog list for each version
+ */
+ public function getChangelog($diff = null)
+ {
+ return $this->remote->getChangelog($diff);
+ }
+
/**
* Checks if the currently installed Grav is upgradable to a newer version
* @return boolean True if it's upgradable, False otherwise.
diff --git a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
index 7528666e1..4a03e6cc1 100644
--- a/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
+++ b/system/src/Grav/Console/Gpm/SelfupgradeCommand.php
@@ -10,6 +10,7 @@
use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
+use Symfony\Component\Console\Question\ConfirmationQuestion;
class SelfupgradeCommand extends Command
{
@@ -32,6 +33,12 @@ protected function configure()
InputOption::VALUE_NONE,
'Force re-fetching the data from remote'
)
+ ->addOption(
+ 'all-yes',
+ 'y',
+ InputOption::VALUE_NONE,
+ 'Assumes yes (or best approach) instead of prompting'
+ )
->setDescription("Detects and performs an update of plugins and themes when available")
->setHelp('The update command updates plugins and themes when a new version is available');
}
@@ -51,7 +58,49 @@ protected function execute(InputInterface $input, OutputInterface $output)
exit;
}
- $this->output->writeln("Preparing to upgrade Grav to v" . $remote . " [release date: " . $release . "]");
+ $questionHelper = $this->getHelper('question');
+ $skipPrompt = $this->input->getOption('all-yes');
+
+ $this->output->writeln("Grav v$remote is now available [release date: $release].");
+ $this->output->writeln("You are currently using v".GRAV_VERSION.".");
+
+ if (!$skipPrompt) {
+ $question = new ConfirmationQuestion("Would you like to upgrade now? [y|N] ", false);
+ $answer = $questionHelper->ask($this->input, $this->output, $question);
+
+ if (!$answer) {
+ $this->output->writeln("Aborting...");
+
+ exit;
+ }
+
+ $question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ", false);
+ $answer = $questionHelper->ask($this->input, $this->output, $question);
+
+ if ($answer) {
+ $changelog = $this->upgrader->getChangelog(GRAV_VERSION);
+
+ $this->output->writeln("");
+ foreach ($changelog as $version => $log) {
+ $title = $version . ' [' . $log->date . ']';
+ $content = preg_replace_callback("/\d\.\s\[\]\(#(.*)\)/", function($match){
+ return "\n".ucfirst($match[1]).":";
+ }, $log->content);
+
+ $this->output->writeln($title);
+ $this->output->writeln(str_repeat('-', strlen($title)));
+ $this->output->writeln($content);
+ $this->output->writeln("");
+ }
+
+ $question = new ConfirmationQuestion("Press [ENTER] to continue.", true);
+ $questionHelper->ask($this->input, $this->output, $question);
+ }
+
+ }
+
+ $this->output->writeln("");
+ $this->output->writeln("Preparing to upgrade to v$remote..");
$this->output->write(" |- Downloading upgrade [" . $this->formatBytes($update->size) . "]... 0%");
$this->file = $this->download($update);