|
@@ -62,106 +62,116 @@ EOF
|
|
|
->setParameters(array(date('Y-m-d H:i:s', time() - 3600)));
|
|
|
|
|
|
foreach ($qb->getQuery()->getResult() as $package) {
|
|
|
- $repo = $provider->getRepository($package->getRepository());
|
|
|
+ $repository = $provider->getRepository($package->getRepository());
|
|
|
|
|
|
- if (!$repo) {
|
|
|
+ if (!$repository) {
|
|
|
$output->writeln('<error>Unsupported repository: '.$package->getRepository().'</error>');
|
|
|
continue;
|
|
|
}
|
|
|
|
|
|
- $output->writeln('Importing '.$repo->getUrl());
|
|
|
+ $output->writeln('Importing '.$repository->getUrl());
|
|
|
|
|
|
try {
|
|
|
- $files = $repo->getAllComposerFiles();
|
|
|
+ foreach ($repository->getTags() as $tag => $identifier) {
|
|
|
+ // TODO parse tag name (or fetch composer file?) w/ composer version parser, if no match, ignore the tag
|
|
|
+ $this->fetchInformation($output, $em, $package, $repository, $identifier);
|
|
|
+ }
|
|
|
+
|
|
|
+ foreach ($repository->getBranches() as $branch => $identifier) {
|
|
|
+ // TODO parse branch name, matching a "$num.x.x" version scheme, + the master one
|
|
|
+ // use for all "x.y.z-dev" versions, usable through "latest-dev"
|
|
|
+ $this->fetchInformation($output, $em, $package, $repository, $identifier);
|
|
|
+ }
|
|
|
+
|
|
|
+ $package->setUpdatedAt(new \DateTime);
|
|
|
+ $package->setCrawledAt(new \DateTime);
|
|
|
+ $em->flush();
|
|
|
} catch (\Exception $e) {
|
|
|
- $output->writeln('<error>Could not fetch data from: '.$repo->getUrl().', skipping.</error>');
|
|
|
+ $output->writeln('<error>Exception: '.$e->getMessage().', skipping package.</error>');
|
|
|
continue;
|
|
|
}
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- foreach ($files as $uniqid => $data) {
|
|
|
- // check if we have that version yet
|
|
|
- foreach ($package->getVersions() as $version) {
|
|
|
- if ($version->getVersion() === $data['version']) {
|
|
|
- continue 2;
|
|
|
- }
|
|
|
- }
|
|
|
+ protected function fetchInformation(OutputInterface $output, $em, $package, $repository, $identifier)
|
|
|
+ {
|
|
|
+ $data = $repository->getComposerInformation($identifier);
|
|
|
|
|
|
- if ($data['name'] !== $package->getName()) {
|
|
|
- $output->writeln('<error>Package name seems to have changed for '.$repo->getUrl().'@'.$uniqid.', skipping</error>');
|
|
|
- continue;
|
|
|
- }
|
|
|
+ // check if we have that version yet
|
|
|
+ foreach ($package->getVersions() as $version) {
|
|
|
+ if ($version->getVersion() === $data['version']) {
|
|
|
+ return;
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $version = new Version();
|
|
|
- $em->persist($version);
|
|
|
+ if ($data['name'] !== $package->getName()) {
|
|
|
+ $output->writeln('<error>Package name seems to have changed for '.$repository->getUrl().'@'.$identifier.', skipping tag.</error>');
|
|
|
+ return;
|
|
|
+ }
|
|
|
|
|
|
- foreach (array('name', 'description', 'homepage', 'license', 'version') as $field) {
|
|
|
- if (isset($data[$field])) {
|
|
|
- $version->{'set'.$field}($data[$field]);
|
|
|
- }
|
|
|
- }
|
|
|
+ $version = new Version();
|
|
|
+ $em->persist($version);
|
|
|
|
|
|
- $version->setPackage($package);
|
|
|
- $version->setUpdatedAt(new \DateTime);
|
|
|
- $version->setReleasedAt(new \DateTime($data['time']));
|
|
|
- $version->setSource(array('type' => $repo->getType(), 'url' => $repo->getUrl()));
|
|
|
+ foreach (array('name', 'description', 'homepage', 'license', 'version') as $field) {
|
|
|
+ if (isset($data[$field])) {
|
|
|
+ $version->{'set'.$field}($data[$field]);
|
|
|
+ }
|
|
|
+ }
|
|
|
|
|
|
- $checksum = hash_file('sha1', $data['download']);
|
|
|
- $version->setDist(array('type' => 'zip', 'url' => $data['download'], 'shasum' => $checksum ?: ''));
|
|
|
+ $version->setPackage($package);
|
|
|
+ $version->setUpdatedAt(new \DateTime);
|
|
|
+ $version->setReleasedAt(new \DateTime($data['time']));
|
|
|
+ $version->setSource(array('type' => $repository->getType(), 'url' => $repository->getUrl()));
|
|
|
+ $version->setDist($repository->getDist($identifier));
|
|
|
|
|
|
- if (isset($data['keywords'])) {
|
|
|
- foreach ($data['keywords'] as $keyword) {
|
|
|
- $version->addTags(Tag::getByName($em, $keyword, true));
|
|
|
- }
|
|
|
+ if (isset($data['keywords'])) {
|
|
|
+ foreach ($data['keywords'] as $keyword) {
|
|
|
+ $version->addTags(Tag::getByName($em, $keyword, true));
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ if (isset($data['authors'])) {
|
|
|
+ foreach ($data['authors'] as $authorData) {
|
|
|
+ $author = null;
|
|
|
+ // skip authors with no information
|
|
|
+ if (!isset($authorData['email']) && !isset($authorData['name'])) {
|
|
|
+ continue;
|
|
|
}
|
|
|
- if (isset($data['authors'])) {
|
|
|
- foreach ($data['authors'] as $authorData) {
|
|
|
- $author = null;
|
|
|
- // skip authors with no information
|
|
|
- if (!isset($authorData['email']) && !isset($authorData['name'])) {
|
|
|
- continue;
|
|
|
- }
|
|
|
-
|
|
|
- if (isset($authorData['email'])) {
|
|
|
- $qb = $em->createQueryBuilder();
|
|
|
- $qb->select('a')
|
|
|
- ->from('Packagist\WebBundle\Entity\Author', 'a')
|
|
|
- ->where('a.email = ?0')
|
|
|
- ->setParameters(array($authorData['email']))
|
|
|
- ->setMaxResults(1);
|
|
|
- $author = $qb->getQuery()->getOneOrNullResult();
|
|
|
- }
|
|
|
-
|
|
|
- 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);
|
|
|
- $version->addAuthors($author);
|
|
|
- $author->addVersions($version);
|
|
|
- }
|
|
|
+
|
|
|
+ if (isset($authorData['email'])) {
|
|
|
+ $qb = $em->createQueryBuilder();
|
|
|
+ $qb->select('a')
|
|
|
+ ->from('Packagist\WebBundle\Entity\Author', 'a')
|
|
|
+ ->where('a.email = ?0')
|
|
|
+ ->setParameters(array($authorData['email']))
|
|
|
+ ->setMaxResults(1);
|
|
|
+ $author = $qb->getQuery()->getOneOrNullResult();
|
|
|
+ }
|
|
|
+
|
|
|
+ if (!$author) {
|
|
|
+ $author = new Author();
|
|
|
+ $em->persist($author);
|
|
|
}
|
|
|
- if (isset($data['require'])) {
|
|
|
- foreach ($data['require'] as $requireName => $requireVersion) {
|
|
|
- $requirement = new Requirement();
|
|
|
- $em->persist($requirement);
|
|
|
- $requirement->setPackageName($requireName);
|
|
|
- $requirement->setPackageVersion($requireVersion);
|
|
|
- $version->addRequirements($requirement);
|
|
|
- $requirement->setVersion($version);
|
|
|
+ foreach (array('email', 'name', 'homepage') as $field) {
|
|
|
+ if (isset($authorData[$field])) {
|
|
|
+ $author->{'set'.$field}($authorData[$field]);
|
|
|
}
|
|
|
}
|
|
|
+ $author->setUpdatedAt(new \DateTime);
|
|
|
+ $version->addAuthors($author);
|
|
|
+ $author->addVersions($version);
|
|
|
}
|
|
|
+ }
|
|
|
|
|
|
- // TODO parse composer.json on every branch matching a "$num.x.x" version scheme, + the master one, for all "x.y.z-dev" versions, usable through "latest-dev"
|
|
|
-
|
|
|
- $package->setUpdatedAt(new \DateTime);
|
|
|
- $package->setCrawledAt(new \DateTime);
|
|
|
- $em->flush();
|
|
|
+ if (isset($data['require'])) {
|
|
|
+ foreach ($data['require'] as $requireName => $requireVersion) {
|
|
|
+ $requirement = new Requirement();
|
|
|
+ $em->persist($requirement);
|
|
|
+ $requirement->setPackageName($requireName);
|
|
|
+ $requirement->setPackageVersion($requireVersion);
|
|
|
+ $version->addRequirements($requirement);
|
|
|
+ $requirement->setVersion($version);
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
}
|