diff --git a/system/src/Grav/Common/GPM/Remote/Plugins.php b/system/src/Grav/Common/GPM/Remote/Plugins.php
index 33e96e31c..fa71fbab6 100644
--- a/system/src/Grav/Common/GPM/Remote/Plugins.php
+++ b/system/src/Grav/Common/GPM/Remote/Plugins.php
@@ -1,19 +1,21 @@
repository);
$this->fetch($refresh, $callback);
- $this->data = json_decode($this->raw)->results->data;
+ $this->data = json_decode($this->raw);
- foreach ($this->data as $data) {
- $this->items[$data->slug] = new Package($data, $this->type);
+ foreach ($this->data as $slug => $data) {
+ $this->items[$slug] = new Package($data, $this->type);
}
}
}
diff --git a/system/src/Grav/Common/GPM/Remote/Themes.php b/system/src/Grav/Common/GPM/Remote/Themes.php
index 64ab61be9..fcb5a34c4 100644
--- a/system/src/Grav/Common/GPM/Remote/Themes.php
+++ b/system/src/Grav/Common/GPM/Remote/Themes.php
@@ -1,19 +1,21 @@
repository);
$this->fetch($refresh, $callback);
- $this->data = json_decode($this->raw)->results->data;
+ $this->data = json_decode($this->raw);
- foreach ($this->data as $data) {
- $this->items[$data->slug] = new Package($data, $this->type);
+ foreach ($this->data as $slug => $data) {
+ $this->items[$slug] = new Package($data, $this->type);
}
}
}
diff --git a/system/src/Grav/Console/Gpm/InfoCommand.php b/system/src/Grav/Console/Gpm/InfoCommand.php
index 4ebcdf0ee..775a222b7 100644
--- a/system/src/Grav/Console/Gpm/InfoCommand.php
+++ b/system/src/Grav/Console/Gpm/InfoCommand.php
@@ -9,32 +9,34 @@ use Symfony\Component\Console\Input\InputInterface;
use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
-class InfoCommand extends Command {
+class InfoCommand extends Command
+{
use ConsoleTrait;
protected $data;
protected $gpm;
- protected function configure() {
+ protected function configure()
+ {
$this
->setName("info")
->addOption(
- 'force',
- 'f',
- InputOption::VALUE_NONE,
- 'Force fetching the new data remotely'
- )
+ 'force',
+ 'f',
+ InputOption::VALUE_NONE,
+ 'Force fetching the new data remotely'
+ )
->addArgument(
- 'package',
- InputArgument::REQUIRED,
- 'The package of which more informations are desired. Use the "index" command for a list of packages'
-
- )
+ 'package',
+ InputArgument::REQUIRED,
+ 'The package of which more informations are desired. Use the "index" command for a list of packages'
+ )
->setDescription("Shows more informations about a package")
->setHelp('The info shows more informations about a package');
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
@@ -51,15 +53,31 @@ class InfoCommand extends Command {
$this->output->writeln("Found package '" . $input->getArgument('package') . "' under the '" . ucfirst($foundPackage->package_type) . "' section");
$this->output->writeln('');
- $this->output->writeln("" . $foundPackage->name . "");
+ $this->output->writeln("" . $foundPackage->name . " [" . $foundPackage->slug . "]");
+ $this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));
+ $this->output->writeln("" . strip_tags($foundPackage->description_plain) . "");
$this->output->writeln('');
- $this->output->writeln("" . strip_tags($foundPackage->description) . "");
- $this->output->writeln('');
- $this->output->writeln("Author: " . $foundPackage->author);
- $this->output->writeln("Version: " . $foundPackage->version);
- $this->output->writeln("Path: " . $foundPackage->install_path);
- $this->output->writeln("URL: " . $foundPackage->url);
- $this->output->writeln("Download: " . $foundPackage->download);
+ $this->output->writeln("".str_pad("Author", 12).": " . $foundPackage->author->name . ' <' . $foundPackage->author->email . '> <' . $foundPackage->author->url . '>');
+
+ foreach (array('version', 'keywords', 'date', 'homepage', 'demo', 'docs', 'guide', 'repository', 'bugs', 'zipball_url', 'license') as $info) {
+ if (isset($foundPackage->$info)) {
+ $name = ucfirst($info);
+ $data = $foundPackage->$info;
+
+ if ($info == 'zipball_url') {
+ $name = "Download";
+ }
+
+ if ($info == 'date') {
+ $name = "Last Update";
+ $data = date('D, j M Y, H:i:s, P ', strtotime('2014-09-16T00:07:16Z'));
+ }
+
+ $name = str_pad($name, 12);
+ $this->output->writeln("".$name.": " . $data);
+ }
+ }
+
$this->output->writeln('');
$this->output->writeln("You can install this package by typing:");
$this->output->writeln(" " . $this->argv . " install " . $foundPackage->slug . "");
diff --git a/system/src/Grav/Console/Gpm/InstallCommand.php b/system/src/Grav/Console/Gpm/InstallCommand.php
index f6c861ff5..0447128a9 100644
--- a/system/src/Grav/Console/Gpm/InstallCommand.php
+++ b/system/src/Grav/Console/Gpm/InstallCommand.php
@@ -69,11 +69,7 @@ class InstallCommand extends Command
!Installer::isGravInstance($this->destination) ||
!Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK])
) {
- $this->output->writeln('');
$this->output->writeln("ERROR: " . Installer::lastErrorMsg());
- $this->output->writeln(" ".$this->destination."");
- $this->output->writeln('');
-
exit;
}
@@ -104,6 +100,7 @@ class InstallCommand extends Command
if (!$checks) {
$this->output->writeln(" '- Installation failed or aborted.");
+ $this->output->writeln('');
} else {
$this->output->write(" |- Installing package... ");
$installation = $this->installPackage($package);
@@ -116,18 +113,14 @@ class InstallCommand extends Command
}
}
}
-
- $this->output->writeln('');
}
-
- $this->output->writeln('');
}
private function downloadPackage($package)
{
$this->tmp = sys_get_temp_dir() . DS . 'Grav-' . uniqid();
- $filename = $package->slug . basename($package->download);
- $output = Response::get($package->download, [], [$this, 'progress']);
+ $filename = $package->slug . basename($package->zipball_url);
+ $output = Response::get($package->zipball_url, [], [$this, 'progress']);
Folder::mkdir($this->tmp);
diff --git a/system/src/Grav/Console/Gpm/UpdateCommand.php b/system/src/Grav/Console/Gpm/UpdateCommand.php
index 882f0e0b2..534ef647d 100644
--- a/system/src/Grav/Console/Gpm/UpdateCommand.php
+++ b/system/src/Grav/Console/Gpm/UpdateCommand.php
@@ -2,6 +2,7 @@
namespace Grav\Console\Gpm;
use Grav\Common\GPM\GPM;
+use Grav\Common\GPM\Installer;
use Grav\Console\ConsoleTrait;
use Symfony\Component\Console\Command\Command;
use Symfony\Component\Console\Input\ArrayInput;
@@ -11,7 +12,8 @@ use Symfony\Component\Console\Input\InputOption;
use Symfony\Component\Console\Output\OutputInterface;
use Symfony\Component\Console\Question\ConfirmationQuestion;
-class UpdateCommand extends Command {
+class UpdateCommand extends Command
+{
use ConsoleTrait;
protected $data;
@@ -21,70 +23,73 @@ class UpdateCommand extends Command {
protected $file;
protected $types = array('plugins', 'themes');
- protected function configure() {
+ protected function configure()
+ {
$this
->setName("update")
->addOption(
- 'force',
- 'f',
- InputOption::VALUE_NONE,
- 'Force re-fetching the data from remote'
- )
+ 'force',
+ 'f',
+ InputOption::VALUE_NONE,
+ 'Force re-fetching the data from remote'
+ )
->addOption(
- 'destination',
- 'd',
- InputOption::VALUE_OPTIONAL,
- 'The grav instance location where the updates should be applied to. By default this would be where the grav cli has been launched from',
- GRAV_ROOT
- )
+ 'destination',
+ 'd',
+ InputOption::VALUE_OPTIONAL,
+ 'The grav instance location where the updates should be applied to. By default this would be where the grav cli has been launched from',
+ GRAV_ROOT
+ )
->addArgument(
- 'package',
- InputArgument::IS_ARRAY|InputArgument::OPTIONAL,
- 'The package or packages that is desired to update. By default all available updates will be applied.'
- )
+ 'package',
+ InputArgument::IS_ARRAY|InputArgument::OPTIONAL,
+ 'The package or packages that is desired to update. By default all available updates will be applied.'
+ )
->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');
}
- protected function execute(InputInterface $input, OutputInterface $output) {
+ protected function execute(InputInterface $input, OutputInterface $output)
+ {
$this->setupConsole($input, $output);
$this->gpm = new GPM($this->input->getOption('force'));
$this->destination = realpath($this->input->getOption('destination'));
- $this->isGravInstance($this->destination);
+ if (!Installer::isGravInstance($this->destination)) {
+ $this->output->writeln("ERROR: " . Installer::lastErrorMsg());
+ exit;
+ }
- // fetch remote data and scan for local extensions
- $this->data = $this->gpm->getUpdatable();
+ $this->data = $this->gpm->getUpdatable();
+ $onlyPackages = array_map('strtolower', $this->input->getArgument('package'));
if (!$this->data['total']) {
- $packages = array_map('strtolower', $this->input->getArgument('package'));
$this->output->writeln("Nothing to update.");
- if (count($packages)) {
- $this->output->writeln("Packages not found: " . implode(', ', $packages) . "");
- }
exit;
}
- $this->output->writeln("Found " . $this->gpm->countInstalled() . " extensions of which " . $this->data['total'] . " need updating\n");
+ $this->output->write("Found " . $this->gpm->countInstalled() . " extensions installed of which " . $this->data['total'] . " need updating");
- if (!$this->data['total']) {
- $this->output->writeln("Good job on keeping everything up to date.");
- $this->output->writeln("Nothing else to do here!");
- exit;
- }
+ $this->userInputPackages($onlyPackages);
+
+ $this->output->writeln('');
unset($this->data['total']);
// updates review
$slugs = [];
- foreach ($this->data as $type => $packages) {
+ foreach ($this->data as $packages) {
$index = 0;
foreach ($packages as $slug => $package) {
+ /*if (!in_array($slug, $onlyPackages)) {
+ continue;
+ }*/
+
$this->output->writeln(
// index
- str_pad($index+++1, 2, '0', STR_PAD_LEFT) . ". " .
+ str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " .
// name
"" . str_pad($package->name, 15) . " " .
// version
@@ -107,13 +112,14 @@ class UpdateCommand extends Command {
// finally update
$installCommand = $this->getApplication()->find('install');
+
$args = new ArrayInput(array(
- 'command' => 'install',
- 'package' => $slugs,
- '-f' => $this->input->getOption('force'),
- '-d' => $this->destination,
- '-y' => true
- ));
+ 'command' => 'install',
+ 'package' => $slugs,
+ '-f' => $this->input->getOption('force'),
+ '-d' => $this->destination,
+ '-y' => true
+ ));
$commandExec = $installCommand->run($args, $this->output);
if ($commandExec != 0) {
@@ -122,4 +128,44 @@ class UpdateCommand extends Command {
}
}
+ private function userInputPackages($onlyPackages)
+ {
+ $found = ['total' => 0];
+ $ignore = [];
+
+ if (!count($onlyPackages)) {
+ $this->output->writeln('');
+ } else {
+ foreach ($onlyPackages as $onlyPackage) {
+ $find = $this->gpm->findPackage($onlyPackage);
+
+ if (!$find || !$this->gpm->isUpdatable($find->slug)) {
+ $name = isset($find->slug) ? $find->slug : $onlyPackage;
+ $ignore[$name] = $name;
+ } else {
+ $found[$find->slug] = $find;
+ $found['total']++;
+ }
+ }
+
+ if ($found['total']) {
+ $list = $found;
+ unset($list['total']);
+ $list = array_keys($list);
+
+ if ($found['total'] !== $this->data['total']) {
+ $this->output->write(", only ".$found['total']." will be updated");
+ }
+
+ $this->output->writeln('');
+ $this->output->writeln("Limiting updates for only ".implode(', ', $list)."");
+ }
+
+ if (count($ignore)) {
+ $this->output->writeln("Packages not found or not requiring updates: ".implode(', ', $ignore)."");
+ }
+ }
+
+ return $found;
+ }
}