mirror of
https://github.com/getgrav/grav.git
synced 2026-05-07 22:06:43 +02:00
Added getChangelog method with option to set a diff starting point version
Selfupgrade command is now going to prompt you before continuing upgrading and optionally can show the change log Added -y|--all-yes option in grav self upgrade command to skip any prompt and just upgrade
This commit is contained in:
@@ -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 @@ class Grav extends Collection
|
||||
$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 @@ class Grav extends Collection
|
||||
*/
|
||||
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;
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -64,6 +64,17 @@ class Upgrader
|
||||
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.
|
||||
|
||||
@@ -10,6 +10,7 @@ use Symfony\Component\Console\Command\Command;
|
||||
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 @@ class SelfupgradeCommand extends Command
|
||||
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 <info>update</info> command updates plugins and themes when a new version is available');
|
||||
}
|
||||
@@ -51,7 +58,49 @@ class SelfupgradeCommand extends Command
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->writeln("Preparing to upgrade Grav to v<cyan>" . $remote . "</cyan> [release date: " . $release . "]");
|
||||
$questionHelper = $this->getHelper('question');
|
||||
$skipPrompt = $this->input->getOption('all-yes');
|
||||
|
||||
$this->output->writeln("Grav v<cyan>$remote</cyan> is now available [release date: $release].");
|
||||
$this->output->writeln("You are currently using v<cyan>".GRAV_VERSION."</cyan>.");
|
||||
|
||||
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<cyan>$remote</cyan>..");
|
||||
|
||||
$this->output->write(" |- Downloading upgrade [" . $this->formatBytes($update->size) . "]... 0%");
|
||||
$this->file = $this->download($update);
|
||||
|
||||
Reference in New Issue
Block a user