Пример #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 int|null|void
  */
 protected function serve()
 {
     $this->gpm = new GPM($this->input->getOption('force'));
     $this->destination = realpath($this->input->getOption('destination'));
     $packages = array_map('strtolower', $this->input->getArgument('package'));
     $this->data = $this->gpm->findPackages($packages);
     if (false === $this->isWindows() && @is_file(getenv("HOME") . '/.grav/config')) {
         $local_config_file = exec('eval echo ~/.grav/config');
         if (file_exists($local_config_file)) {
             $this->local_config = Yaml::parse($local_config_file);
         }
     }
     if (!Installer::isGravInstance($this->destination) || !Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK])) {
         $this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
         exit;
     }
     $this->output->writeln('');
     if (!$this->data['total']) {
         $this->output->writeln("Nothing to install.");
         $this->output->writeln('');
         exit;
     }
     if (count($this->data['not_found'])) {
         $this->output->writeln("These packages were not found on Grav: <red>" . implode('</red>, <red>', array_keys($this->data['not_found'])) . "</red>");
     }
     unset($this->data['not_found']);
     unset($this->data['total']);
     foreach ($this->data as $data) {
         foreach ($data as $package) {
             //Check for dependencies
             if (isset($package->dependencies)) {
                 $this->output->writeln("Package <cyan>" . $package->name . "</cyan> has " . count($package->dependencies) . " required dependencies that must be installed first...");
                 $this->output->writeln('');
                 $dependency_data = $this->gpm->findPackages($package->dependencies);
                 if (!$dependency_data['total']) {
                     $this->output->writeln("No dependencies found...");
                     $this->output->writeln('');
                 } else {
                     unset($dependency_data['total']);
                     foreach ($dependency_data as $type => $dep_data) {
                         foreach ($dep_data as $name => $dep_package) {
                             Installer::isValidDestination($this->destination . DS . $dep_package->install_path);
                             $error_code = Installer::lastErrorCode();
                             if (!$error_code) {
                                 $this->processPackage($dep_package);
                             }
                         }
                     }
                 }
             }
             $this->processPackage($package);
         }
     }
     // clear cache after successful upgrade
     $this->clearCache();
 }
Пример #3
0
 public static function install($packages, $options)
 {
     $options = array_merge(self::$options, $options);
     if (!Installer::isGravInstance($options['destination']) || !Installer::isValidDestination($options['destination'], [Installer::EXISTS, Installer::IS_LINK])) {
         return false;
     }
     $packages = is_array($packages) ? $packages : [$packages];
     $count = count($packages);
     $packages = array_filter(array_map(function ($p) {
         return !is_string($p) ? $p instanceof Package ? $p : false : self::GPM()->findPackage($p);
     }, $packages));
     if (!$options['skip_invalid'] && $count !== count($packages)) {
         return false;
     }
     foreach ($packages as $package) {
         if (isset($package->dependencies) && $options['install_deps']) {
             $result = static::install($package->dependencies, $options);
             if (!$result) {
                 return false;
             }
         }
         // Check destination
         Installer::isValidDestination($options['destination'] . DS . $package->install_path);
         if (Installer::lastErrorCode() === Installer::EXISTS && !$options['overwrite']) {
             return false;
         }
         if (Installer::lastErrorCode() === Installer::IS_LINK && !$options['ignore_symlinks']) {
             return false;
         }
         $local = static::download($package);
         Installer::install($local, $options['destination'], ['install_path' => $package->install_path]);
         Folder::delete(dirname($local));
         $errorCode = Installer::lastErrorCode();
         if (Installer::lastErrorCode() & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
             return false;
         }
     }
     return true;
 }
Пример #4
0
 public static function selfupgrade()
 {
     $upgrader = new Upgrader();
     if (!Installer::isGravInstance(GRAV_ROOT)) {
         return false;
     }
     if (is_link(GRAV_ROOT . DS . 'index.php')) {
         Installer::setError(Installer::IS_LINK);
         return false;
     }
     if (method_exists($upgrader, 'meetsRequirements') && !$upgrader->meetsRequirements()) {
         $error = [];
         $error[] = '<p>Grav has increased the minimum PHP requirement.<br />';
         $error[] = 'You are currently running PHP <strong>' . PHP_VERSION . '</strong>';
         $error[] = ', but PHP <strong>' . GRAV_PHP_MIN . '</strong> is required.</p>';
         $error[] = '<p><a href="http://getgrav.org/blog/changing-php-requirements-to-5.5" class="button button-small secondary">Additional information</a></p>';
         Installer::setError(implode("\n", $error));
         return false;
     }
     $update = $upgrader->getAssets()['grav-update'];
     $tmp = CACHE_DIR . 'tmp/Grav-' . uniqid();
     $file = self::_downloadSelfupgrade($update, $tmp);
     Installer::install($file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]);
     $errorCode = Installer::lastErrorCode();
     Folder::delete($tmp);
     if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
         return false;
     }
     return true;
 }
