Example #1
0
 /**
  * @param      $vulnerabilities
  * @param      $version
  * @param null $found_vulnerabilities
  *
  * @return bool
  */
 public function isVulnerable($vulnerabilities, $version, &$found_vulnerabilities = null)
 {
     $found_vulnerabilities = Collection::make($vulnerabilities)->filter(function ($v) use($version) {
         return $this->semver->lessThan($version, $v->fixed_in);
     });
     return $found_vulnerabilities->count() > 0;
 }
 /**
  * Checks if the installed version of Composer is compatible.
  *
  * Composer 1.0.0 and higher consider a `composer install` without having a
  * lock file present as equal to `composer update`. We do not ship with a lock
  * file to avoid merge conflicts downstream, meaning that if a project is
  * installed with an older version of Composer the scaffolding of Drupal will
  * not be triggered. We check this here instead of in drupal-scaffold to be
  * able to give immediate feedback to the end user, rather than failing the
  * installation after going through the lengthy process of compiling and
  * downloading the Composer dependencies.
  *
  * @see https://github.com/composer/composer/pull/5035
  */
 public static function checkComposerVersion(Event $event)
 {
     $composer = $event->getComposer();
     $io = $event->getIO();
     $version = $composer::VERSION;
     // If Composer is installed through git we have no easy way to determine if
     // it is new enough, just display a warning.
     if ($version === '@package_version@') {
         $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>');
     } elseif (Comparator::lessThan($version, '1.0.0')) {
         $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.');
         exit(1);
     }
 }
Example #3
0
 /**
  * Checks if the installed version of Composer is compatible.
  *
  * Composer 1.0.0 and higher consider a `composer install` without having a
  * lock file present as equal to `composer update`. We do not ship with a lock
  * file to avoid merge conflicts downstream, meaning that if a project is
  * installed with an older version of Composer the scaffolding of Drupal will
  * not be triggered. We check this here instead of in drupal-scaffold to be
  * able to give immediate feedback to the end user, rather than failing the
  * installation after going through the lengthy process of compiling and
  * downloading the Composer dependencies.
  *
  * @see https://github.com/composer/composer/pull/5035
  */
 public static function checkComposerVersion(Event $event)
 {
     $composer = $event->getComposer();
     $io = $event->getIO();
     $version = $composer::VERSION;
     // The dev-channel of composer uses the git revision as version number,
     // try to the branch alias instead.
     if (preg_match('/^[0-9a-f]{40}$/i', $version)) {
         $version = $composer::BRANCH_ALIAS_VERSION;
     }
     // If Composer is installed through git we have no easy way to determine if
     // it is new enough, just display a warning.
     if ($version === '@package_version@' || $version === '@package_branch_alias_version@') {
         $io->writeError('<warning>You are running a development version of Composer. If you experience problems, please update Composer to the latest stable version.</warning>');
     } elseif (Comparator::lessThan($version, '1.0.0')) {
         $io->writeError('<error>Drupal-project requires Composer version 1.0.0 or higher. Please update your Composer before continuing</error>.');
         exit(1);
     }
 }
Example #4
0
 /**
  * Check if the package is outdated.
  *
  * @return bool
  */
 public function isOutdated()
 {
     return Comparator::lessThan($this->version, $this->getLatestVersion());
 }
