Пример #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;
     }
 }
Пример #2
0
 /**
  * @return bool
  */
 private function upgrade()
 {
     Installer::install($this->file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]);
     $errorCode = Installer::lastErrorCode();
     Folder::delete($this->tmp);
     if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Installing upgrade...    <red>error</red>                             ");
         $this->output->writeln("  |  '- " . Installer::lastErrorMsg());
         return false;
     }
     $this->output->write("\r");
     // extra white spaces to clear out the buffer properly
     $this->output->writeln("  |- Installing upgrade...    <green>ok</green>                             ");
     return true;
 }
 /**
  * @param $package
  *
  * @return bool
  */
 private function installPackage($package)
 {
     Installer::install($this->file, $this->destination, ['install_path' => $package->install_path]);
     $errorCode = Installer::lastErrorCode();
     Folder::delete($this->tmp);
     if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Installing package...    <red>error</red>                             ");
         $this->output->writeln("  |  '- " . Installer::lastErrorMsg());
         return false;
     }
     $this->output->write("\r");
     // extra white spaces to clear out the buffer properly
     $this->output->writeln("  |- Installing package...    <green>ok</green>                             ");
     return true;
 }
Пример #4
0
 /**
  * Handles updating Grav
  *
  * @return bool True if the action was performed
  */
 public function taskUpdategrav()
 {
     require_once __DIR__ . '/gpm.php';
     if (!$this->authorizeTask('install grav', ['admin.super'])) {
         return;
     }
     $result = \Grav\Plugin\Admin\Gpm::selfupgrade();
     if ($result) {
         $this->admin->json_response = ['status' => 'success', 'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_WAS_SUCCESSFULLY_UPDATED_TO') . ' '];
     } else {
         $this->admin->json_response = ['status' => 'error', 'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_UPDATE_FAILED') . ' <br>' . Installer::lastErrorMsg()];
     }
     return true;
 }
Пример #5
0
 /**
  * Handles updating Grav
  *
  * @return bool True if the action was performed
  */
 public function taskUpdategrav()
 {
     if (!$this->authorizeTask('install grav', ['admin.super'])) {
         return false;
     }
     $gpm = Gpm::GPM();
     $version = $gpm->grav->getVersion();
     $result = Gpm::selfupgrade();
     if ($result) {
         $this->admin->json_response = ['status' => 'success', 'type' => 'updategrav', 'version' => $version, 'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_WAS_SUCCESSFULLY_UPDATED_TO') . ' ' . $version];
     } else {
         $this->admin->json_response = ['status' => 'error', 'type' => 'updategrav', 'version' => GRAV_VERSION, 'message' => $this->admin->translate('PLUGIN_ADMIN.GRAV_UPDATE_FAILED') . ' <br>' . Installer::lastErrorMsg()];
     }
     return true;
 }
Пример #6
0
 /**
  * @param Package[]|string[]|string $packages
  * @param array                     $options
  *
  * @return bool
  */
 public static function uninstall($packages, array $options)
 {
     $options = array_merge(self::$options, $options);
     $packages = is_array($packages) ? $packages : [$packages];
     $count = count($packages);
     $packages = array_filter(array_map(function ($p) {
         if (is_string($p)) {
             $p = strtolower($p);
             $plugin = static::GPM()->getInstalledPlugin($p);
             $p = $plugin ?: static::GPM()->getInstalledTheme($p);
         }
         return $p instanceof Package ? $p : false;
     }, $packages));
     if (!$options['skip_invalid'] && $count !== count($packages)) {
         return false;
     }
     foreach ($packages as $package) {
         $location = Grav::instance()['locator']->findResource($package->package_type . '://' . $package->slug);
         // Check destination
         Installer::isValidDestination($location);
         if (Installer::lastErrorCode() === Installer::IS_LINK && !$options['ignore_symlinks']) {
             return false;
         }
         Installer::uninstall($location);
         $errorCode = Installer::lastErrorCode();
         if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
             $msg = Installer::lastErrorMsg();
             throw new \RuntimeException($msg);
         }
         if (count($packages) == 1) {
             $message = Installer::getMessage();
             if ($message) {
                 return $message;
             }
         }
     }
     return true;
 }