Пример #5
0
 public static function selfupgrade()
 {
     $upgrader = new Upgrader();
     if (!Installer::isGravInstance(GRAV_ROOT)) {
         return false;
     }
     if (is_link(GRAV_ROOT . DS . 'index.php')) {
         Installer::setError(Installer::IS_LINK);
         return false;
     }
     $update = $upgrader->getAssets()['grav-update'];
     $tmp = CACHE_DIR . 'tmp/Grav-' . uniqid();
     $file = self::_downloadSelfupgrade($update, $tmp);
     Installer::install($file, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true]);
     $errorCode = Installer::lastErrorCode();
     Folder::delete($tmp);
     if ($errorCode & (Installer::ZIP_OPEN_ERROR | Installer::ZIP_EXTRACT_ERROR)) {
         return false;
     }
     return true;
 }
Пример #6
0
 /**
  * @return int|null|void|bool
  */
 protected function serve()
 {
     $this->gpm = new GPM($this->input->getOption('force'));
     $this->all_yes = $this->input->getOption('all-yes');
     $this->displayGPMRelease();
     $this->destination = realpath($this->input->getOption('destination'));
     $packages = array_map('strtolower', $this->input->getArgument('package'));
     $this->data = $this->gpm->findPackages($packages);
     if (false === $this->isWindows() && @is_file(getenv("HOME") . '/.grav/config')) {
         $local_config_file = exec('eval echo ~/.grav/config');
         if (file_exists($local_config_file)) {
             $this->local_config = Yaml::parse($local_config_file);
         }
     }
     if (!Installer::isGravInstance($this->destination) || !Installer::isValidDestination($this->destination, [Installer::EXISTS, Installer::IS_LINK])) {
         $this->output->writeln("<red>ERROR</red>: " . Installer::lastErrorMsg());
         exit;
     }
     $this->output->writeln('');
     if (!$this->data['total']) {
         $this->output->writeln("Nothing to install.");
         $this->output->writeln('');
         exit;
     }
     if (count($this->data['not_found'])) {
         $this->output->writeln("These packages were not found on Grav: <red>" . implode('</red>, <red>', array_keys($this->data['not_found'])) . "</red>");
     }
     unset($this->data['not_found']);
     unset($this->data['total']);
     if (isset($this->local_config)) {
         // Symlinks available, ask if Grav should use them
         $this->use_symlinks = false;
         $helper = $this->getHelper('question');
         $question = new ConfirmationQuestion('Should Grav use the symlinks if available? [y|N] ', false);
         $answer = $this->all_yes ? false : $helper->ask($this->input, $this->output, $question);
         if ($answer) {
             $this->use_symlinks = true;
         }
     }
     $this->output->writeln('');
     try {
         $dependencies = $this->gpm->getDependencies($packages);
     } catch (\Exception $e) {
         //Error out if there are incompatible packages requirements and tell which ones, and what to do
         //Error out if there is any error in parsing the dependencies and their versions, and tell which one is broken
         $this->output->writeln("<red>" . $e->getMessage() . "</red>");
         return false;
     }
     if ($dependencies) {
         try {
             $this->installDependencies($dependencies, 'install', "The following dependencies need to be installed...");
             $this->installDependencies($dependencies, 'update', "The following dependencies need to be updated...");
             $this->installDependencies($dependencies, 'ignore', "The following dependencies can be updated as there is a newer version, but it's not mandatory...", false);
         } catch (\Exception $e) {
             $this->output->writeln("<red>Installation aborted</red>");
             return false;
         }
         $this->output->writeln("<green>Dependencies are OK</green>");
         $this->output->writeln("");
     }
     //We're done installing dependencies. Install the actual packages
     foreach ($this->data as $data) {
         foreach ($data as $package_name => $package) {
             if (in_array($package_name, array_keys($dependencies))) {
                 $this->output->writeln("<green>Package " . $package_name . " already installed as dependency</green>");
             } else {
                 $is_valid_destination = Installer::isValidDestination($this->destination . DS . $package->install_path);
                 if ($is_valid_destination || Installer::lastErrorCode() == Installer::NOT_FOUND) {
                     $this->processPackage($package, true, false);
                 } else {
                     if (Installer::lastErrorCode() == Installer::EXISTS) {
                         try {
                             $this->askConfirmationIfMajorVersionUpdated($package);
                             $this->gpm->checkNoOtherPackageNeedsThisDependencyInALowerVersion($package->slug, $package->available, array_keys($data));
                         } catch (\Exception $e) {
                             $this->output->writeln("<red>" . $e->getMessage() . "</red>");
                             return false;
                         }
                         $helper = $this->getHelper('question');
                         $question = new ConfirmationQuestion("The package <cyan>{$package_name}</cyan> is already installed, overwrite? [y|N] ", false);
                         $answer = $this->all_yes ? true : $helper->ask($this->input, $this->output, $question);
                         if ($answer) {
                             $is_update = true;
                             $this->processPackage($package, true, $is_update);
                         } else {
                             $this->output->writeln("<yellow>Package " . $package_name . " not overwritten</yellow>");
                         }
                     } else {
                         if (Installer::lastErrorCode() == Installer::IS_LINK) {
                             $this->output->writeln("<red>Cannot overwrite existing symlink for </red><cyan>{$package_name}</cyan>");
                             $this->output->writeln("");
                         }
                     }
                 }
             }
         }
     }
     if (count($this->demo_processing) > 0) {
         foreach ($this->demo_processing as $package) {
             $this->installDemoContent($package);
         }
     }
     // clear cache after successful upgrade
     $this->clearCache();
     return true;
 }