/**
  * @param $package
  *
  * @return bool
  */
 private function checkDestination($package)
 {
     $questionHelper = $this->getHelper('question');
     $skipPrompt = $this->input->getOption('all-yes');
     Installer::isValidDestination($this->destination . DS . $package->install_path);
     if (Installer::lastErrorCode() == Installer::EXISTS) {
         if (!$skipPrompt) {
             $this->output->write("\r");
             $this->output->writeln("  |- Checking destination...  <yellow>exists</yellow>");
             $question = new ConfirmationQuestion("  |  '- The package has been detected as installed already, do you want to overwrite it? [y|N] ", false);
             $answer = $questionHelper->ask($this->input, $this->output, $question);
             if (!$answer) {
                 $this->output->writeln("  |     '- <red>You decided to not overwrite the already installed package.</red>");
                 return false;
             }
         }
     }
     if (Installer::lastErrorCode() == Installer::IS_LINK) {
         $this->output->write("\r");
         $this->output->writeln("  |- Checking destination...  <yellow>symbolic link</yellow>");
         if ($skipPrompt) {
             $this->output->writeln("  |     '- <yellow>Skipped automatically.</yellow>");
             return false;
         }
         $question = new ConfirmationQuestion("  |  '- Destination has been detected as symlink, delete symbolic link first? [y|N] ", false);
         $answer = $questionHelper->ask($this->input, $this->output, $question);
         if (!$answer) {
             $this->output->writeln("  |     '- <red>You decided to not delete the symlink automatically.</red>");
             return false;
         } else {
             unlink($this->destination . DS . $package->install_path);
         }
     }
     $this->output->write("\r");
     $this->output->writeln("  |- Checking destination...  <green>ok</green>");
     return true;
 }
Пример #2
0
 public static function uninstall($packages, $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 = self::getGrav()['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) {
             return false;
         }
     }
     return true;
 }
Пример #3
0
 /**
  * @param $slug
  * @param $package
  *
  * @return bool
  */
 private function checkDestination($slug, $package)
 {
     $path = self::getGrav()['locator']->findResource($package->package_type . '://' . $slug);
     $questionHelper = $this->getHelper('question');
     $skipPrompt = $this->input->getOption('all-yes');
     Installer::isValidDestination($path);
     if (Installer::lastErrorCode() == Installer::IS_LINK) {
         $this->output->write("\r");
         $this->output->writeln("  |- Checking destination...  <yellow>symbolic link</yellow>");
         if ($skipPrompt) {
             $this->output->writeln("  |     '- <yellow>Skipped automatically.</yellow>");
             return false;
         }
         $question = new ConfirmationQuestion("  |  '- Destination has been detected as symlink, delete symbolic link first? [y|N] ", false);
         $answer = $questionHelper->ask($this->input, $this->output, $question);
         if (!$answer) {
             $this->output->writeln("  |     '- <red>You decided to not delete the symlink automatically.</red>");
             return false;
         }
     }
     $this->output->write("\r");
     $this->output->writeln("  |- Checking destination...  <green>ok</green>");
     return true;
 }