Пример #7
0
 /**
  * @param $slug
  * @param $package
  *
  * @return bool
  */
 private function uninstallPackage($slug, $package)
 {
     $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $slug);
     Installer::uninstall($path);
     $errorCode = Installer::lastErrorCode();
     if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Uninstalling package...  <red>error</red>                             ");
         $this->output->writeln("  |  '- " . Installer::lastErrorMsg());
         return false;
     }
     $this->output->write("\r");
     // extra white spaces to clear out the buffer properly
     $this->output->writeln("  |- Uninstalling package...  <green>ok</green>                             ");
     return true;
 }
Пример #8
0
 /**
  * Install a package
  *
  * @param Package $package
  * @param bool    $is_update True if it's an update. False if it's an install
  *
  * @return bool
  */
 private function installPackage($package, $is_update = false)
 {
     $type = $package->package_type;
     Installer::install($this->file, $this->destination, ['install_path' => $package->install_path, 'theme' => $type == 'themes', 'is_update' => $is_update]);
     $error_code = Installer::lastErrorCode();
     Folder::delete($this->tmp);
     if ($error_code) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Installing package...    <red>error</red>                             ");
         $this->output->writeln("  |  '- " . Installer::lastErrorMsg());
         return false;
     }
     $message = Installer::getMessage();
     if ($message) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- " . $message);
     }
     $this->output->write("\r");
     // extra white spaces to clear out the buffer properly
     $this->output->writeln("  |- Installing package...    <green>ok</green>                             ");
     return true;
 }
Пример #9
0
 /**
  * @param $slug
  * @param $package
  *
  * @return bool
  */
 private function uninstallPackage($slug, $package, $is_dependency = false)
 {
     if (!$slug) {
         return false;
     }
     //check if there are packages that have this as a dependency. Abort and show list
     $dependent_packages = $this->gpm->getPackagesThatDependOnPackage($slug);
     if (count($dependent_packages) > ($is_dependency ? 1 : 0)) {
         $this->output->writeln('');
         $this->output->writeln('');
         $this->output->writeln("<red>Uninstallation failed.</red>");
         $this->output->writeln('');
         if (count($dependent_packages) > ($is_dependency ? 2 : 1)) {
             $this->output->writeln("The installed packages <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove those first.");
         } else {
             $this->output->writeln("The installed package <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove it first.");
         }
         $this->output->writeln('');
         return false;
     }
     $locator = Grav::instance()['locator'];
     $path = $locator->findResource($package->package_type . '://' . $slug);
     Installer::uninstall($path);
     $errorCode = Installer::lastErrorCode();
     if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- Uninstalling package...  <red>error</red>                             ");
         $this->output->writeln("  |  '- " . Installer::lastErrorMsg());
         return false;
     }
     $message = Installer::getMessage();
     if ($message) {
         $this->output->write("\r");
         // extra white spaces to clear out the buffer properly
         $this->output->writeln("  |- " . $message);
     }
     $this->output->write("\r");
     // extra white spaces to clear out the buffer properly
     $this->output->writeln("  |- Uninstalling package...  <green>ok</green>                             ");
     if (isset($package->dependencies)) {
         $questionHelper = $this->getHelper('question');
         foreach ($package->dependencies as $dependency) {
             if (is_array($dependency)) {
                 $dependency = $dependency['name'];
             }
             if ($dependency === 'grav') {
                 continue;
             }
             $dependencyPackage = $this->gpm->findPackage($dependency);
             $question = new ConfirmationQuestion("  |  '- Delete dependency <cyan>" . $dependency . "</cyan> too? [y|N] ", false);
             $answer = $questionHelper->ask($this->input, $this->output, $question);
             if ($answer) {
                 $this->output->writeln("  |     '- <red>You decided to delete " . $dependency . ".</red>");
                 $uninstall = $this->uninstallPackage($dependency, $dependencyPackage, true);
                 if (!$uninstall) {
                     $this->output->writeln("  '- <red>Uninstallation failed or aborted.</red>");
                     $this->output->writeln('');
                 } else {
                     $this->output->writeln("  '- <green>Success!</green>  ");
                     $this->output->writeln('');
                 }
             }
         }
     }
     return true;
 }
