/** * {@inheritDoc} */ public function uninstall(WritableRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125) return; throw new \InvalidArgumentException('Package is not installed: ' . $package); } $repo->removePackage($package); }
/** * Get a list of all Drupal extensions currently managed by the root package. * * This finds Drupal extensions in the root package of the current project. It * does not reconcile them against the file system. * * @param \Composer\Composer $composer * The Composer object. * * @return Composer\Package\PackageInterface[] * Composer packages representing Drupal modules managed in the root * package, keyed by package type. */ public function getComposerManagedExtensions(WritableRepositoryInterface $local_repository) { $types = ['drupal-module', 'drupal-theme', 'drupal-profile']; $packages = $local_repository->getPackages(); $composer_managed_extensions = []; foreach ($packages as $package) { $package_type = $package->getType(); if (in_array($package_type, $types)) { $composer_managed_extensions[$package_type] = $package; } } return $composer_managed_extensions; }
/** * @param string $name * @param string $version * @param string $newName * @return null|Package */ protected static function createPackage($name, $version, $newName) { if (!isset(self::$config['repositories'])) { return null; } $package = null; foreach (self::$config['repositories'] as $cursor) { if (isset($cursor['package']['name'], $cursor['package']['version']) && $cursor['package']['name'] === $name && ($version === '*' || $cursor['package']['version'] === $version)) { $package = $cursor['package']; break; } } if (!$package) { return null; } $new = self::bindPackageValues($newName, $package); self::$localRepo->addPackage($new); return $new; }
/** * {@inheritDoc} */ public function uninstall(WritableRepositoryInterface $repo, PackageInterface $package) { if (!$repo->hasPackage($package)) { // TODO throw exception again here, when update is fixed and we don't have to remove+install (see #125) return; throw new \InvalidArgumentException('Package is not installed: ' . $package); } $downloadPath = $this->getInstallPath($package); $this->downloadManager->remove($package, $downloadPath); $this->removeBinaries($package); $repo->removePackage($package); }
/** * @param WritableRepositoryInterface $repo repository to purge packages from * @param Installer\InstallationManager $im manager to check whether packages are still installed */ protected function purgePackages(WritableRepositoryInterface $repo, Installer\InstallationManager $im) { foreach ($repo->getPackages() as $package) { if (!$im->isPackageInstalled($repo, $package)) { $repo->removePackage($package); } } }
/** * @param Pool $pool * @param PolicyInterface $policy * @param WritableRepositoryInterface $localRepo * @param array $repositories */ private function processPackageUrls($pool, $policy, $localRepo, $repositories) { if (!$this->update) { return; } $rootRefs = $this->package->getReferences(); foreach ($localRepo->getCanonicalPackages() as $package) { // find similar packages (name/version) in all repositories $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion())); foreach ($matches as $index => $match) { // skip local packages if (!in_array($match->getRepository(), $repositories, true)) { unset($matches[$index]); continue; } // skip providers/replacers if ($match->getName() !== $package->getName()) { unset($matches[$index]); continue; } $matches[$index] = $match->getId(); } // select preferred package according to policy rules if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) { $newPackage = $pool->literalToPackage($matches[0]); // update the dist and source URLs $sourceUrl = $package->getSourceUrl(); $newSourceUrl = $newPackage->getSourceUrl(); $newReference = $newPackage->getSourceReference(); if ($package->isDev() && isset($rootRefs[$package->getName()]) && $package->getSourceReference() === $rootRefs[$package->getName()]) { $newReference = $rootRefs[$package->getName()]; } $this->updatePackageUrl($package, $newSourceUrl, $newPackage->getSourceType(), $newReference, $newPackage->getDistUrl()); if ($package instanceof CompletePackage && $newPackage instanceof CompletePackage) { $package->setAbandoned($newPackage->getReplacementPackage() ?: $newPackage->isAbandoned()); } } } }
/** * @param Pool $pool * @param PolicyInterface $policy * @param WritableRepositoryInterface $localRepo * @param array $repositories */ private function processPackageUrls($pool, $policy, $localRepo, $repositories) { if (!$this->update) { return; } foreach ($localRepo->getCanonicalPackages() as $package) { // find similar packages (name/version) in all repositories $matches = $pool->whatProvides($package->getName(), new Constraint('=', $package->getVersion())); foreach ($matches as $index => $match) { // skip local packages if (!in_array($match->getRepository(), $repositories, true)) { unset($matches[$index]); continue; } // skip providers/replacers if ($match->getName() !== $package->getName()) { unset($matches[$index]); continue; } $matches[$index] = $match->getId(); } // select preferred package according to policy rules if ($matches && ($matches = $policy->selectPreferredPackages($pool, array(), $matches))) { $newPackage = $pool->literalToPackage($matches[0]); // update the dist and source URLs $sourceUrl = $package->getSourceUrl(); $newSourceUrl = $newPackage->getSourceUrl(); if ($sourceUrl !== $newSourceUrl) { $package->setSourceType($newPackage->getSourceType()); $package->setSourceUrl($newSourceUrl); $package->setSourceReference($newPackage->getSourceReference()); } // only update dist url for github/bitbucket dists as they use a combination of dist url + dist reference to install // but for other urls this is ambiguous and could result in bad outcomes if (preg_match('{^https?://(?:(?:www\\.)?bitbucket\\.org|(api\\.)?github\\.com)/}', $newPackage->getDistUrl())) { $package->setDistUrl($newPackage->getDistUrl()); } } } }
/** * Inject the contao/*-bundle versions into the Contao package. * * @param WritableRepositoryInterface $repository The repository where to add the packages. * * @param string $version The version to use. * * @param string $prettyVersion The version to use. * * @return void */ protected function injectContaoBundles(WritableRepositoryInterface $repository, $version, $prettyVersion) { foreach (Environment::$bundleNames as $bundleName) { if ($remove = $repository->findPackage($bundleName, '*')) { if ($this->isNotMetaPackageOrHasSameVersion($remove, $version)) { // stop if the package is required somehow and must not be injected or if the virtual package is // already injected. continue; } // Otherwise remove the package. $repository->removePackage($remove); } $package = new CompletePackage($bundleName, $version, $prettyVersion); $package->setType('metapackage'); $repository->addPackage($package); } }