/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $url = $target->getSourceUrl(); $ref = $target->getSourceReference(); $this->io->write(" Checking out " . $ref); $this->execute($url, "svn switch", sprintf("%s/%s", $url, $ref), $path); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path, $url) { GitUtil::cleanEnv(); if (!$this->hasMetadataRepository($path)) { throw new \RuntimeException('The .git directory is missing from ' . $path . ', see https://getcomposer.org/commit-deps for more information'); } $updateOriginUrl = false; if (0 === $this->process->execute('git remote -v', $output, $path) && preg_match('{^origin\\s+(?P<url>\\S+)}m', $output, $originMatch) && preg_match('{^composer\\s+(?P<url>\\S+)}m', $output, $composerMatch)) { if ($originMatch['url'] === $composerMatch['url'] && $composerMatch['url'] !== $target->getSourceUrl()) { $updateOriginUrl = true; } } $ref = $target->getSourceReference(); $this->io->writeError(" Checking out " . $ref); $command = 'git remote set-url composer %s && git fetch composer && git fetch --tags composer'; $commandCallable = function ($url) use($command) { return sprintf($command, ProcessExecutor::escape($url)); }; $this->gitUtil->runCommand($commandCallable, $url, $path); if ($newRef = $this->updateToCommit($path, $ref, $target->getPrettyVersion(), $target->getReleaseDate())) { if ($target->getDistReference() === $target->getSourceReference()) { $target->setDistReference($newRef); } $target->setSourceReference($newRef); } if ($updateOriginUrl) { $this->updateOriginUrl($path, $target->getSourceUrl()); } }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $ref = escapeshellarg($target->getSourceReference()); $path = escapeshellarg($path); $url = escapeshellarg($target->getSourceUrl()); $this->io->write(" Checking out " . $target->getSourceReference()); $this->process->execute(sprintf('cd %s && svn switch %s/%s', $path, $url, $ref)); }
/** * {@inheritDoc} */ public function doDownload(PackageInterface $package, $path) { $url = escapeshellarg($package->getSourceUrl()); $ref = escapeshellarg($package->getSourceReference()); $path = escapeshellarg($path); $this->io->write(" Cloning " . $package->getSourceReference()); $this->process->execute(sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref), $ignoredOutput); }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $url = $target->getSourceUrl(); $ref = $target->getSourceReference(); if (!is_dir($path . '/.svn')) { throw new \RuntimeException('The .svn directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information'); } $this->io->write(" Checking out " . $ref); $this->execute($url, "svn switch", sprintf("%s/%s", $url, $ref), $path); }
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 doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $url = escapeshellarg($target->getSourceUrl()); $ref = escapeshellarg($target->getSourceReference()); $path = escapeshellarg($path); $this->io->write(" Updating to " . $target->getSourceReference()); $command = sprintf('cd %s && hg pull %s && hg up %s', $path, $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
/** * {@inheritDoc} */ public function doDownload(PackageInterface $package, $path) { $url = escapeshellarg($package->getSourceUrl()); $ref = escapeshellarg($package->getSourceReference()); $path = escapeshellarg($path); $this->io->write(" Cloning " . $package->getSourceReference()); $command = sprintf('git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s', $url, $path, $ref); if (0 !== $this->process->execute($command, $ignoredOutput)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
/** * {@inheritDoc} */ public function download(PackageInterface $package, $path) { $url = $package->getDistUrl(); $checksum = $package->getDistSha1Checksum(); if (!is_dir($path)) { if (file_exists($path)) { throw new \UnexpectedValueException($path . ' exists and is not a directory'); } if (!mkdir($path, 0777, true)) { throw new \UnexpectedValueException($path . ' does not exist and could not be created'); } } $fileName = rtrim($path . '/' . md5(time() . rand()) . '.' . pathinfo($url, PATHINFO_EXTENSION), '.'); $this->io->write(" - Package <info>" . $package->getName() . "</info> (<comment>" . $package->getPrettyVersion() . "</comment>)"); if (!extension_loaded('openssl') && (0 === strpos($url, 'https:') || 0 === strpos($url, 'http://github.com'))) { // bypass https for github if openssl is disabled if (preg_match('{^https?://(github.com/[^/]+/[^/]+/(zip|tar)ball/[^/]+)$}i', $url, $match)) { $url = 'http://nodeload.' . $match[1]; } else { throw new \RuntimeException('You must enable the openssl extension to download files via https'); } } $rfs = new RemoteFilesystem($this->io); $rfs->copy($package->getSourceUrl(), $url, $fileName); $this->io->write(''); if (!file_exists($fileName)) { throw new \UnexpectedValueException($url . ' could not be saved to ' . $fileName . ', make sure the' . ' directory is writable and you have internet connectivity'); } if ($checksum && hash_file('sha1', $fileName) !== $checksum) { throw new \UnexpectedValueException('The checksum verification of the archive failed (downloaded from ' . $url . ')'); } $this->io->write(' Unpacking archive'); $this->extract($fileName, $path); $this->io->write(' Cleaning up'); unlink($fileName); // If we have only a one dir inside it suppose to be a package itself $contentDir = glob($path . '/*'); if (1 === count($contentDir)) { $contentDir = $contentDir[0]; // Rename the content directory to avoid error when moving up // a child folder with the same name $temporaryName = md5(time() . rand()); rename($contentDir, $temporaryName); $contentDir = $temporaryName; foreach (array_merge(glob($contentDir . '/.*'), glob($contentDir . '/*')) as $file) { if (trim(basename($file), '.')) { rename($file, $path . '/' . basename($file)); } } rmdir($contentDir); } $this->io->write(''); }
public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { $url = escapeshellarg($target->getSourceUrl()); $ref = escapeshellarg($target->getSourceReference()); $this->io->write(" Updating to " . $target->getSourceReference()); if (!is_dir($path . '/.hg')) { throw new \RuntimeException('The .hg directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information'); } $command = sprintf('hg pull %s && hg up %s', $url, $ref); if (0 !== $this->process->execute($command, $ignoredOutput, realpath($path))) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } }
/** * {@inheritDoc} */ public function doDownload(PackageInterface $package, $path) { $ref = escapeshellarg($package->getSourceReference()); $command = 'git clone %s %s && cd %2$s && git checkout %3$s && git reset --hard %3$s'; $this->io->write(" Cloning " . $package->getSourceReference()); // github, autoswitch protocols if (preg_match('{^(?:https?|git)(://github.com/.*)}', $package->getSourceUrl(), $match)) { $protocols = array('git', 'https', 'http'); foreach ($protocols as $protocol) { $url = escapeshellarg($protocol . $match[1]); if (0 === $this->process->execute(sprintf($command, $url, escapeshellarg($path), $ref), $ignoredOutput)) { return; } $this->filesystem->removeDirectory($path); } throw new \RuntimeException('Failed to checkout ' . $url . ' via git, https and http protocols, aborting.' . "\n\n" . $this->process->getErrorOutput()); } else { $url = escapeshellarg($package->getSourceUrl()); $command = sprintf($command, $url, escapeshellarg($path), $ref); if (0 !== $this->process->execute($command, $ignoredOutput)) { throw new \RuntimeException('Failed to execute ' . $command . "\n\n" . $this->process->getErrorOutput()); } } }
/** * {@inheritDoc} */ public function doDownload(PackageInterface $package, $path, $url) { GitUtil::cleanEnv(); $path = $this->normalizePath($path); $ref = $package->getSourceReference(); $flag = Platform::isWindows() ? '/D ' : ''; $command = 'git clone --no-checkout %s %s && cd ' . $flag . '%2$s && git remote add composer %1$s && git fetch composer'; $this->io->writeError(" Cloning " . $ref); $commandCallable = function ($url) use($ref, $path, $command) { return sprintf($command, ProcessExecutor::escape($url), ProcessExecutor::escape($path), ProcessExecutor::escape($ref)); }; $this->gitUtil->runCommand($commandCallable, $url, $path, true); if ($url !== $package->getSourceUrl()) { $url = $package->getSourceUrl(); $this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path); } $this->setPushUrl($path, $url); if ($newRef = $this->updateToCommit($path, $ref, $package->getPrettyVersion(), $package->getReleaseDate())) { if ($package->getDistReference() === $package->getSourceReference()) { $package->setDistReference($newRef); } $package->setSourceReference($newRef); } }
/** * {@inheritDoc} */ public function doUpdate(PackageInterface $initial, PackageInterface $target, $path) { SvnUtil::cleanEnv(); $url = $target->getSourceUrl(); $ref = $target->getSourceReference(); if (!is_dir($path . '/.svn')) { throw new \RuntimeException('The .svn directory is missing from ' . $path . ', see http://getcomposer.org/commit-deps for more information'); } $flags = ""; if (0 === $this->process->execute('svn --version', $output)) { if (preg_match('{(\\d+(?:\\.\\d+)+)}', $output, $match) && version_compare($match[1], '1.7.0', '>=')) { $flags .= ' --ignore-ancestry'; } } $this->io->write(" Checking out " . $ref); $this->execute($url, "svn switch" . $flags, sprintf("%s/%s", $url, $ref), $path); }
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; }
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; }
protected function setPushUrl(PackageInterface $package, $path) { // set push url for github projects if (preg_match('{^(?:https?|git)://github.com/([^/]+)/([^/]+?)(?:\\.git)?$}', $package->getSourceUrl(), $match)) { $pushUrl = 'git@github.com:' . $match[1] . '/' . $match[2] . '.git'; $cmd = sprintf('git remote set-url --push origin %s', escapeshellarg($pushUrl)); $this->process->execute($cmd, $ignoredOutput, $path); } }
/** * @param PackageInterface $package * @return bool */ protected function save(PackageInterface $package) { $name = $package->getPrettyName(); /** @var Cocona $cocona */ $cocona = self::$app['cocona']; if ($cocona->isInstalled()) { $model = Package::firstOrNew(['name' => $name]); $model->version = $package->getPrettyVersion(); $model->source_type = $package->getSourceType(); $model->source_url = $package->getSourceUrl(); return $model->save(); } /** @var Repository $cache */ $cache = self::$app['cache']; $key = 'cocona.packages.queued'; /** @var Collection $packages */ $packages = $cache->rememberForever($key, function () { return new Collection(); }); $packages->put($name, $package); $cache->forever($key, $packages); return true; }
private function updatePackageUrl(PackageInterface $package, $sourceUrl, $sourceType, $sourceReference, $distUrl) { $oldSourceRef = $package->getSourceReference(); if ($package->getSourceUrl() !== $sourceUrl) { $package->setSourceType($sourceType); $package->setSourceUrl($sourceUrl); $package->setSourceReference($sourceReference); } // 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)/}i', $distUrl)) { $package->setDistUrl($distUrl); $this->updateInstallReferences($package, $sourceReference); } if ($this->updateWhitelist && !$this->isUpdateable($package)) { $this->updateInstallReferences($package, $oldSourceRef); } }
public function getSourceUrl() { return $this->aliasOf->getSourceUrl(); }
protected function setPushUrl(PackageInterface $package, $path) { if (preg_match('{^(?:https?|git)://' . $this->getGitHubDomainsRegex() . '/([^/]+)/([^/]+?)(?:\\.git)?$}', $package->getSourceUrl(), $match)) { $protocols = $this->config->get('github-protocols'); $pushUrl = 'git@' . $match[1] . ':' . $match[2] . '/' . $match[3] . '.git'; if ($protocols[0] !== 'git') { $pushUrl = 'https://' . $match[1] . '/' . $match[2] . '/' . $match[3] . '.git'; } $cmd = sprintf('git remote set-url --push origin %s', escapeshellarg($pushUrl)); $this->process->execute($cmd, $ignoredOutput, $path); } }
/** * Clone repository * * @param PackageInterface $package * @param string $path * @param string $url * @return $this */ protected function cloneRepository(PackageInterface $package, $path, $url) { $command = $this->getCloneCommand(); $this->io->write(" Cloning " . $package->getSourceReference()); $commandCallable = $this->getCloneCommandCallback($path, $package->getSourceReference(), $command); $this->gitUtil->runCommand($commandCallable, $url, $path, true); if ($url !== $package->getSourceUrl()) { $url = $package->getSourceUrl(); $this->process->execute(sprintf('git remote set-url origin %s', ProcessExecutor::escape($url)), $output, $path); } $this->setPushUrl($path, $url); return $this; }
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); } }
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); } }
/** * Returns a GitHub "Comparing changes" URL for provided package versions. * * @param PackageInterface $initialPackage * @param PackageInterface $targetPackage * * @throws Exception\CouldNotCalculateChangelog * * @return string */ public static function getChangelog(PackageInterface $initialPackage, PackageInterface $targetPackage) { if ($initialPackage->getSourceUrl() === $targetPackage->getSourceUrl()) { $reGithubUrl = '/^https?:\\/\\/github\\.com\\/[^\\/]+\\/[^\\/]+\\.git$/'; if (preg_match($reGithubUrl, $initialPackage->getSourceUrl())) { /* Example: PackageInterface::sourceUrl: https://github.com/sonata-project/SonataCoreBundle.git PackageInterface::prettyVersion: 2.2 (or 2.4, or master) Result: https://github.com/sonata-project/SonataCoreBundle/compare/2.2...master */ $initialVersion = $initialPackage->getPrettyVersion(); $targetVersion = $targetPackage->getPrettyVersion(); if ($initialVersion === $targetVersion) { $initialVersion = $initialPackage->getSourceReference(); $targetVersion = $targetPackage->getSourceReference(); } return preg_replace('/\\.git$/', "/compare/{$initialVersion}...{$targetVersion}", $targetPackage->getSourceUrl()); } throw new Exception\CouldNotCalculateChangelog('Unknown changelog; not a GitHub URL: ' . $initialPackage->getSourceUrl(), Exception\CouldNotCalculateChangelog::CODE_SOURCEURL_UNSUPPORTED); } throw new Exception\CouldNotCalculateChangelog('Unknown changelog; source URLs don\'t match: ' . $initialPackage->getSourceUrl() . ', ' . $targetPackage->getSourceUrl(), Exception\CouldNotCalculateChangelog::CODE_SOURCEURL_MISMATCH); }
/** * {@inheritdoc} */ public function getSourceUrl() { return $this->package->getSourceUrl(); }