Example #5
0
 /**
  * Selects the upgrade functions applicable for this upgrade.
  *
  * The upgrade functions are specified by the `upgradeList`
  * hook.  This variable is an associative array containing version numbers
  * as keys and an array of upgrade function names as values.  This function
  * merges all the upgrade function names of the version between the current
  * installed version and the upgraded version.
  *
  * @param string $version the version of SimpleID to upgrade from, calls
  * {@link getVersion()} if not specified
  * @return array an array of strings, containing the list of upgrade functions
  * to call.  The functions should be called in the same order as they appear
  * in this array
  * @see SimpleID\API\ModuleHooks::upgradeListHook()
  */
 protected function getUpgradeList($version = NULL)
 {
     $mgr = ModuleManager::instance();
     $upgrade_data = array();
     foreach ($mgr->getModules() as $name => $module) {
         $data = $mgr->invoke($name, 'upgradeList');
         if ($data != NULL) {
             $upgrade_data = array_merge_recursive($upgrade_data, $data);
         }
     }
     if ($version == NULL) {
         $version = $this->getVersion();
     }
     $list = array();
     // Sorts versions from newest to oldest
     $versions = array_keys($upgrade_data);
     $versions = Semver::rsort($versions);
     foreach ($versions as $upgrade_version) {
         if (Comparator::lessThan($version, $upgrade_version)) {
             $list = array_merge($list, $upgrade_data[$upgrade_version]);
         }
     }
     if (Comparator::lessThan($version, SIMPLEID_VERSION)) {
         $list[] = 'SimpleID\\Upgrade->setVersion';
     }
     return $list;
 }
 /**
  * {@inheritdoc}
  */
 public function deploy($version, $stage)
 {
     $successfulDeploy = true;
     $hosts = $this->configuration->getHostsByStage($stage);
     foreach ($hosts as $host) {
         $exception = null;
         $deployEventName = AccompliEvents::DEPLOY_RELEASE;
         $deployCompleteEventName = AccompliEvents::DEPLOY_RELEASE_COMPLETE;
         $deployFailedEventName = AccompliEvents::DEPLOY_RELEASE_FAILED;
         $title = new Title($this->logger->getOutput(), sprintf('Deploying release "%s" to "%s":', $version, $host->getHostname()));
         $title->render();
         try {
             $this->eventDispatcher->dispatch(AccompliEvents::CREATE_CONNECTION, new HostEvent($host));
             $workspaceEvent = new WorkspaceEvent($host);
             $this->eventDispatcher->dispatch(AccompliEvents::GET_WORKSPACE, $workspaceEvent);
             $workspace = $workspaceEvent->getWorkspace();
             if ($workspace instanceof Workspace) {
                 $prepareDeployReleaseEvent = new PrepareDeployReleaseEvent($workspace, $version);
                 $this->eventDispatcher->dispatch(AccompliEvents::PREPARE_DEPLOY_RELEASE, $prepareDeployReleaseEvent);
                 $release = $prepareDeployReleaseEvent->getRelease();
                 if ($release instanceof Release) {
                     $currentRelease = $prepareDeployReleaseEvent->getCurrentRelease();
                     if ($currentRelease instanceof Release && Comparator::lessThan($release->getVersion(), $currentRelease->getVersion())) {
                         $deployEventName = AccompliEvents::ROLLBACK_RELEASE;
                         $deployCompleteEventName = AccompliEvents::ROLLBACK_RELEASE_COMPLETE;
                         $deployFailedEventName = AccompliEvents::ROLLBACK_RELEASE_FAILED;
                     }
                     $deployReleaseEvent = new DeployReleaseEvent($release, $currentRelease);
                     $this->eventDispatcher->dispatch($deployEventName, $deployReleaseEvent);
                     $this->eventDispatcher->dispatch($deployCompleteEventName, $deployReleaseEvent);
                     continue;
                 }
                 throw new RuntimeException(sprintf('No task configured to initialize release version "%s" for deployment.', $version));
             }
             throw new RuntimeException('No task configured to initialize the workspace.');
         } catch (Exception $exception) {
         }
         $successfulDeploy = false;
         $failedEvent = new FailedEvent($this->eventDispatcher->getLastDispatchedEventName(), $this->eventDispatcher->getLastDispatchedEvent(), $exception);
         $this->eventDispatcher->dispatch($deployFailedEventName, $failedEvent);
     }
     return $successfulDeploy;
 }
Example #7
0
 /**
  * Get outdated packages with their current and latest version.
  *
  * @throws \Vinkla\Climb\ClimbException
  *
  * @return array
  */
 public function getOutdatedPackages()
 {
     // Get all installed and required packages.
     $installed = $this->getInstalledPackages();
     $required = $this->getRequiredPackages();
     // Get the installed version number of the required packages.
     $packages = array_intersect_key($installed, $required);
     $outdated = [];
     foreach ($packages as $package => $version) {
         if (!($latest = $this->getLatestVersion($package))) {
             continue;
         }
         if (Comparator::lessThan($version, $latest)) {
             $constraint = $required[$package];
             $outdated[$package] = [$constraint, $version, $latest];
         }
     }
     return $outdated;
 }
 /**
  * Get sql file list ordered by floats
  * @param   string   $module
  * @param   string   $action
  * @param   float    specific version
  * @param   float    current version
  * @return  array    array sorted according to version
  */
 public function getSqlFileListOrdered($module, $action, $specific = null, $current = null)
 {
     $ary = $this->getSqlFileList($module, $action);
     asort($ary);
     $sem = new Comparator();
     if (strpos($current, 'v') === 0) {
         $current = substr($current, 1);
     }
     if (isset($specific)) {
         $ary = array_reverse($ary);
         if ($specific == 1) {
             foreach ($ary as $key => $val) {
                 $val = substr($val, 0, -4);
                 if (strpos($val, 'v') === 0) {
                     $val = substr($val, 1);
                 }
                 if ($sem->greaterThan($val, $current)) {
                     unset($ary[$key]);
                 }
             }
         } else {
             foreach ($ary as $key => $val) {
                 $val = substr($val, 0, -4);
                 if (strpos($val, 'v') === 0) {
                     $val = substr($val, 1);
                 }
                 if ($sem->lessThan($val, $specific)) {
                     unset($ary[$key]);
                 }
                 if ($sem->greaterThan($val, $current)) {
                     unset($ary[$key]);
                 }
             }
         }
     }
     return $ary;
 }
Example #9
0
 /**
  * @param array $versions
  * @param int $direction
  *
  * @return array
  */
 private static function usort(array $versions, $direction)
 {
     if (null === self::$versionParser) {
         self::$versionParser = new VersionParser();
     }
     $versionParser = self::$versionParser;
     $normalized = array();
     // Normalize outside of usort() scope for minor performance increase.
     // Creates an array of arrays: [[normalized, key], ...]
     foreach ($versions as $key => $version) {
         $normalized[] = array($versionParser->normalize($version), $key);
     }
     usort($normalized, function (array $left, array $right) use($direction) {
         if ($left[0] === $right[0]) {
             return 0;
         }
         if (Comparator::lessThan($left[0], $right[0])) {
             return -$direction;
         }
         return $direction;
     });
     // Recreate input array, using the original indexes which are now in sorted order.
     $sorted = array();
     foreach ($normalized as $item) {
         $sorted[] = $versions[$item[1]];
     }
     return $sorted;
 }