/** * Return the install path based on package type. * * Relies on built-in BaseInstaller behaviour with one exception: silverstripe/framework * must be installed to 'sapphire' and not 'framework' if the version is <3.0.0 * * @param PackageInterface $package * @param string $frameworkType * @return string */ public function getInstallPath(PackageInterface $package, $frameworkType = '') { if ($package->getName() == 'silverstripe/framework' && preg_match('/^\\d+\\.\\d+\\.\\d+/', $package->getVersion()) && version_compare($package->getVersion(), '2.999.999') < 0) { return $this->templatePath($this->locations['module'], array('name' => 'sapphire')); } else { return parent::getInstallPath($package, $frameworkType); } }
public function uninstall(InstalledRepositoryInterface $repo, PackageInterface $package) { $this->initGingerBackend(); $extra = $package->getExtra(); $uninstallPluginCommand = new Cqrs\UninstallPluginCommand(array('plugin_name' => $package->getName(), 'plugin_type' => $package->getType(), 'plugin_namespace' => $extra['plugin-namespace'], 'plugin_version' => $package->getVersion())); $this->getServiceManager()->get('malocher.cqrs.gate')->getBus()->invokeCommand($uninstallPluginCommand); parent::uninstall($repo, $package); }
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator) { if ($this->preferStable && ($stabA = $a->getStability()) !== ($stabB = $b->getStability())) { return BasePackage::$stabilities[$stabA] < BasePackage::$stabilities[$stabB]; } $constraint = new VersionConstraint($operator, $b->getVersion()); $version = new VersionConstraint('==', $a->getVersion()); return $constraint->matchSpecific($version, true); }
public function dump(PackageInterface $package) { $keys = array('binaries' => 'bin', 'type', 'extra', 'installationSource' => 'installation-source', 'autoload', 'notificationUrl' => 'notification-url', 'includePaths' => 'include-path'); $data = array(); $data['name'] = $package->getPrettyName(); $data['version'] = $package->getPrettyVersion(); $data['version_normalized'] = $package->getVersion(); if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); $data['source']['reference'] = $package->getSourceReference(); } if ($package->getDistType()) { $data['dist']['type'] = $package->getDistType(); $data['dist']['url'] = $package->getDistUrl(); $data['dist']['reference'] = $package->getDistReference(); $data['dist']['shasum'] = $package->getDistSha1Checksum(); } if ($package->getArchiveExcludes()) { $data['archive']['exclude'] = $package->getArchiveExcludes(); } foreach (BasePackage::$supportedLinkTypes as $type => $opts) { if ($links = $package->{'get' . ucfirst($opts['method'])}()) { foreach ($links as $link) { $data[$type][$link->getTarget()] = $link->getPrettyConstraint(); } ksort($data[$type]); } } if ($packages = $package->getSuggests()) { ksort($packages); $data['suggest'] = $packages; } if ($package->getReleaseDate()) { $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); } $data = $this->dumpValues($package, $keys, $data); if ($package instanceof CompletePackageInterface) { $keys = array('scripts', 'license', 'authors', 'description', 'homepage', 'keywords', 'repositories', 'support'); $data = $this->dumpValues($package, $keys, $data); if (isset($data['keywords']) && is_array($data['keywords'])) { sort($data['keywords']); } } if ($package instanceof RootPackageInterface) { $minimumStability = $package->getMinimumStability(); if ($minimumStability) { $data['minimum-stability'] = $minimumStability; } } return $data; }
/** * {@inheritDoc} */ public function notifyInstall(PackageInterface $package) { if (!$this->notifyUrl || !$this->config->get('notify-on-install')) { return; } // TODO use an optional curl_multi pool for all the notifications $url = str_replace('%package%', $package->getPrettyName(), $this->notifyUrl); $params = array('version' => $package->getPrettyVersion(), 'version_normalized' => $package->getVersion()); $opts = array('http' => array('method' => 'POST', 'header' => 'Content-type: application/x-www-form-urlencoded', 'content' => http_build_query($params, '', '&'), 'timeout' => 3)); $context = stream_context_create($opts); @file_get_contents($url, false, $context); }
protected function setRootPackage(PackageInterface $package) { $info = ['name' => $package->getName(), 'version' => $package->getVersion()]; $alias = $this->generatePackagetAlias($package); if (!empty($alias)) { $info['alias'] = $alias; } $extra = $package->getExtra(); if (isset($extra[self::EXTRA_BOOTSTRAP])) { $info['bootstrap'] = $extra[self::EXTRA_BOOTSTRAP]; } $this->savePackage($info); }
protected function addPackage(PackageInterface $package) { $extension = ['name' => $package->getName(), 'version' => $package->getVersion()]; $alias = $this->generateDefaultAlias($package); if (!empty($alias)) { $extension['alias'] = $alias; } $extra = $package->getExtra(); if (isset($extra[self::EXTRA_BOOTSTRAP])) { $extension['bootstrap'] = $extra[self::EXTRA_BOOTSTRAP]; } $extensions = $this->loadExtensions(); $extensions[$package->getName()] = $extension; $this->saveExtensions($extensions); }
public function dump(PackageInterface $package) { $keys = array('binaries' => 'bin', 'scripts', 'type', 'extra', 'installationSource' => 'installation-source', 'license', 'authors', 'description', 'homepage', 'keywords', 'autoload', 'repositories', 'includePaths' => 'include-path', 'support'); $data = array(); $data['name'] = $package->getPrettyName(); $data['version'] = $package->getPrettyVersion(); $data['version_normalized'] = $package->getVersion(); if ($package->getTargetDir()) { $data['target-dir'] = $package->getTargetDir(); } if ($package->getReleaseDate()) { $data['time'] = $package->getReleaseDate()->format('Y-m-d H:i:s'); } if ($package->getSourceType()) { $data['source']['type'] = $package->getSourceType(); $data['source']['url'] = $package->getSourceUrl(); $data['source']['reference'] = $package->getSourceReference(); } if ($package->getDistType()) { $data['dist']['type'] = $package->getDistType(); $data['dist']['url'] = $package->getDistUrl(); $data['dist']['reference'] = $package->getDistReference(); $data['dist']['shasum'] = $package->getDistSha1Checksum(); } foreach (BasePackage::$supportedLinkTypes as $type => $opts) { if ($links = $package->{'get' . ucfirst($opts['method'])}()) { foreach ($links as $link) { $data[$type][$link->getTarget()] = $link->getPrettyConstraint(); } } } if ($packages = $package->getSuggests()) { $data['suggest'] = $packages; } foreach ($keys as $method => $key) { if (is_numeric($method)) { $method = $key; } $getter = 'get' . ucfirst($method); $value = $package->{$getter}(); if (null !== $value && !(is_array($value) && 0 === count($value))) { $data[$key] = $value; } } return $data; }
/** * Given a concrete version, this returns a ~ constraint (when possible) * that should be used, for example, in composer.json. * * For example: * * 1.2.1 -> ~1.2 * * 1.2 -> ~1.2 * * v3.2.1 -> ~3.2 * * 2.0-beta.1 -> ~2.0@beta * * dev-master -> ~2.1@dev (dev version with alias) * * dev-master -> dev-master (dev versions are untouched) * * @param PackageInterface $package * @return string */ public function findRecommendedRequireVersion(PackageInterface $package) { $version = $package->getVersion(); if (!$package->isDev()) { return $this->transformVersion($version, $package->getPrettyVersion(), $package->getStability()); } $loader = new ArrayLoader($this->getParser()); $dumper = new ArrayDumper(); $extra = $loader->getBranchAlias($dumper->dump($package)); if ($extra) { $extra = preg_replace('{^(\\d+\\.\\d+\\.\\d+)(\\.9999999)-dev$}', '$1.0', $extra, -1, $count); if ($count) { $extra = str_replace('.9999999', '.0', $extra); return $this->transformVersion($extra, $extra, 'dev'); } } return $package->getPrettyVersion(); }
/** * @param PackageInterface $package * * @throws \InvalidArgumentException * @return string */ protected function _validatePackage(PackageInterface $package) { $_packageName = $package->getPrettyName(); $_parts = explode('/', $_packageName, 2); $this->_extra = Option::clean($package->getExtra()); $this->_config = Option::get($this->_extra, 'config', array()); $this->_plugIn = static::DSP_PLUGIN_PACKAGE_TYPE == $package->getType(); // Only install DreamFactory packages if not a plug-in if (static::PACKAGE_PREFIX != ($_vendor = @current($_parts)) && !$this->_plugIn) { throw new \InvalidArgumentException('This package is not a DreamFactory package and cannot be installed by this installer.' . PHP_EOL . ' * Name: ' . $_packageName . PHP_EOL . ' * Parts: ' . implode(' / ', $_parts) . PHP_EOL); } // Effectively /docRoot/shared/[vendor]/[namespace]/[package] Log::debug('Package "' . $_packageName . '" installation type: ' . ($this->_plugIn ? 'Plug-in' : 'Package')); $this->_packageName = $_packageName; $this->_installPath = $this->_buildInstallPath($_vendor, @end($_parts)); // Link path for plug-ins $_extra = Option::clean($package->getExtra()); $this->_linkName = Option::get($_extra, 'link_name', $_parts[1]); // Relative to composer.json... i.e. web/[link_name] $this->_linkPath = trim(static::PLUG_IN_LINK_PATH . '/' . $this->_linkName, '/'); Log::info('Platform Installer Debug > ' . $_packageName . ' > Version ' . $package->getVersion()); Log::debug(' * Install path: ' . $this->_installPath); if ($this->_plugIn) { Log::debug(' * Link name: ' . $this->_linkName); Log::debug(' * Link path: ' . $this->_linkPath); } return true; }
public function __toString() { return parent::__toString() . ' (alias of ' . $this->aliasOf->getVersion() . ')'; }
public function getLatestVersion() { return $this->latestPackage->getVersion(); }
public function versionCompare(PackageInterface $a, PackageInterface $b, $operator) { $constraint = new VersionConstraint($operator, $b->getVersion()); $version = new VersionConstraint('==', $a->getVersion()); return $constraint->matchSpecific($version); }
private function updateInformation(OutputInterface $output, RegistryInterface $doctrine, $package, PackageInterface $data) { $em = $doctrine->getEntityManager(); $version = new Version(); $version->setName($package->getName()); $version->setNormalizedVersion(preg_replace('{-dev$}i', '', $data->getVersion())); // check if we have that version yet foreach ($package->getVersions() as $existingVersion) { if ($existingVersion->equals($version)) { // avoid updating newer versions, in case two branches have the same version in their composer.json if ($existingVersion->getReleasedAt() > $data->getReleaseDate()) { return; } if ($existingVersion->getDevelopment()) { $version = $existingVersion; break; } return; } } $version->setVersion($data->getPrettyVersion()); $version->setDevelopment(substr($data->getVersion(), -4) === '-dev'); $em->persist($version); $version->setDescription($data->getDescription()); $package->setDescription($data->getDescription()); $version->setHomepage($data->getHomepage()); $version->setLicense($data->getLicense() ?: array()); $version->setPackage($package); $version->setUpdatedAt(new \DateTime()); $version->setReleasedAt($data->getReleaseDate()); if ($data->getSourceType()) { $source['type'] = $data->getSourceType(); $source['url'] = $data->getSourceUrl(); $source['reference'] = $data->getSourceReference(); $version->setSource($source); } if ($data->getDistType()) { $dist['type'] = $data->getDistType(); $dist['url'] = $data->getDistUrl(); $dist['reference'] = $data->getDistReference(); $dist['shasum'] = $data->getDistSha1Checksum(); $version->setDist($dist); } if ($data->getType()) { $version->setType($data->getType()); if ($data->getType() && $data->getType() !== $package->getType()) { $package->setType($data->getType()); } } $version->setTargetDir($data->getTargetDir()); $version->setAutoload($data->getAutoload()); $version->setExtra($data->getExtra()); $version->setBinaries($data->getBinaries()); $version->getTags()->clear(); if ($data->getKeywords()) { foreach ($data->getKeywords() as $keyword) { $version->addTag(Tag::getByName($em, $keyword, true)); } } $version->getAuthors()->clear(); if ($data->getAuthors()) { foreach ($data->getAuthors() as $authorData) { $author = null; // skip authors with no information if (empty($authorData['email']) && empty($authorData['name'])) { continue; } if (!empty($authorData['email'])) { $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByEmail($authorData['email']); } if (!$author && !empty($authorData['homepage'])) { $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage'])); } if (!$author && !empty($authorData['name'])) { $author = $doctrine->getRepository('PackagistWebBundle:Author')->findOneByNameAndPackage($authorData['name'], $package); } if (!$author) { $author = new Author(); $em->persist($author); } foreach (array('email', 'name', 'homepage') as $field) { if (isset($authorData[$field])) { $author->{'set' . $field}($authorData[$field]); } } $author->setUpdatedAt(new \DateTime()); if (!$version->getAuthors()->contains($author)) { $version->addAuthor($author); } if (!$author->getVersions()->contains($version)) { $author->addVersion($version); } } } foreach ($this->supportedLinkTypes as $linkType => $linkEntity) { $links = array(); foreach ($data->{'get' . $linkType . 's'}() as $link) { $links[$link->getTarget()] = $link->getPrettyConstraint(); } foreach ($version->{'get' . $linkType}() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) { $version->{'get' . $linkType}()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($links[$link->getPackageName()]); } } foreach ($links as $linkPackageName => $linkPackageVersion) { $class = 'Packagist\\WebBundle\\Entity\\' . $linkEntity; $link = new $class(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->{'add' . $linkType . 'Link'}($link); $link->setVersion($version); $em->persist($link); } } if (!$package->getVersions()->contains($version)) { $package->addVersions($version); } }
/** * Given a package, this finds the latest package matching it * * @param PackageInterface $package * @param Composer $composer * @param string $phpVersion * @param bool $minorOnly * * @return PackageInterface|null */ private function find_latest_package(PackageInterface $package, Composer $composer, $phpVersion, $minorOnly = false) { // find the latest version allowed in this pool $name = $package->getName(); $versionSelector = new VersionSelector($this->get_pool($composer)); $stability = $composer->getPackage()->getMinimumStability(); $flags = $composer->getPackage()->getStabilityFlags(); if (isset($flags[$name])) { $stability = array_search($flags[$name], BasePackage::$stabilities, true); } $bestStability = $stability; if ($composer->getPackage()->getPreferStable()) { $bestStability = $package->getStability(); } $targetVersion = null; if (0 === strpos($package->getVersion(), 'dev-')) { $targetVersion = $package->getVersion(); } if ($targetVersion === null && $minorOnly) { $targetVersion = '^' . $package->getVersion(); } return $versionSelector->findBestCandidate($name, $targetVersion, $phpVersion, $bestStability); }
/** * Parse the `composer.json` "extra" block of a package and return its transformed data * * @param \Composer\Package\PackageInterface $package * @param string $package_dir * @return array|null */ public function parseComposerExtra(PackageInterface $package, $package_dir) { $presets = array(); $extra = $package->getExtra(); if (isset($extra['assets-presets'])) { foreach ($extra['assets-presets'] as $index => $item) { $use_item = array(); foreach (array_keys(Config::get('use-statements')) as $statement) { if (isset($item[$statement])) { $item_statement = is_array($item[$statement]) ? $item[$statement] : array($item[$statement]); $use_item[$statement] = array(); foreach ($item_statement as $path) { $use_item[$statement][] = $path; } } if (!empty($use_item)) { $presets[$index] = $use_item; } } } $relative_path = str_replace($this->getAssetsVendorDir() . '/', '', $package_dir); if ($relative_path === $package_dir) { $relative_path = str_replace($this->getAppBasePath(), '', $package_dir); } if (strlen($relative_path)) { $relative_path = trim($relative_path, '/'); } return array('name' => $package->getPrettyName(), 'version' => $package->getVersion(), 'relative_path' => $relative_path, 'assets_presets' => $presets); } return null; }
/** * Create a version string which is unique. dev-master * packages report a version of 9999999-dev. We need a unique version * so we can detect changes. here we use the source reference which * in the case of git is the commit hash * * @param PackageInterface $package * * @return string */ private function createVersion(PackageInterface $package) { $version = $package->getVersion(); if (null !== $package->getSourceReference()) { $version = sprintf('%s-%s', $version, $package->getSourceReference()); } return $version; }
public static function getCacheKey(Package\PackageInterface $p) { $distRef = $p->getDistReference(); if (preg_match('{^[a-f0-9]{40}$}', $distRef)) { return "{$p->getName()}/{$distRef}.{$p->getDistType()}"; } return "{$p->getName()}/{$p->getVersion()}-{$distRef}.{$p->getDistType()}"; }
protected function afterDrupalRewriteInfo(PackageEvent $event, IOInterface $io, PackageInterface $package) { $packageVersion = $package->getVersion(); $packageName = $package->getName(); list($vendor, $project) = explode('/', $packageName); $packagePath = $this->installer->getPackageBasePath($package); $info = array('project' => $project, 'version' => $packageVersion, 'date' => date('Y-m-d'), 'datestamp' => time()); $this->rewriteDirInfo($event, $io, $packagePath, $info); }
/** * Scans the given package and collects extensions data. * @param PackageInterface $package */ public function processPackage(PackageInterface $package) { $extra = $package->getExtra(); $files = isset($extra[self::EXTRA_OPTION_NAME]) ? $extra[self::EXTRA_OPTION_NAME] : null; if ($package->getType() !== self::PACKAGE_TYPE && is_null($files)) { return; } $extension = ['name' => $package->getName(), 'version' => $package->getVersion()]; if ($package->getVersion() === '9999999-dev') { $reference = $package->getSourceReference() ?: $package->getDistReference(); if ($reference) { $extension['reference'] = $reference; } } $this->data['extensions'][$package->getName()] = $extension; $aliases = array_merge($this->prepareAliases($package, 'psr-0'), $this->prepareAliases($package, 'psr-4')); $this->data['aliases'] = array_merge($this->data['aliases'], $aliases); foreach ((array) $files as $name => $path) { $config = $this->readExtensionConfig($package, $path); $config['aliases'] = array_merge($aliases, isset($config['aliases']) ? (array) $config['aliases'] : []); $this->data['aliases'] = array_merge($this->data['aliases'], $config['aliases']); $this->data[$name] = isset($this->data[$name]) ? Helper::mergeConfig($this->data[$name], $config) : $config; } }
/** * Checks if the package matches the given constraint directly or through * provided or replaced packages * * @param array|PackageInterface $candidate * @param string $name Name of the package to be matched * @param ConstraintInterface $constraint The constraint to verify * @return int One of the MATCH* constants of this class or 0 if there is no match */ private function match($candidate, $name, ConstraintInterface $constraint = null) { $candidateName = $candidate->getName(); $candidateVersion = $candidate->getVersion(); $isDev = $candidate->getStability() === 'dev'; $isAlias = $candidate instanceof AliasPackage; if (!$isDev && !$isAlias && isset($this->filterRequires[$name])) { $requireFilter = $this->filterRequires[$name]; } else { $requireFilter = new EmptyConstraint(); } if ($candidateName === $name) { $pkgConstraint = new Constraint('==', $candidateVersion); if ($constraint === null || $constraint->matches($pkgConstraint)) { return $requireFilter->matches($pkgConstraint) ? self::MATCH : self::MATCH_FILTERED; } return self::MATCH_NAME; } $provides = $candidate->getProvides(); $replaces = $candidate->getReplaces(); // aliases create multiple replaces/provides for one target so they can not use the shortcut below if (isset($replaces[0]) || isset($provides[0])) { foreach ($provides as $link) { if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) { return $requireFilter->matches($link->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED; } } foreach ($replaces as $link) { if ($link->getTarget() === $name && ($constraint === null || $constraint->matches($link->getConstraint()))) { return $requireFilter->matches($link->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED; } } return self::MATCH_NONE; } if (isset($provides[$name]) && ($constraint === null || $constraint->matches($provides[$name]->getConstraint()))) { return $requireFilter->matches($provides[$name]->getConstraint()) ? self::MATCH_PROVIDE : self::MATCH_FILTERED; } if (isset($replaces[$name]) && ($constraint === null || $constraint->matches($replaces[$name]->getConstraint()))) { return $requireFilter->matches($replaces[$name]->getConstraint()) ? self::MATCH_REPLACE : self::MATCH_FILTERED; } return self::MATCH_NONE; }
/** * Check if the passed package is not a meta package or has the same version. * * @param PackageInterface $package The package to check. * * @param string $version The version to match against. * * @return bool */ private function isNotMetaPackageOrHasSameVersion(PackageInterface $package, $version) { return 'metapackage' !== $package->getType() || $package->getVersion() == $version; }
private function getCacheKey(PackageInterface $package) { if (preg_match('{^[a-f0-9]{40}$}', $package->getDistReference())) { return $package->getName() . '/' . $package->getDistReference() . '.' . $package->getDistType(); } return $package->getName() . '/' . $package->getVersion() . '-' . $package->getDistReference() . '.' . $package->getDistType(); }
private function updateInformation(Package $package, PackageInterface $data, $flags) { $em = $this->doctrine->getEntityManager(); $version = new Version(); $version->setNormalizedVersion($data->getVersion()); // check if we have that version yet foreach ($package->getVersions() as $existingVersion) { if ($existingVersion->getNormalizedVersion() === $version->getNormalizedVersion()) { if ($existingVersion->getDevelopment() || $flags & self::UPDATE_TAGS) { $version = $existingVersion; break; } // mark it updated to avoid it being pruned $existingVersion->setUpdatedAt(new \DateTime()); return; } } $version->setName($package->getName()); $version->setVersion($data->getPrettyVersion()); $version->setDevelopment($data->isDev()); $em->persist($version); $version->setDescription($data->getDescription()); $package->setDescription($data->getDescription()); $version->setHomepage($data->getHomepage()); $version->setLicense($data->getLicense() ?: array()); $version->setPackage($package); $version->setUpdatedAt(new \DateTime()); $version->setReleasedAt($data->getReleaseDate()); if ($data->getSourceType()) { $source['type'] = $data->getSourceType(); $source['url'] = $data->getSourceUrl(); $source['reference'] = $data->getSourceReference(); $version->setSource($source); } if ($data->getDistType()) { $dist['type'] = $data->getDistType(); $dist['url'] = $data->getDistUrl(); $dist['reference'] = $data->getDistReference(); $dist['shasum'] = $data->getDistSha1Checksum(); $version->setDist($dist); } if ($data->getType()) { $version->setType($data->getType()); if ($data->getType() && $data->getType() !== $package->getType()) { $package->setType($data->getType()); } } $version->setTargetDir($data->getTargetDir()); $version->setAutoload($data->getAutoload()); $version->setExtra($data->getExtra()); $version->setBinaries($data->getBinaries()); $version->setIncludePaths($data->getIncludePaths()); $version->setSupport($data->getSupport()); $version->getTags()->clear(); if ($data->getKeywords()) { foreach ($data->getKeywords() as $keyword) { $tag = Tag::getByName($em, $keyword, true); if (!$version->getTags()->contains($tag)) { $version->addTag($tag); } } } $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author'); $version->getAuthors()->clear(); if ($data->getAuthors()) { foreach ($data->getAuthors() as $authorData) { $author = null; // skip authors with no information if (empty($authorData['email']) && empty($authorData['name'])) { continue; } if (!empty($authorData['email'])) { $author = $authorRepository->findOneByEmail($authorData['email']); } if (!$author && !empty($authorData['homepage'])) { $author = $authorRepository->findOneBy(array('name' => $authorData['name'], 'homepage' => $authorData['homepage'])); } if (!$author && !empty($authorData['name'])) { $author = $authorRepository->findOneByNameAndPackage($authorData['name'], $package); } if (!$author) { $author = new Author(); $em->persist($author); } foreach (array('email', 'name', 'homepage', 'role') as $field) { if (isset($authorData[$field])) { $author->{'set' . $field}($authorData[$field]); } } $author->setUpdatedAt(new \DateTime()); if (!$version->getAuthors()->contains($author)) { $version->addAuthor($author); } if (!$author->getVersions()->contains($version)) { $author->addVersion($version); } } } // handle links foreach ($this->supportedLinkTypes as $linkType => $opts) { $links = array(); foreach ($data->{$opts['method']}() as $link) { $constraint = $link->getPrettyConstraint(); if (false !== strpos($constraint, '~')) { $constraint = str_replace(array('[', ']'), '', $link->getConstraint()); $constraint = preg_replace('{(\\d\\.\\d)(\\.0)+(?=$|,|-)}', '$1', $constraint); $constraint = preg_replace('{([><=,]) }', '$1', $constraint); $constraint = preg_replace('{(<[0-9.]+)-dev}', '$1', $constraint); } if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) { $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) { if ($matches[2] === 'stable') { return $matches[1]; } return $matches[1] . '-' . $matches[2]; }, $constraint); } $links[$link->getTarget()] = $constraint; } foreach ($version->{'get' . $linkType}() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) { $version->{'get' . $linkType}()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($links[$link->getPackageName()]); } } foreach ($links as $linkPackageName => $linkPackageVersion) { $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity']; $link = new $class(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->{'add' . $linkType . 'Link'}($link); $link->setVersion($version); $em->persist($link); } } // handle suggests if ($suggests = $data->getSuggests()) { foreach ($version->getSuggest() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) { $version->getSuggest()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($suggests[$link->getPackageName()]); } } foreach ($suggests as $linkPackageName => $linkPackageVersion) { $link = new SuggestLink(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->addSuggestLink($link); $link->setVersion($version); $em->persist($link); } } if (!$package->getVersions()->contains($version)) { $package->addVersions($version); } }
protected function doInstall($localRepo, $installedRepo, $aliases, $devMode = false) { $minimumStability = $this->package->getMinimumStability(); $stabilityFlags = $this->package->getStabilityFlags(); // initialize locker to create aliased packages if (!$this->update && $this->locker->isLocked($devMode)) { $lockedPackages = $this->locker->getLockedPackages($devMode); $minimumStability = $this->locker->getMinimumStability(); $stabilityFlags = $this->locker->getStabilityFlags(); } $this->whitelistUpdateDependencies($localRepo, $devMode, $this->package->getRequires(), $this->package->getDevRequires()); $this->io->write('<info>Loading composer repositories with package information</info>'); // creating repository pool $pool = new Pool($minimumStability, $stabilityFlags); $pool->addRepository($installedRepo); foreach ($this->repositoryManager->getRepositories() as $repository) { $pool->addRepository($repository); } // creating requirements request $installFromLock = false; $request = new Request($pool); $constraint = new VersionConstraint('=', $this->package->getVersion()); $request->install($this->package->getName(), $constraint); if ($this->update) { $this->io->write('<info>Updating ' . ($devMode ? 'dev ' : '') . 'dependencies</info>'); $request->updateAll(); $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires(); foreach ($links as $link) { $request->install($link->getTarget(), $link->getConstraint()); } } elseif ($this->locker->isLocked($devMode)) { $installFromLock = true; $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies from lock file</info>'); if (!$this->locker->isFresh() && !$devMode) { $this->io->write('<warning>Your lock file is out of sync with your composer.json, run "composer.phar update" to update dependencies</warning>'); } foreach ($lockedPackages as $package) { $version = $package->getVersion(); foreach ($aliases as $alias) { if ($alias['package'] === $package->getName() && $alias['version'] === $package->getVersion()) { $version = $alias['alias_normalized']; break; } } $constraint = new VersionConstraint('=', $version); $request->install($package->getName(), $constraint); } } else { $this->io->write('<info>Installing ' . ($devMode ? 'dev ' : '') . 'dependencies</info>'); $links = $devMode ? $this->package->getDevRequires() : $this->package->getRequires(); foreach ($links as $link) { $request->install($link->getTarget(), $link->getConstraint()); } } // fix the version of all installed packages (+ platform) that are not // in the current local repo to prevent rogue updates (e.g. non-dev // updating when in dev) foreach ($installedRepo->getPackages() as $package) { if ($package->getRepository() === $localRepo) { continue; } $constraint = new VersionConstraint('=', $package->getVersion()); $request->install($package->getName(), $constraint); } // if the updateWhitelist is enabled, packages not in it are also fixed // to the version specified in the lock, or their currently installed version if ($this->update && $this->updateWhitelist) { if ($this->locker->isLocked($devMode)) { $currentPackages = $this->locker->getLockedPackages($devMode); } else { $currentPackages = $installedRepo->getPackages(); } // collect links from composer as well as installed packages $candidates = array(); foreach ($links as $link) { $candidates[$link->getTarget()] = true; } foreach ($localRepo->getPackages() as $package) { $candidates[$package->getName()] = true; } // fix them to the version in lock (or currently installed) if they are not updateable foreach ($candidates as $candidate => $dummy) { foreach ($currentPackages as $curPackage) { if ($curPackage->getName() === $candidate) { if ($this->isUpdateable($curPackage)) { break; } $constraint = new VersionConstraint('=', $curPackage->getVersion()); $request->install($curPackage->getName(), $constraint); } } } } // prepare solver $policy = new DefaultPolicy(); $solver = new Solver($policy, $pool, $installedRepo); // solve dependencies try { $operations = $solver->solve($request); } catch (SolverProblemsException $e) { $this->io->write('<error>Your requirements could not be resolved to an installable set of packages.</error>'); $this->io->write($e->getMessage()); return false; } // force dev packages to be updated if we update or install from a (potentially new) lock foreach ($localRepo->getPackages() as $package) { // skip non-dev packages if (!$package->isDev()) { continue; } // skip packages that will be updated/uninstalled foreach ($operations as $operation) { if ('update' === $operation->getJobType() && $operation->getInitialPackage()->equals($package) || 'uninstall' === $operation->getJobType() && $operation->getPackage()->equals($package)) { continue 2; } } // force update to locked version if it does not match the installed version if ($installFromLock) { $lockData = $this->locker->getLockData(); unset($lockedReference); foreach ($lockData['packages'] as $lockedPackage) { if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { $lockedReference = $lockedPackage['source-reference']; break; } } if (isset($lockedReference) && $lockedReference !== $package->getSourceReference()) { // changing the source ref to update to will be handled in the operations loop below $operations[] = new UpdateOperation($package, clone $package); } } else { // force update to latest on update if ($this->update) { // skip package if the whitelist is enabled and it is not in it if ($this->updateWhitelist && !$this->isUpdateable($package)) { continue; } $newPackage = $this->repositoryManager->findPackage($package->getName(), $package->getVersion()); if ($newPackage && $newPackage->getSourceReference() !== $package->getSourceReference()) { $operations[] = new UpdateOperation($package, $newPackage); } } // force installed package to update to referenced version if it does not match the installed version $references = $this->package->getReferences(); if (isset($references[$package->getName()]) && $references[$package->getName()] !== $package->getSourceReference()) { // changing the source ref to update to will be handled in the operations loop below $operations[] = new UpdateOperation($package, clone $package); } } } // execute operations if (!$operations) { $this->io->write('Nothing to install or update'); } foreach ($operations as $operation) { // collect suggestions if ('install' === $operation->getJobType()) { foreach ($operation->getPackage()->getSuggests() as $target => $reason) { $this->suggestedPackages[] = array('source' => $operation->getPackage()->getPrettyName(), 'target' => $target, 'reason' => $reason); } } $event = 'Composer\\Script\\ScriptEvents::PRE_PACKAGE_' . strtoupper($operation->getJobType()); if (defined($event) && $this->runScripts) { $this->eventDispatcher->dispatchPackageEvent(constant($event), $operation); } // if installing from lock, restore dev packages' references to their locked state if ($installFromLock) { $package = null; if ('update' === $operation->getJobType()) { $package = $operation->getTargetPackage(); } elseif ('install' === $operation->getJobType()) { $package = $operation->getPackage(); } if ($package && $package->isDev()) { $lockData = $this->locker->getLockData(); foreach ($lockData['packages'] as $lockedPackage) { if (!empty($lockedPackage['source-reference']) && strtolower($lockedPackage['package']) === $package->getName()) { // update commit date to allow recovery in case the commit disappeared if (!empty($lockedPackage['commit-date'])) { $package->setReleaseDate(new \DateTime('@' . $lockedPackage['commit-date'])); } $package->setSourceReference($lockedPackage['source-reference']); break; } } } } else { // not installing from lock, force dev packages' references if they're in root package refs $package = null; if ('update' === $operation->getJobType()) { $package = $operation->getTargetPackage(); } elseif ('install' === $operation->getJobType()) { $package = $operation->getPackage(); } if ($package && $package->isDev()) { $references = $this->package->getReferences(); if (isset($references[$package->getName()])) { $package->setSourceReference($references[$package->getName()]); } } } // output alias operations in verbose mode, or all ops in dry run if ($this->dryRun || $this->verbose && false !== strpos($operation->getJobType(), 'Alias')) { $this->io->write(' - ' . $operation); } $this->installationManager->execute($localRepo, $operation); $event = 'Composer\\Script\\ScriptEvents::POST_PACKAGE_' . strtoupper($operation->getJobType()); if (defined($event) && $this->runScripts) { $this->eventDispatcher->dispatchPackageEvent(constant($event), $operation); } if (!$this->dryRun) { $localRepo->write(); } } return true; }
/** * @return bool */ public function isLatest() { $constraint = new Constraint('==', $this->latestPackage->getVersion()); return $constraint->matches($this->getCurrentVersion()); }
/** * {@inheritdoc} */ public function getVersion() { return $this->package->getVersion(); }
private function updateInformation(Package $package, PackageInterface $data, $flags) { $em = $this->doctrine->getManager(); $version = new Version(); $normVersion = $data->getVersion(); $existingVersion = $package->getVersion($normVersion); if ($existingVersion) { $source = $existingVersion->getSource(); // update if the right flag is set, or the source reference has changed (re-tag or new commit on branch) if ($source['reference'] !== $data->getSourceReference() || $flags & self::UPDATE_EQUAL_REFS) { $version = $existingVersion; } else { // mark it updated to avoid it being pruned $existingVersion->setUpdatedAt(new \DateTime()); return false; } } $version->setName($package->getName()); $version->setVersion($data->getPrettyVersion()); $version->setNormalizedVersion($normVersion); $version->setDevelopment($data->isDev()); $em->persist($version); $descr = $this->sanitize($data->getDescription()); $version->setDescription($descr); $package->setDescription($descr); $version->setHomepage($data->getHomepage()); $version->setLicense($data->getLicense() ?: array()); $version->setPackage($package); $version->setUpdatedAt(new \DateTime()); $version->setReleasedAt($data->getReleaseDate()); if ($data->getSourceType()) { $source['type'] = $data->getSourceType(); $source['url'] = $data->getSourceUrl(); $source['reference'] = $data->getSourceReference(); $version->setSource($source); } else { $version->setSource(null); } if ($data->getDistType()) { $dist['type'] = $data->getDistType(); $dist['url'] = $data->getDistUrl(); $dist['reference'] = $data->getDistReference(); $dist['shasum'] = $data->getDistSha1Checksum(); $version->setDist($dist); } else { $version->setDist(null); } if ($data->getType()) { $type = $this->sanitize($data->getType()); $version->setType($type); if ($type !== $package->getType()) { $package->setType($type); } } $version->setTargetDir($data->getTargetDir()); $version->setAutoload($data->getAutoload()); $version->setExtra($data->getExtra()); $version->setBinaries($data->getBinaries()); $version->setIncludePaths($data->getIncludePaths()); $version->setSupport($data->getSupport()); if ($data->getKeywords()) { $keywords = array(); foreach ($data->getKeywords() as $keyword) { $keywords[mb_strtolower($keyword, 'UTF-8')] = $keyword; } $existingTags = []; foreach ($version->getTags() as $tag) { $existingTags[mb_strtolower($tag->getName(), 'UTF-8')] = $tag; } foreach ($keywords as $tagKey => $keyword) { if (isset($existingTags[$tagKey])) { unset($existingTags[$tagKey]); continue; } $tag = Tag::getByName($em, $keyword, true); if (!$version->getTags()->contains($tag)) { $version->addTag($tag); } } foreach ($existingTags as $tag) { $version->getTags()->removeElement($tag); } } elseif (count($version->getTags())) { $version->getTags()->clear(); } $authorRepository = $this->doctrine->getRepository('PackagistWebBundle:Author'); $version->getAuthors()->clear(); if ($data->getAuthors()) { foreach ($data->getAuthors() as $authorData) { $author = null; foreach (array('email', 'name', 'homepage', 'role') as $field) { if (isset($authorData[$field])) { $authorData[$field] = trim($authorData[$field]); if ('' === $authorData[$field]) { $authorData[$field] = null; } } else { $authorData[$field] = null; } } // skip authors with no information if (!isset($authorData['email']) && !isset($authorData['name'])) { continue; } $author = $authorRepository->findOneBy(array('email' => $authorData['email'], 'name' => $authorData['name'], 'homepage' => $authorData['homepage'], 'role' => $authorData['role'])); if (!$author) { $author = new Author(); $em->persist($author); } foreach (array('email', 'name', 'homepage', 'role') as $field) { if (isset($authorData[$field])) { $author->{'set' . $field}($authorData[$field]); } } // only update the author timestamp once a month at most as the value is kinda unused if ($author->getUpdatedAt() === null || $author->getUpdatedAt()->getTimestamp() < time() - 86400 * 30) { $author->setUpdatedAt(new \DateTime()); } if (!$version->getAuthors()->contains($author)) { $version->addAuthor($author); } if (!$author->getVersions()->contains($version)) { $author->addVersion($version); } } } // handle links foreach ($this->supportedLinkTypes as $linkType => $opts) { $links = array(); foreach ($data->{$opts['method']}() as $link) { $constraint = $link->getPrettyConstraint(); if (false !== strpos($constraint, ',') && false !== strpos($constraint, '@')) { $constraint = preg_replace_callback('{([><]=?\\s*[^@]+?)@([a-z]+)}i', function ($matches) { if ($matches[2] === 'stable') { return $matches[1]; } return $matches[1] . '-' . $matches[2]; }, $constraint); } $links[$link->getTarget()] = $constraint; } foreach ($version->{'get' . $linkType}() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($links[$link->getPackageName()]) || $links[$link->getPackageName()] !== $link->getPackageVersion()) { $version->{'get' . $linkType}()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($links[$link->getPackageName()]); } } foreach ($links as $linkPackageName => $linkPackageVersion) { $class = 'Packagist\\WebBundle\\Entity\\' . $opts['entity']; $link = new $class(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->{'add' . $linkType . 'Link'}($link); $link->setVersion($version); $em->persist($link); } } // handle suggests if ($suggests = $data->getSuggests()) { foreach ($version->getSuggest() as $link) { // clear links that have changed/disappeared (for updates) if (!isset($suggests[$link->getPackageName()]) || $suggests[$link->getPackageName()] !== $link->getPackageVersion()) { $version->getSuggest()->removeElement($link); $em->remove($link); } else { // clear those that are already set unset($suggests[$link->getPackageName()]); } } foreach ($suggests as $linkPackageName => $linkPackageVersion) { $link = new SuggestLink(); $link->setPackageName($linkPackageName); $link->setPackageVersion($linkPackageVersion); $version->addSuggestLink($link); $link->setVersion($version); $em->persist($link); } } elseif (count($version->getSuggest())) { // clear existing suggests if present foreach ($version->getSuggest() as $link) { $em->remove($link); } $version->getSuggest()->clear(); } if (!$package->getVersions()->contains($version)) { $package->addVersions($version); } return true; }
public function getInstallPath(PackageInterface $package) { $version = $package->getVersion(); return __DIR__ . '/Fixtures/installer-v' . $version[0] . '/'; }
/** * {@inheritDoc} */ public function update(InstalledRepositoryInterface $repo, PackageInterface $initial, PackageInterface $target) { $this->repository = $repo; $this->beforePatches($initial, $initial->getVersion(), $target->getVersion()); if ($repo->hasPackage($initial)) { $modules = 0; foreach ($this->getModulesPaths($initial) as $path) { $this->beforeUpdateModule($path, $initial); $modules++; } if ($modules) { $this->io->write(''); } } parent::update($repo, $initial, $target); $modules = 0; foreach ($this->getModulesPaths($target) as $path) { $this->afterUpdateModule($path, $target); $modules++; } if ($modules) { $this->io->write(''); } $this->afterPatches($initial, $initial->getVersion(), $target->getVersion()); }