/** * Get an array of dependencies needed to be installed or updated for a list of packages * to be installed. * * @param array $packages The packages slugs * * @return array|bool */ public function getDependenciesNeededToInstall($packages) { $gpm = $this->gpm(); if (!$gpm) { return false; } $dependencies = $this->gpm->getDependencies($packages); return $dependencies; }
/** * @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; }