diff --git a/bin/gpm b/bin/gpm index 9eb5ceb28..0a9701780 100755 --- a/bin/gpm +++ b/bin/gpm @@ -29,7 +29,6 @@ $grav = Grav::instance(['loader' => $autoload]); $app = new Application('Grav Package Manager', '0.1.0'); $app->addCommands(array( - new \Grav\Console\Gpm\FetchCommand(), new \Grav\Console\Gpm\IndexCommand(), new \Grav\Console\Gpm\InfoCommand(), new \Grav\Console\Gpm\InstallCommand(), diff --git a/system/src/Grav/Console/Gpm/FetchCommand.php b/system/src/Grav/Console/Gpm/FetchCommand.php deleted file mode 100644 index 1743e685b..000000000 --- a/system/src/Grav/Console/Gpm/FetchCommand.php +++ /dev/null @@ -1,111 +0,0 @@ -setName("fetch") - ->addOption( - 'force', - 'f', - InputOption::VALUE_NONE, - 'Force fetching the new data remotely' - ) - ->setDescription("Fetches the data for plugins and themes available") - ->setHelp('The fetch command downloads the list of plugins and themes available'); - } - - protected function execute(InputInterface $input, OutputInterface $output) - { - $this->setupConsole($input, $output); - - $this->cache = self::$grav['cache']->fetch(md5('cli:gpm')); - $this->fetch($this->output); - } - - private function fetch() - { - if (!$this->cache || $this->input->getOption('force')){ - $data = $this->fetchData(); - $date = new \DateTime(); - self::$grav['cache']->save(md5('cli:gpm'), $data, 86400); - $date = $date->modify('+1 day')->format('D, d M Y H:i:s'); - $this->cache = $data; - $this->output->writeln("Data cached until ".$date."\n"); - } - } - - private function fetchData() - { - $this->output->writeln(""); - $this->output->writeln('Fetching data from getgrav.org'); - $this->output->writeln(""); - $curl = $this->getCurl(); - $response = array(); - - $this->progress = new ProgressBar($this->output, count($this->pkg_types)); - $this->progress->setFormat("%message%\n%current%/%max% [%bar%] %percent:3s%%"); - - $this->progress->setMessage('Task in progress'); - $this->progress->start(); - foreach($this->pkg_types as $pkg_type) { - $this->progress->setMessage('Fetching "'.$pkg_type.'"...'); - $url = $this->repository . '/' . $pkg_type . '.json'; - - curl_setopt($curl, CURLOPT_URL, $url); - $response[$pkg_type] = curl_exec($curl); - - $this->progress->advance(); - } - - curl_close($curl); - $this->progress->setMessage("Fetch completed"); - $this->progress->finish(); - $this->output->writeln(""); - - return $response; - } - - private function getCurl($progress = false) - { - $curl = curl_init(); - - curl_setopt($curl, CURLOPT_REFERER, 'Grav GPM v'.GRAV_VERSION); - curl_setopt($curl, CURLOPT_RETURNTRANSFER, true); - curl_setopt($curl, CURLOPT_USERAGENT, 'Grav GPM v'.GRAV_VERSION); - curl_setopt($curl, CURLOPT_FOLLOWLOCATION, true); - - if ($progress) - { - curl_setopt($curl, CURLOPT_NOPROGRESS, false); - curl_setopt($curl, CURLOPT_HEADER, 1); - curl_setopt($curl, CURLOPT_PROGRESSFUNCTION, array($this, 'progress')); - } - - return $curl; - } - - private function progress($download_size, $downloaded) - { - if ($download_size > 0) - { - $this->output->writeln($downloaded / $download_size * 100); - } - } -}