Exemplo n.º 1
0
 /**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->gpm = new GPM($this->input->getOption('force'));
     $this->displayGPMRelease();
     $this->destination = realpath($this->input->getOption('destination'));
     $skip_prompt = $this->input->getOption('all-yes');
     if (!Installer::isGravInstance($this->destination)) {
         $this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
         exit;
     }
     if ($this->input->getOption('plugins') === false and $this->input->getOption('themes') === false) {
         $list_type_update = ['plugins' => true, 'themes' => true];
     } else {
         $list_type_update['plugins'] = $this->input->getOption('plugins');
         $list_type_update['themes'] = $this->input->getOption('themes');
     }
     $this->data = $this->gpm->getUpdatable($list_type_update);
     $only_packages = array_map('strtolower', $this->input->getArgument('package'));
     if (!$this->data['total']) {
         $this->output->writeln("Nothing to update.");
         exit;
     }
     $this->output->write("Found <green>" . $this->gpm->countInstalled() . "</green> extensions installed of which <magenta>" . $this->data['total'] . "</magenta> need updating");
     $limit_to = $this->userInputPackages($only_packages);
     $this->output->writeln('');
     unset($this->data['total']);
     unset($limit_to['total']);
     // updates review
     $slugs = [];
     $index = 0;
     foreach ($this->data as $packages) {
         foreach ($packages as $slug => $package) {
             if (count($limit_to) && !array_key_exists($slug, $limit_to)) {
                 continue;
             }
             $this->output->writeln(str_pad($index++ + 1, 2, '0', STR_PAD_LEFT) . ". " . "<cyan>" . str_pad($package->name, 15) . "</cyan> " . "[v<magenta>" . $package->version . "</magenta> ➜ v<green>" . $package->available . "</green>]");
             $slugs[] = $slug;
         }
     }
     if (!$skip_prompt) {
         // prompt to continue
         $this->output->writeln("");
         $questionHelper = $this->getHelper('question');
         $question = new ConfirmationQuestion("Continue with the update process? [Y|n] ", true);
         $answer = $questionHelper->ask($this->input, $this->output, $question);
         if (!$answer) {
             $this->output->writeln("Update aborted. Exiting...");
             exit;
         }
     }
     // finally update
     $install_command = $this->getApplication()->find('install');
     $args = new ArrayInput(['command' => 'install', 'package' => $slugs, '-f' => $this->input->getOption('force'), '-d' => $this->destination, '-y' => true]);
     $command_exec = $install_command->run($args, $this->output);
     if ($command_exec != 0) {
         $this->output->writeln("<red>Error:</red> An error occurred while trying to install the extensions");
         exit;
     }
 }
Exemplo n.º 2
0
 /**
  * Handles getting GPM updates
  */
 public function onTaskGPM()
 {
     $task = 'GPM';
     if (!$this->admin->authorize(['admin.maintenance', 'admin.super'])) {
         $this->admin->json_response = ['status' => 'unauthorized', 'message' => $this->admin->translate('PLUGIN_ADMIN.INSUFFICIENT_PERMISSIONS_FOR_TASK') . ' ' . $task . '.'];
         return false;
     }
     $action = $_POST['action'];
     // getUpdatable | getUpdatablePlugins | getUpdatableThemes | gravUpdates
     $flush = isset($_POST['flush']) && $_POST['flush'] == true ? true : false;
     if (isset($this->grav['session'])) {
         $this->grav['session']->close();
     }
     try {
         $gpm = new GPM($flush);
         switch ($action) {
             case 'getUpdates':
                 $resources_updates = $gpm->getUpdatable();
                 if ($gpm->grav != null) {
                     $grav_updates = ["isUpdatable" => $gpm->grav->isUpdatable(), "assets" => $gpm->grav->getAssets(), "version" => GRAV_VERSION, "available" => $gpm->grav->getVersion(), "date" => $gpm->grav->getDate(), "isSymlink" => $gpm->grav->isSymlink()];
                     echo json_encode(["status" => "success", "payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush]]);
                 } else {
                     echo json_encode(["status" => "error", "message" => "Cannot connect to the GPM"]);
                 }
                 break;
         }
     } catch (\Exception $e) {
         echo json_encode(["status" => "error", "message" => $e->getMessage()]);
     }
     exit;
 }
Exemplo n.º 3
0
 /**
  * Handles getting GPM updates
  */
 public function onTaskGPM()
 {
     $action = $_POST['action'];
     // getUpdatable | getUpdatablePlugins | getUpdatableThemes | gravUpdates
     $flush = isset($_POST['flush']) && $_POST['flush'] == true ? true : false;
     if (isset($this->grav['session'])) {
         $this->grav['session']->close();
     }
     try {
         $gpm = new GPM($flush);
         switch ($action) {
             case 'getUpdates':
                 $resources_updates = $gpm->getUpdatable();
                 $grav_updates = ["isUpdatable" => $gpm->grav->isUpdatable(), "assets" => $gpm->grav->getAssets(), "version" => GRAV_VERSION, "available" => $gpm->grav->getVersion(), "date" => $gpm->grav->getDate(), "isSymlink" => $gpm->grav->isSymlink()];
                 echo json_encode(["status" => "success", "payload" => ["resources" => $resources_updates, "grav" => $grav_updates, "installed" => $gpm->countInstalled(), 'flushed' => $flush]]);
                 break;
         }
     } catch (\Exception $e) {
         echo json_encode(["status" => "error", "message" => $e->getMessage()]);
     }
     exit;
 }