mirror of
https://github.com/getgrav/grav.git
synced 2026-02-22 22:51:13 +01:00
Updated GPM to use the new repository logic
This commit is contained in:
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
namespace Grav\Common\GPM\Remote;
|
||||
|
||||
class Plugins extends Collection {
|
||||
class Plugins extends Collection
|
||||
{
|
||||
private $repository = 'http://getgrav.org/downloads/plugins.json';
|
||||
private $type = 'plugins';
|
||||
private $data;
|
||||
|
||||
public function __construct($refresh = false, $callback = null) {
|
||||
public function __construct($refresh = false, $callback = null)
|
||||
{
|
||||
parent::__construct($this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,19 +1,21 @@
|
||||
<?php
|
||||
namespace Grav\Common\GPM\Remote;
|
||||
|
||||
class Themes extends Collection {
|
||||
class Themes extends Collection
|
||||
{
|
||||
private $repository = 'http://getgrav.org/downloads/themes.json';
|
||||
private $type = 'themes';
|
||||
private $data;
|
||||
|
||||
public function __construct($refresh = false, $callback = null) {
|
||||
public function __construct($refresh = false, $callback = null)
|
||||
{
|
||||
parent::__construct($this->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);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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>info</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 <cyan>'" . $input->getArgument('package') . "'</cyan> under the '<green>" . ucfirst($foundPackage->package_type) . "</green>' section");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<cyan>" . $foundPackage->name . "</cyan>");
|
||||
$this->output->writeln("<cyan>" . $foundPackage->name . "</cyan> [" . $foundPackage->slug . "]");
|
||||
$this->output->writeln(str_repeat('-', strlen($foundPackage->name) + strlen($foundPackage->slug) + 3));
|
||||
$this->output->writeln("<white>" . strip_tags($foundPackage->description_plain) . "</white>");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<white>" . strip_tags($foundPackage->description) . "</white>");
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("<magenta>Author:</magenta> " . $foundPackage->author);
|
||||
$this->output->writeln("<magenta>Version:</magenta> " . $foundPackage->version);
|
||||
$this->output->writeln("<magenta>Path:</magenta> " . $foundPackage->install_path);
|
||||
$this->output->writeln("<magenta>URL:</magenta> " . $foundPackage->url);
|
||||
$this->output->writeln("<magenta>Download:</magenta> " . $foundPackage->download);
|
||||
$this->output->writeln("<green>".str_pad("Author", 12).":</green> " . $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("<green>".$name.":</green> " . $data);
|
||||
}
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("You can install this package by typing:");
|
||||
$this->output->writeln(" <green>" . $this->argv . " install</green> <cyan>" . $foundPackage->slug . "</cyan>");
|
||||
|
||||
@@ -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("<red>ERROR</red>: " . Installer::lastErrorMsg());
|
||||
$this->output->writeln(" <white>".$this->destination."</white>");
|
||||
$this->output->writeln('');
|
||||
|
||||
exit;
|
||||
}
|
||||
|
||||
@@ -104,6 +100,7 @@ class InstallCommand extends Command
|
||||
|
||||
if (!$checks) {
|
||||
$this->output->writeln(" '- <red>Installation failed or aborted.</red>");
|
||||
$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);
|
||||
|
||||
|
||||
@@ -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 <info>update</info> 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("<red>ERROR</red>: " . 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: <red>" . implode('</red>, <red>', $packages) . "</red>");
|
||||
}
|
||||
exit;
|
||||
}
|
||||
|
||||
$this->output->writeln("Found <green>" . $this->gpm->countInstalled() . "</green> extensions of which <magenta>" . $this->data['total'] . "</magenta> need updating\n");
|
||||
$this->output->write("Found <green>" . $this->gpm->countInstalled() . "</green> extensions installed of which <magenta>" . $this->data['total'] . "</magenta> need updating");
|
||||
|
||||
if (!$this->data['total']) {
|
||||
$this->output->writeln("Good job on keeping everything <cyan>up to date</cyan>.");
|
||||
$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
|
||||
"<cyan>" . str_pad($package->name, 15) . "</cyan> " .
|
||||
// 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 <magenta>".$found['total']."</magenta> will be updated");
|
||||
}
|
||||
|
||||
$this->output->writeln('');
|
||||
$this->output->writeln("Limiting updates for only <cyan>".implode('</cyan>, <cyan>', $list)."</cyan>");
|
||||
}
|
||||
|
||||
if (count($ignore)) {
|
||||
$this->output->writeln("Packages not found or not requiring updates: <red>".implode('</red>, <red>', $ignore)."</red>");
|
||||
}
|
||||
}
|
||||
|
||||
return $found;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user