private function updateDocumentFromPackage(\Solarium_Document_ReadWrite $document, Package $package)
 {
     $document->id = $package->getId();
     $document->name = $package->getName();
     $document->description = $package->getDescription();
     $tags = array();
     foreach ($package->getVersions() as $version) {
         foreach ($version->getTags() as $tag) {
             $tags[mb_strtolower($tag->getName(), 'UTF-8')] = true;
         }
     }
     $document->tags = array_keys($tags);
 }
Exemple #2
0
 public function notifyUpdateFailure(Package $package, \Exception $e, $details = null)
 {
     if (!$package->isUpdateFailureNotified()) {
         $recipients = array();
         foreach ($package->getMaintainers() as $maintainer) {
             if ($maintainer->isNotifiableForFailures()) {
                 $recipients[$maintainer->getEmail()] = $maintainer->getUsername();
             }
         }
         if ($recipients) {
             $body = $this->twig->render('PackagistWebBundle:Email:update_failed.txt.twig', array('package' => $package, 'exception' => get_class($e), 'exceptionMessage' => $e->getMessage(), 'details' => $details));
             $message = \Swift_Message::newInstance()->setSubject($package->getName() . ' failed to update, invalid composer.json data')->setFrom($this->options['from'], $this->options['fromName'])->setTo($recipients)->setBody($body);
             try {
                 $this->mailer->send($message);
             } catch (\Swift_TransportException $e) {
                 $this->logger->error('[' . get_class($e) . '] ' . $e->getMessage());
                 return false;
             }
         }
         $package->setUpdateFailureNotified(true);
         $this->em->flush();
     }
     return true;
 }
 private function updateDocumentFromPackage(Solarium_Document_ReadWrite $document, Package $package, array $tags, $redis, DownloadManager $downloadManager, FavoriteManager $favoriteManager)
 {
     $document->setField('id', $package->getId());
     $document->setField('name', $package->getName());
     $document->setField('package_name', $package->getPackageName());
     $document->setField('description', preg_replace('{[\\x00-\\x1f]+}u', '', $package->getDescription()));
     $document->setField('type', $package->getType());
     $document->setField('trendiness', $redis->zscore('downloads:trending', $package->getId()));
     $document->setField('downloads', $downloadManager->getTotalDownloads($package));
     $document->setField('favers', $favoriteManager->getFaverCount($package));
     $document->setField('repository', $package->getRepository());
     $document->setField('language', $package->getLanguage());
     if ($package->isAbandoned()) {
         $document->setField('abandoned', 1);
         $document->setField('replacementPackage', $package->getReplacementPackage() ?: '');
     } else {
         $document->setField('abandoned', 0);
         $document->setField('replacementPackage', '');
     }
     $tags = array_map(function ($tag) {
         return mb_strtolower(preg_replace('{[\\x00-\\x1f]+}u', '', $tag), 'UTF-8');
     }, $tags);
     $document->setField('tags', $tags);
 }
 /**
  * Populates a feed entry with data coming from Package objects.
  *
  * @param \Zend\Feed\Writer\Entry $entry
  * @param Package                 $package
  */
 protected function populatePackageData(Entry $entry, Package $package)
 {
     $entry->setTitle($package->getName());
     $entry->setLink($this->generateUrl('view_package', array('name' => $package->getName()), true));
     $entry->setId($package->getName());
     $entry->setDateModified($package->getCreatedAt());
     $entry->setDateCreated($package->getCreatedAt());
     $entry->setDescription($package->getDescription() ?: ' ');
 }
 /**
  * @Route(
  *      "/packages/{name}/unabandon",
  *      name="unabandon_package",
  *      requirements={"name"="[A-Za-z0-9_.-]+/[A-Za-z0-9_.-]+?"}
  * )
  */
 public function unabandonAction(Package $package)
 {
     if (!$package->getMaintainers()->contains($this->getUser()) && !$this->isGranted('ROLE_EDIT_PACKAGES')) {
         throw new AccessDeniedException();
     }
     $package->setAbandoned(false);
     $package->setReplacementPackage(null);
     $package->setIndexedAt(null);
     $em = $this->getDoctrine()->getManager();
     $em->flush();
     return $this->redirect($this->generateUrl('view_package', array('name' => $package->getName())));
 }
Exemple #6
0
 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;
 }
 private function updateDocumentFromPackage(\Solarium_Document_ReadWrite $document, Package $package, $redis)
 {
     $document->setField('id', $package->getId());
     $document->setField('name', $package->getName());
     $document->setField('description', $package->getDescription());
     $document->setField('type', $package->getType());
     $document->setField('trendiness', $redis->zscore('downloads:trending', $package->getId()));
     $document->setField('repository', $package->getRepository());
     if ($package->isAbandoned()) {
         $document->setField('abandoned', 1);
         $document->setField('replacementPackage', $package->getReplacementPackage() ?: '');
     } else {
         $document->setField('abandoned', 0);
         $document->setField('replacementPackage', '');
     }
     $tags = array();
     foreach ($package->getVersions() as $version) {
         foreach ($version->getTags() as $tag) {
             $tags[mb_strtolower($tag->getName(), 'UTF-8')] = true;
         }
     }
     $document->setField('tags', array_keys($tags));
 }
Exemple #8
0
 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);
     }
 }
 private function updateDocumentFromPackage(\Solarium_Document_ReadWrite $document, Package $package)
 {
     $document->setField('id', strtolower($package->getName()));
     $document->setField('name', $package->getName());
     $document->setField('description', $package->getDescription());
     $document->setField('type', $package->getType());
     $tags = array();
     foreach ($package->getVersions() as $version) {
         foreach ($version->getTags() as $tag) {
             $tags[mb_strtolower($tag->getName(), 'UTF-8')] = true;
         }
     }
     $document->setField('tags', array_keys($tags));
 }
Exemple #10
0
 public function deletePackage(Package $package)
 {
     $this->redis->srem('set:packages', strtolower($package->getName()));
 }