Пример #10
0
 /**
  * @param $slug
  * @param $package
  *
  * @return bool
  */
 private function uninstallPackage($slug, $package, $is_dependency = false)
 {
     if (!$slug) {
         return false;
     }
     //check if there are packages that have this as a dependency. Abort and show list
     $dependent_packages = $this->gpm->getPackagesThatDependOnPackage($slug);
     if (count($dependent_packages) > ($is_dependency ? 1 : 0)) {
         $this->output->writeln('');
         $this->output->writeln('');
         $this->output->writeln("<red>Uninstallation failed.</red>");
         $this->output->writeln('');
         if (count($dependent_packages) > ($is_dependency ? 2 : 1)) {
             $this->output->writeln("The installed packages <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove those first.");
         } else {
             $this->output->writeln("The installed package <cyan>" . implode('</cyan>, <cyan>', $dependent_packages) . "</cyan> depends on this package. Please remove it first.");
         }
         $this->output->writeln('');
         return false;
     }
     if (isset($package->dependencies)) {
         $dependencies = $package->dependencies;
         if ($is_dependency) {
             foreach ($dependencies as $key => $dependency) {
                 if (in_array($dependency['name'], $this->dependencies)) {
                     unset($dependencies[$key]);
                 }
             }
         } else {
             if (count($dependencies) > 0) {
                 $this->output->writeln('  `- Dependencies found...');
                 $this->output->writeln('');
             }
         }
         $questionHelper = $this->getHelper('question');
         foreach ($dependencies as $dependency) {
             $this->dependencies[] = $dependency['name'];
             if (is_array($dependency)) {
                 $dependency = $dependency['name'];
             }
             if ($dependency === 'grav') {
                 continue;
             }
             $dependencyPackage = $this->gpm->findPackage($dependency);
             $dependency_exists = $this->packageExists($dependency, $dependencyPackage);
             if ($dependency_exists == Installer::EXISTS) {
                 $this->output->writeln("A dependency on <cyan>" . $dependencyPackage->name . "</cyan> [v" . $dependencyPackage->version . "] was found");
                 $question = new ConfirmationQuestion("  |- Uninstall <cyan>" . $dependencyPackage->name . "</cyan>? [y|N] ", false);
                 $answer = $this->all_yes ? true : $questionHelper->ask($this->input, $this->output, $question);
                 if ($answer) {
                     $uninstall = $this->uninstallPackage($dependency, $dependencyPackage, true);
                     if (!$uninstall) {
                         $this->output->writeln("  '- <red>Uninstallation failed or aborted.</red>");
                     } else {
                         $this->output->writeln("  '- <green>Success!</green>  ");
                     }
                     $this->output->writeln('');
                 } else {
                     $this->output->writeln("  '- <yellow>You decided not to uninstall " . $dependencyPackage->name . ".</yellow>");
                     $this->output->writeln('');
                 }
             }
         }
     }
     $locator = Grav::instance()['locator'];
     $path = $locator->findResource($package->package_type . '://' . $slug);
     Installer::uninstall($path);
     $errorCode = Installer::lastErrorCode();
     if ($errorCode && $errorCode !== Installer::IS_LINK && $errorCode !== Installer::EXISTS) {
         $this->output->writeln("  |- Uninstalling " . $package->name . " package...  <red>error</red>                             ");
         $this->output->writeln("  |  '- <yellow>" . Installer::lastErrorMsg() . "</yellow>");
         return false;
     }
     $message = Installer::getMessage();
     if ($message) {
         $this->output->writeln("  |- " . $message);
     }
     if (!$is_dependency && $this->dependencies) {
         $this->output->writeln("Finishing up uninstalling <cyan>" . $package->name . "</cyan>");
     }
     $this->output->writeln("  |- Uninstalling " . $package->name . " package...  <green>ok</green>                             ");
     return true;
 }
Пример #11
0
 /**
  * Handles updating Grav
  *
  * @return bool True is the action was performed
  */
 public function taskUpdategrav()
 {
     require_once __DIR__ . '/gpm.php';
     if (!$this->authoriseTask('install grav', ['admin.super'])) {
         return;
     }
     $result = \Grav\Plugin\Admin\Gpm::selfupgrade();
     if ($result) {
         $this->admin->json_response = ['status' => 'success', 'message' => 'Grav was successfully updated to '];
     } else {
         $this->admin->json_response = ['status' => 'error', 'message' => 'Grav update failed <br>' . Installer::lastErrorMsg()];
     }
     return true;
 }