VersionRepository.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970
  1. <?php
  2. /*
  3. * This file is part of Packagist.
  4. *
  5. * (c) Jordi Boggiano <j.boggiano@seld.be>
  6. * Nils Adermann <naderman@naderman.de>
  7. *
  8. * For the full copyright and license information, please view the LICENSE
  9. * file that was distributed with this source code.
  10. */
  11. namespace Packagist\WebBundle\Entity;
  12. use Doctrine\ORM\EntityRepository;
  13. /**
  14. * @author Jordi Boggiano <j.boggiano@seld.be>
  15. */
  16. class VersionRepository extends EntityRepository
  17. {
  18. protected $supportedLinkTypes = array(
  19. 'require',
  20. 'conflict',
  21. 'provide',
  22. 'replace',
  23. 'devRequire',
  24. 'suggest',
  25. );
  26. public function remove(Version $version)
  27. {
  28. $em = $this->getEntityManager();
  29. $version->getPackage()->getVersions()->removeElement($version);
  30. foreach ($version->getAuthors() as $author) {
  31. /** @var $author Author */
  32. $author->getVersions()->removeElement($version);
  33. }
  34. $version->getAuthors()->clear();
  35. foreach ($version->getTags() as $tag) {
  36. /** @var $tag Tag */
  37. $tag->getVersions()->removeElement($version);
  38. }
  39. $version->getTags()->clear();
  40. foreach ($this->supportedLinkTypes as $linkType) {
  41. foreach ($version->{'get'.$linkType}() as $link) {
  42. $em->remove($link);
  43. }
  44. $version->{'get'.$linkType}()->clear();
  45. }
  46. $em->remove($version);
  47. }
  48. public function getFullVersion($versionId)
  49. {
  50. $qb = $this->getEntityManager()->createQueryBuilder();
  51. $qb->select('v', 't', 'a')
  52. ->from('Packagist\WebBundle\Entity\Version', 'v')
  53. ->leftJoin('v.tags', 't')
  54. ->leftJoin('v.authors', 'a')
  55. ->where('v.id = :id')
  56. ->setParameter('id', $versionId);
  57. return $qb->getQuery()->getSingleResult();
  58. }
  59. }