Пример #4
0
 /**
  * @param      $package
  *
  * @return bool
  */
 private function checkDestination($package)
 {
     $question_helper = $this->getHelper('question');
     Installer::isValidDestination($this->destination . DS . $package->install_path);
     if (Installer::lastErrorCode() == Installer::IS_LINK) {
         $this->output->write("\r");
         $this->output->writeln("  |- Checking destination...  <yellow>symbolic link</yellow>");
         if ($this->all_yes) {
             $this->output->writeln("  |     '- <yellow>Skipped automatically.</yellow>");
             return false;
         }
         $question = new ConfirmationQuestion("  |  '- Destination has been detected as symlink, delete symbolic link first? [y|N] ", false);
         $answer = $question_helper->ask($this->input, $this->output, $question);
         if (!$answer) {
             $this->output->writeln("  |     '- <red>You decided to not delete the symlink automatically.</red>");
             return false;
         } else {
             unlink($this->destination . DS . $package->install_path);
         }
     }
     $this->output->write("\r");
     $this->output->writeln("  |- Checking destination...  <green>ok</green>");
     return true;
 }
 /**
  * @return int|null|void
  */
 protected function serve()
 {
     $package_file = $this->input->getArgument('package-file');
     $helper = $this->getHelper('question');
     $question = new ConfirmationQuestion('Are you sure you want to direct-install <cyan>' . $package_file . '</cyan> [y|N] ', false);
     $answer = $helper->ask($this->input, $this->output, $question);
     if (!$answer) {
         $this->output->writeln("exiting...");
         $this->output->writeln('');
         exit;
     }
     $tmp_dir = Grav::instance()['locator']->findResource('tmp://', true, true);
     $tmp_zip = $tmp_dir . '/Grav-' . uniqid();
     $this->output->writeln("");
     $this->output->writeln("Preparing to install <cyan>" . $package_file . "</cyan>");
     if ($this->isRemote($package_file)) {
         $zip = $this->downloadPackage($package_file, $tmp_zip);
     } else {
         $zip = $this->copyPackage($package_file, $tmp_zip);
     }
     if (file_exists($zip)) {
         $tmp_source = $tmp_dir . '/Grav-' . uniqid();
         $this->output->write("  |- Extracting package...    ");
         $extracted = Installer::unZip($zip, $tmp_source);
         if (!$extracted) {
             $this->output->write("\r");
             $this->output->writeln("  |- Extracting package...    <red>failed</red>");
             exit;
         }
         $this->output->write("\r");
         $this->output->writeln("  |- Extracting package...    <green>ok</green>");
         $type = $this->getPackageType($extracted);
         if (!$type) {
             $this->output->writeln("  '- <red>ERROR: Not a valid Grav package</red>");
             $this->output->writeln('');
             exit;
         }
         $blueprint = $this->getBlueprints($extracted);
         if ($blueprint) {
             if (isset($blueprint['dependencies'])) {
                 $depencencies = [];
                 foreach ($blueprint['dependencies'] as $dependency) {
                     if (is_array($dependency) && isset($dependency['name'])) {
                         $depencencies[] = $dependency['name'];
                     } else {
                         $depencencies[] = $dependency;
                     }
                 }
                 $this->output->writeln("  |- Dependencies found...    <cyan>[" . implode(',', $depencencies) . "]</cyan>");
                 $question = new ConfirmationQuestion("  |  '- Dependencies will not be satisfied. Continue ? [y|N] ", false);
                 $answer = $helper->ask($this->input, $this->output, $question);
                 if (!$answer) {
                     $this->output->writeln("exiting...");
                     $this->output->writeln('');
                     exit;
                 }
             }
         }
         if ($type == 'grav') {
             $this->output->write("  |- Checking destination...  ");
             Installer::isValidDestination(GRAV_ROOT . '/system');
             if (Installer::IS_LINK === Installer::lastErrorCode()) {
                 $this->output->write("\r");
                 $this->output->writeln("  |- Checking destination...  <yellow>symbolic link</yellow>");
                 $this->output->writeln("  '- <red>ERROR: symlinks found...</red> <yellow>" . GRAV_ROOT . "</yellow>");
                 $this->output->writeln('');
                 exit;
             }
             $this->output->write("\r");
             $this->output->writeln("  |- Checking destination...  <green>ok</green>");
             $this->output->write("  |- Installing package...  ");
             Installer::install($zip, GRAV_ROOT, ['sophisticated' => true, 'overwrite' => true, 'ignore_symlinks' => true], $extracted);
         } else {
             $name = $this->getPackageName($extracted);
             if (!$name) {
                 $this->output->writeln("<red>ERROR: Name could not be determined.</red> Please specify with --name|-n");
                 $this->output->writeln('');
                 exit;
             }
             $install_path = $this->getInstallPath($type, $name);
             $is_update = file_exists($install_path);
             $this->output->write("  |- Checking destination...  ");
             Installer::isValidDestination(GRAV_ROOT . DS . $install_path);
             if (Installer::lastErrorCode() == Installer::IS_LINK) {
                 $this->output->write("\r");
                 $this->output->writeln("  |- Checking destination...  <yellow>symbolic link</yellow>");
                 $this->output->writeln("  '- <red>ERROR: symlink found...</red>  <yellow>" . GRAV_ROOT . DS . $install_path . '</yellow>');
                 $this->output->writeln('');
                 exit;
             } else {
                 $this->output->write("\r");
                 $this->output->writeln("  |- Checking destination...  <green>ok</green>");
             }
             $this->output->write("  |- Installing package...  ");
             Installer::install($zip, GRAV_ROOT, ['install_path' => $install_path, 'theme' => $type == 'theme', 'is_update' => $is_update], $extracted);
         }
         Folder::delete($tmp_source);
         $this->output->write("\r");
         if (Installer::lastErrorCode()) {
             $this->output->writeln("  '- <red>Installation failed or aborted.</red>");
             $this->output->writeln('');
         } else {
             $this->output->writeln("  |- Installing package...    <green>ok</green>");
             $this->output->writeln("  '- <green>Success!</green>  ");
             $this->output->writeln('');
         }
     } else {
         $this->output->writeln("  '- <red>ERROR: ZIP package could not be found</red>");
     }
     Folder::delete($tmp_zip);
     // clear cache after successful upgrade
     $this->clearCache();
     return true;
 }
 /**
  * @return int|null|void
  */
 protected function serve()
 {
     $this->upgrader = new Upgrader($this->input->getOption('force'));
     $this->all_yes = $this->input->getOption('all-yes');
     $this->overwrite = $this->input->getOption('overwrite');
     $this->displayGPMRelease();
     $update = $this->upgrader->getAssets()['grav-update'];
     $local = $this->upgrader->getLocalVersion();
     $remote = $this->upgrader->getRemoteVersion();
     $release = strftime('%c', strtotime($this->upgrader->getReleaseDate()));
     if (!$this->upgrader->meetsRequirements()) {
         $this->output->writeln("<red>ATTENTION:</red>");
         $this->output->writeln("   Grav has increased the minimum PHP requirement.");
         $this->output->writeln("   You are currently running PHP <red>" . PHP_VERSION . "</red>, but PHP <green>" . GRAV_PHP_MIN . "</green> is required.");
         $this->output->writeln("   Additional information: <white>http://getgrav.org/blog/changing-php-requirements-to-5.5</white>");
         $this->output->writeln("");
         $this->output->writeln("Selfupgrade aborted.");
         $this->output->writeln("");
         exit;
     }
     if (!$this->overwrite && !$this->upgrader->isUpgradable()) {
         $this->output->writeln("You are already running the latest version of Grav (v" . $local . ") released on " . $release);
         exit;
     }
     Installer::isValidDestination(GRAV_ROOT . '/system');
     if (Installer::IS_LINK === Installer::lastErrorCode()) {
         $this->output->writeln("<red>ATTENTION:</red> Grav is symlinked, cannot upgrade, aborting...");
         $this->output->writeln('');
         $this->output->writeln("You are currently running a symbolically linked Grav v" . $local . ". Latest available is v" . $remote . ".");
         exit;
     }
     // not used but preloaded just in case!
     new ArrayInput([]);
     $questionHelper = $this->getHelper('question');
     $this->output->writeln("Grav v<cyan>{$remote}</cyan> is now available [release date: {$release}].");
     $this->output->writeln("You are currently using v<cyan>" . GRAV_VERSION . "</cyan>.");
     if (!$this->all_yes) {
         $question = new ConfirmationQuestion("Would you like to read the changelog before proceeding? [y|N] ", false);
         $answer = $questionHelper->ask($this->input, $this->output, $question);
         if ($answer) {
             $changelog = $this->upgrader->getChangelog(GRAV_VERSION);
             $this->output->writeln("");
             foreach ($changelog as $version => $log) {
                 $title = $version . ' [' . $log['date'] . ']';
                 $content = preg_replace_callback("/\\d\\.\\s\\[\\]\\(#(.*)\\)/", function ($match) {
                     return "\n" . ucfirst($match[1]) . ":";
                 }, $log['content']);
                 $this->output->writeln($title);
                 $this->output->writeln(str_repeat('-', strlen($title)));
                 $this->output->writeln($content);
                 $this->output->writeln("");
             }
             $question = new ConfirmationQuestion("Press [ENTER] to continue.", true);
             $questionHelper->ask($this->input, $this->output, $question);
         }
         $question = new ConfirmationQuestion("Would you like to upgrade now? [y|N] ", false);
         $answer = $questionHelper->ask($this->input, $this->output, $question);
         if (!$answer) {
             $this->output->writeln("Aborting...");
             exit;
         }
     }
     $this->output->writeln("");
     $this->output->writeln("Preparing to upgrade to v<cyan>{$remote}</cyan>..");
     $this->output->write("  |- Downloading upgrade [" . $this->formatBytes($update['size']) . "]...     0%");
     $this->file = $this->download($update);
     $this->output->write("  |- Installing upgrade...  ");
     $installation = $this->upgrade();
     if (!$installation) {
         $this->output->writeln("  '- <red>Installation failed or aborted.</red>");
         $this->output->writeln('');
     } else {
         $this->output->writeln("  '- <green>Success!</green>  ");
         $this->output->writeln('');
     }
     // clear cache after successful upgrade
     $this->clearCache('all');
 }
Пример #7
0
 /**
  * Check if package exists
  *
  * @param $slug
  * @param $package
  * @return int
  */
 private function packageExists($slug, $package)
 {
     $path = Grav::instance()['locator']->findResource($package->package_type . '://' . $slug);
     Installer::isValidDestination($path);
     return Installer::lastErrorCode();
 }