Package.php 24 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914
  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 Composer\Factory;
  13. use Composer\IO\NullIO;
  14. use Composer\Repository\VcsRepository;
  15. use Doctrine\Common\Collections\ArrayCollection;
  16. use Doctrine\ORM\Mapping as ORM;
  17. use Symfony\Component\Validator\Constraints as Assert;
  18. use Symfony\Component\Validator\Context\ExecutionContextInterface;
  19. use Composer\Repository\Vcs\GitHubDriver;
  20. /**
  21. * @ORM\Entity(repositoryClass="Packagist\WebBundle\Entity\PackageRepository")
  22. * @ORM\Table(
  23. * name="package",
  24. * uniqueConstraints={@ORM\UniqueConstraint(name="package_name_idx", columns={"name"})},
  25. * indexes={
  26. * @ORM\Index(name="indexed_idx",columns={"indexedAt"}),
  27. * @ORM\Index(name="crawled_idx",columns={"crawledAt"}),
  28. * @ORM\Index(name="dumped_idx",columns={"dumpedAt"}),
  29. * @ORM\Index(name="repository_idx",columns={"repository"})
  30. * }
  31. * )
  32. * @Assert\Callback(callback="isPackageUnique")
  33. * @Assert\Callback(callback="isVendorWritable")
  34. * @Assert\Callback(callback="isRepositoryValid", groups={"Update", "Default"})
  35. * @author Jordi Boggiano <j.boggiano@seld.be>
  36. */
  37. class Package
  38. {
  39. const AUTO_MANUAL_HOOK = 1;
  40. const AUTO_GITHUB_HOOK = 2;
  41. /**
  42. * @ORM\Id
  43. * @ORM\Column(type="integer")
  44. * @ORM\GeneratedValue(strategy="AUTO")
  45. */
  46. private $id;
  47. /**
  48. * Unique package name
  49. *
  50. * @ORM\Column(length=191)
  51. */
  52. private $name;
  53. /**
  54. * @ORM\Column(nullable=true)
  55. */
  56. private $type;
  57. /**
  58. * @ORM\Column(type="text", nullable=true)
  59. */
  60. private $description;
  61. /**
  62. * @ORM\Column(type="string", nullable=true)
  63. */
  64. private $language;
  65. /**
  66. * @ORM\Column(type="text", nullable=true)
  67. */
  68. private $readme;
  69. /**
  70. * @ORM\Column(type="integer", nullable=true, name="github_stars")
  71. */
  72. private $gitHubStars;
  73. /**
  74. * @ORM\Column(type="integer", nullable=true, name="github_watches")
  75. */
  76. private $gitHubWatches;
  77. /**
  78. * @ORM\Column(type="integer", nullable=true, name="github_forks")
  79. */
  80. private $gitHubForks;
  81. /**
  82. * @ORM\Column(type="integer", nullable=true, name="github_open_issues")
  83. */
  84. private $gitHubOpenIssues;
  85. /**
  86. * @ORM\OneToMany(targetEntity="Packagist\WebBundle\Entity\Version", mappedBy="package")
  87. */
  88. private $versions;
  89. /**
  90. * @ORM\ManyToMany(targetEntity="User", inversedBy="packages")
  91. * @ORM\JoinTable(name="maintainers_packages")
  92. */
  93. private $maintainers;
  94. /**
  95. * @ORM\Column()
  96. * @Assert\NotBlank(groups={"Update", "Default"})
  97. */
  98. private $repository;
  99. // dist-tags / rel or runtime?
  100. /**
  101. * @ORM\Column(type="datetime")
  102. */
  103. private $createdAt;
  104. /**
  105. * @ORM\Column(type="datetime", nullable=true)
  106. */
  107. private $updatedAt;
  108. /**
  109. * @ORM\Column(type="datetime", nullable=true)
  110. */
  111. private $crawledAt;
  112. /**
  113. * @ORM\Column(type="datetime", nullable=true)
  114. */
  115. private $indexedAt;
  116. /**
  117. * @ORM\Column(type="datetime", nullable=true)
  118. */
  119. private $dumpedAt;
  120. /**
  121. * @ORM\OneToMany(targetEntity="Packagist\WebBundle\Entity\Download", mappedBy="package")
  122. */
  123. private $downloads;
  124. /**
  125. * @ORM\Column(type="smallint")
  126. */
  127. private $autoUpdated = 0;
  128. /**
  129. * @var bool
  130. * @ORM\Column(type="boolean")
  131. */
  132. private $abandoned = false;
  133. /**
  134. * @var string
  135. * @ORM\Column(type="string", length=255, nullable=true)
  136. */
  137. private $replacementPackage;
  138. /**
  139. * @ORM\Column(type="boolean", options={"default"=false})
  140. */
  141. private $updateFailureNotified = false;
  142. private $entityRepository;
  143. private $router;
  144. /**
  145. * @var \Composer\Repository\Vcs\VcsDriverInterface
  146. */
  147. private $vcsDriver = true;
  148. private $vcsDriverError;
  149. /**
  150. * @var array lookup table for versions
  151. */
  152. private $cachedVersions;
  153. public function __construct()
  154. {
  155. $this->versions = new ArrayCollection();
  156. $this->createdAt = new \DateTime;
  157. }
  158. public function toArray(VersionRepository $versionRepo)
  159. {
  160. $versions = array();
  161. $versionIds = [];
  162. $this->versions = $versionRepo->refreshVersions($this->getVersions());
  163. foreach ($this->getVersions() as $version) {
  164. $versionIds[] = $version->getId();
  165. }
  166. $versionData = $versionRepo->getVersionData($versionIds);
  167. foreach ($this->getVersions() as $version) {
  168. /** @var $version Version */
  169. $versions[$version->getVersion()] = $version->toArray($versionData);
  170. }
  171. $maintainers = array();
  172. foreach ($this->getMaintainers() as $maintainer) {
  173. /** @var $maintainer User */
  174. $maintainers[] = $maintainer->toArray();
  175. }
  176. $data = array(
  177. 'name' => $this->getName(),
  178. 'description' => $this->getDescription(),
  179. 'time' => $this->getCreatedAt()->format('c'),
  180. 'maintainers' => $maintainers,
  181. 'versions' => $versions,
  182. 'type' => $this->getType(),
  183. 'repository' => $this->getRepository(),
  184. 'github_stars' => $this->getGitHubStars(),
  185. 'github_watchers' => $this->getGitHubWatches(),
  186. 'github_forks' => $this->getGitHubForks(),
  187. 'github_open_issues' => $this->getGitHubOpenIssues(),
  188. 'language' => $this->getLanguage(),
  189. );
  190. if ($this->isAbandoned()) {
  191. $data['abandoned'] = $this->getReplacementPackage() ?: true;
  192. }
  193. return $data;
  194. }
  195. public function isRepositoryValid(ExecutionContextInterface $context)
  196. {
  197. // vcs driver was not nulled which means the repository was not set/modified and is still valid
  198. if (true === $this->vcsDriver && null !== $this->getName()) {
  199. return;
  200. }
  201. $property = 'repository';
  202. $driver = $this->vcsDriver;
  203. if (!is_object($driver)) {
  204. if (preg_match('{^http://}', $this->repository)) {
  205. $context->buildViolation('Non-secure HTTP URLs are not supported, make sure you use an HTTPS or SSH URL')
  206. ->atPath($property)
  207. ->addViolation()
  208. ;
  209. } elseif (preg_match('{https?://.+@}', $this->repository)) {
  210. $context->buildViolation('URLs with user@host are not supported, use a read-only public URL')
  211. ->atPath($property)
  212. ->addViolation()
  213. ;
  214. } elseif (is_string($this->vcsDriverError)) {
  215. $context->buildViolation('Uncaught Exception: '.htmlentities($this->vcsDriverError, ENT_COMPAT, 'utf-8'))
  216. ->atPath($property)
  217. ->addViolation()
  218. ;
  219. } else {
  220. $context->buildViolation('No valid/supported repository was found at the given URL')
  221. ->atPath($property)
  222. ->addViolation()
  223. ;
  224. }
  225. return;
  226. }
  227. try {
  228. $information = $driver->getComposerInformation($driver->getRootIdentifier());
  229. if (false === $information) {
  230. $context->buildViolation('No composer.json was found in the '.$driver->getRootIdentifier().' branch.')
  231. ->atPath($property)
  232. ->addViolation()
  233. ;
  234. return;
  235. }
  236. if (empty($information['name'])) {
  237. $context->buildViolation('The package name was not found in the composer.json, make sure there is a name present.')
  238. ->atPath($property)
  239. ->addViolation()
  240. ;
  241. return;
  242. }
  243. if (!preg_match('{^[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*$}iD', $information['name'])) {
  244. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, it should have a vendor name, a forward slash, and a package name. The vendor and package name can be words separated by -, . or _. The complete name should match "[a-z0-9]([_.-]?[a-z0-9]+)*/[a-z0-9]([_.-]?[a-z0-9]+)*".')
  245. ->atPath($property)
  246. ->addViolation()
  247. ;
  248. return;
  249. }
  250. if (preg_match('{(free.*watch|watch.*free|movie.*free|free.*movie|watch.*movie|watch.*full|generate.*resource|generate.*unlimited|hack.*coin|coin.*hack|v[.-]?bucks|(fortnite|pubg).*free|hack.*cheat|cheat.*hack|putlocker)}i', $information['name'])) {
  251. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is blocked, if you think this is a mistake please get in touch with us.')
  252. ->atPath($property)
  253. ->addViolation()
  254. ;
  255. return;
  256. }
  257. $reservedNames = ['nul', 'con', 'prn', 'aux', 'com1', 'com2', 'com3', 'com4', 'com5', 'com6', 'com7', 'com8', 'com9', 'lpt1', 'lpt2', 'lpt3', 'lpt4', 'lpt5', 'lpt6', 'lpt7', 'lpt8', 'lpt9'];
  258. $bits = explode('/', strtolower($information['name']));
  259. if (in_array($bits[0], $reservedNames, true) || in_array($bits[1], $reservedNames, true)) {
  260. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is reserved, package and vendor names can not match any of: '.implode(', ', $reservedNames).'.')
  261. ->atPath($property)
  262. ->addViolation()
  263. ;
  264. return;
  265. }
  266. if (preg_match('{\.json$}', $information['name'])) {
  267. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, package names can not end in .json, consider renaming it or perhaps using a -json suffix instead.')
  268. ->atPath($property)
  269. ->addViolation()
  270. ;
  271. return;
  272. }
  273. if (preg_match('{[A-Z]}', $information['name'])) {
  274. $suggestName = preg_replace('{(?:([a-z])([A-Z])|([A-Z])([A-Z][a-z]))}', '\\1\\3-\\2\\4', $information['name']);
  275. $suggestName = strtolower($suggestName);
  276. $context->buildViolation('The package name '.htmlentities($information['name'], ENT_COMPAT, 'utf-8').' is invalid, it should not contain uppercase characters. We suggest using '.$suggestName.' instead.')
  277. ->atPath($property)
  278. ->addViolation()
  279. ;
  280. return;
  281. }
  282. } catch (\Exception $e) {
  283. $context->buildViolation('We had problems parsing your composer.json file, the parser reports: '.htmlentities($e->getMessage(), ENT_COMPAT, 'utf-8'))
  284. ->atPath($property)
  285. ->addViolation()
  286. ;
  287. }
  288. if (null === $this->getName()) {
  289. $context->buildViolation('An unexpected error has made our parser fail to find a package name in your repository, if you think this is incorrect please try again')
  290. ->atPath($property)
  291. ->addViolation()
  292. ;
  293. }
  294. }
  295. public function setEntityRepository($repository)
  296. {
  297. $this->entityRepository = $repository;
  298. }
  299. public function setRouter($router)
  300. {
  301. $this->router = $router;
  302. }
  303. public function isPackageUnique(ExecutionContextInterface $context)
  304. {
  305. try {
  306. if ($this->entityRepository->findOneByName($this->name)) {
  307. $context->buildViolation('A package with the name <a href="'.$this->router->generate('view_package', array('name' => $this->name)).'">'.$this->name.'</a> already exists.')
  308. ->atPath('repository')
  309. ->addViolation()
  310. ;
  311. }
  312. } catch (\Doctrine\ORM\NoResultException $e) {}
  313. }
  314. public function isVendorWritable(ExecutionContextInterface $context)
  315. {
  316. try {
  317. $vendor = $this->getVendor();
  318. if ($vendor && $this->entityRepository->isVendorTaken($vendor, reset($this->maintainers))) {
  319. $context->buildViolation('The vendor is already taken by someone else. '
  320. . 'You may ask them to add your package and give you maintainership access. '
  321. . 'If they add you as a maintainer on any package in that vendor namespace, '
  322. . 'you will then be able to add new packages in that namespace. '
  323. . 'The packages already in that vendor namespace can be found at '
  324. . '<a href="'.$this->router->generate('view_vendor', array('vendor' => $vendor)).'">'.$vendor.'</a>')
  325. ->atPath('repository')
  326. ->addViolation()
  327. ;
  328. }
  329. } catch (\Doctrine\ORM\NoResultException $e) {}
  330. }
  331. /**
  332. * Get id
  333. *
  334. * @return string
  335. */
  336. public function getId()
  337. {
  338. return $this->id;
  339. }
  340. /**
  341. * Set name
  342. *
  343. * @param string $name
  344. */
  345. public function setName($name)
  346. {
  347. $this->name = $name;
  348. }
  349. /**
  350. * Get name
  351. *
  352. * @return string
  353. */
  354. public function getName()
  355. {
  356. return $this->name;
  357. }
  358. /**
  359. * Get vendor prefix
  360. *
  361. * @return string
  362. */
  363. public function getVendor()
  364. {
  365. return preg_replace('{/.*$}', '', $this->name);
  366. }
  367. /**
  368. * Get package name without vendor
  369. *
  370. * @return string
  371. */
  372. public function getPackageName()
  373. {
  374. return preg_replace('{^[^/]*/}', '', $this->name);
  375. }
  376. /**
  377. * Set description
  378. *
  379. * @param string $description
  380. */
  381. public function setDescription($description)
  382. {
  383. $this->description = $description;
  384. }
  385. /**
  386. * Get description
  387. *
  388. * @return string
  389. */
  390. public function getDescription()
  391. {
  392. return $this->description;
  393. }
  394. /**
  395. * Set language
  396. *
  397. * @param string $language
  398. */
  399. public function setLanguage($language)
  400. {
  401. $this->language = $language;
  402. }
  403. /**
  404. * Get language
  405. *
  406. * @return string
  407. */
  408. public function getLanguage()
  409. {
  410. return $this->language;
  411. }
  412. /**
  413. * Set readme
  414. *
  415. * @param string $readme
  416. */
  417. public function setReadme($readme)
  418. {
  419. $this->readme = $readme;
  420. }
  421. /**
  422. * Get readme
  423. *
  424. * @return string
  425. */
  426. public function getReadme()
  427. {
  428. return $this->readme;
  429. }
  430. /**
  431. * Get readme with transformations that should not be done in the stored readme as they might not be valid in the long run
  432. *
  433. * @return string
  434. */
  435. public function getOptimizedReadme()
  436. {
  437. return str_replace(['<img src="https://raw.github.com/', '<img src="https://raw.githubusercontent.com/'], '<img src="https://rawcdn.githack.com/', $this->readme);
  438. }
  439. /**
  440. * @param int $val
  441. */
  442. public function setGitHubStars($val)
  443. {
  444. $this->gitHubStars = $val;
  445. }
  446. /**
  447. * @return int
  448. */
  449. public function getGitHubStars()
  450. {
  451. return $this->gitHubStars;
  452. }
  453. /**
  454. * @param int $val
  455. */
  456. public function setGitHubWatches($val)
  457. {
  458. $this->gitHubWatches = $val;
  459. }
  460. /**
  461. * @return int
  462. */
  463. public function getGitHubWatches()
  464. {
  465. return $this->gitHubWatches;
  466. }
  467. /**
  468. * @param int $val
  469. */
  470. public function setGitHubForks($val)
  471. {
  472. $this->gitHubForks = $val;
  473. }
  474. /**
  475. * @return int
  476. */
  477. public function getGitHubForks()
  478. {
  479. return $this->gitHubForks;
  480. }
  481. /**
  482. * @param int $val
  483. */
  484. public function setGitHubOpenIssues($val)
  485. {
  486. $this->gitHubOpenIssues = $val;
  487. }
  488. /**
  489. * @return int
  490. */
  491. public function getGitHubOpenIssues()
  492. {
  493. return $this->gitHubOpenIssues;
  494. }
  495. /**
  496. * Set createdAt
  497. *
  498. * @param \DateTime $createdAt
  499. */
  500. public function setCreatedAt($createdAt)
  501. {
  502. $this->createdAt = $createdAt;
  503. }
  504. /**
  505. * Get createdAt
  506. *
  507. * @return \DateTime
  508. */
  509. public function getCreatedAt()
  510. {
  511. return $this->createdAt;
  512. }
  513. /**
  514. * Set repository
  515. *
  516. * @param string $repository
  517. */
  518. public function setRepository($repoUrl)
  519. {
  520. $this->vcsDriver = null;
  521. // prevent local filesystem URLs
  522. if (preg_match('{^(\.|[a-z]:|/)}i', $repoUrl)) {
  523. return;
  524. }
  525. $repoUrl = preg_replace('{^git@github.com:}i', 'https://github.com/', $repoUrl);
  526. $repoUrl = preg_replace('{^git://github.com/}i', 'https://github.com/', $repoUrl);
  527. $repoUrl = preg_replace('{^(https://github.com/.*?)\.git$}i', '$1', $repoUrl);
  528. // normalize protocol case
  529. $repoUrl = preg_replace_callback('{^(https?|git|svn)://}i', function ($match) { return strtolower($match[1]) . '://'; }, $repoUrl);
  530. $this->repository = $repoUrl;
  531. // avoid user@host URLs
  532. if (preg_match('{https?://.+@}', $repoUrl)) {
  533. return;
  534. }
  535. try {
  536. $io = new NullIO();
  537. $config = Factory::createConfig();
  538. $io->loadConfiguration($config);
  539. $repository = new VcsRepository(array('url' => $this->repository), $io, $config);
  540. $driver = $this->vcsDriver = $repository->getDriver();
  541. if (!$driver) {
  542. return;
  543. }
  544. $information = $driver->getComposerInformation($driver->getRootIdentifier());
  545. if (!isset($information['name'])) {
  546. return;
  547. }
  548. if (null === $this->getName()) {
  549. $this->setName(trim($information['name']));
  550. }
  551. if ($driver instanceof GitHubDriver) {
  552. $this->repository = $driver->getRepositoryUrl();
  553. }
  554. } catch (\Exception $e) {
  555. $this->vcsDriverError = '['.get_class($e).'] '.$e->getMessage();
  556. }
  557. }
  558. /**
  559. * Get repository
  560. *
  561. * @return string $repository
  562. */
  563. public function getRepository()
  564. {
  565. return $this->repository;
  566. }
  567. /**
  568. * Get a user-browsable version of the repository URL
  569. *
  570. * @return string $repository
  571. */
  572. public function getBrowsableRepository()
  573. {
  574. if (preg_match('{(://|@)bitbucket.org[:/]}i', $this->repository)) {
  575. return preg_replace('{^(?:git@|https://|git://)bitbucket.org[:/](.+?)(?:\.git)?$}i', 'https://bitbucket.org/$1', $this->repository);
  576. }
  577. return preg_replace('{^(git://github.com/|git@github.com:)}', 'https://github.com/', $this->repository);
  578. }
  579. /**
  580. * Add versions
  581. *
  582. * @param Version $versions
  583. */
  584. public function addVersions(Version $versions)
  585. {
  586. $this->versions[] = $versions;
  587. }
  588. /**
  589. * Get versions
  590. *
  591. * @return \Doctrine\Common\Collections\Collection
  592. */
  593. public function getVersions()
  594. {
  595. return $this->versions;
  596. }
  597. public function getVersion($normalizedVersion)
  598. {
  599. if (null === $this->cachedVersions) {
  600. $this->cachedVersions = array();
  601. foreach ($this->getVersions() as $version) {
  602. $this->cachedVersions[strtolower($version->getNormalizedVersion())] = $version;
  603. }
  604. }
  605. if (isset($this->cachedVersions[strtolower($normalizedVersion)])) {
  606. return $this->cachedVersions[strtolower($normalizedVersion)];
  607. }
  608. }
  609. /**
  610. * Set updatedAt
  611. *
  612. * @param \DateTime $updatedAt
  613. */
  614. public function setUpdatedAt($updatedAt)
  615. {
  616. $this->updatedAt = $updatedAt;
  617. $this->setUpdateFailureNotified(false);
  618. }
  619. /**
  620. * Get updatedAt
  621. *
  622. * @return \DateTime
  623. */
  624. public function getUpdatedAt()
  625. {
  626. return $this->updatedAt;
  627. }
  628. /**
  629. * Set crawledAt
  630. *
  631. * @param \DateTime|null $crawledAt
  632. */
  633. public function setCrawledAt($crawledAt)
  634. {
  635. $this->crawledAt = $crawledAt;
  636. }
  637. /**
  638. * Get crawledAt
  639. *
  640. * @return \DateTime
  641. */
  642. public function getCrawledAt()
  643. {
  644. return $this->crawledAt;
  645. }
  646. /**
  647. * Set indexedAt
  648. *
  649. * @param \DateTime $indexedAt
  650. */
  651. public function setIndexedAt($indexedAt)
  652. {
  653. $this->indexedAt = $indexedAt;
  654. }
  655. /**
  656. * Get indexedAt
  657. *
  658. * @return \DateTime
  659. */
  660. public function getIndexedAt()
  661. {
  662. return $this->indexedAt;
  663. }
  664. /**
  665. * Set dumpedAt
  666. *
  667. * @param \DateTime $dumpedAt
  668. */
  669. public function setDumpedAt($dumpedAt)
  670. {
  671. $this->dumpedAt = $dumpedAt;
  672. }
  673. /**
  674. * Get dumpedAt
  675. *
  676. * @return \DateTime
  677. */
  678. public function getDumpedAt()
  679. {
  680. return $this->dumpedAt;
  681. }
  682. /**
  683. * Add maintainers
  684. *
  685. * @param User $maintainer
  686. */
  687. public function addMaintainer(User $maintainer)
  688. {
  689. $this->maintainers[] = $maintainer;
  690. }
  691. /**
  692. * Get maintainers
  693. *
  694. * @return \Doctrine\Common\Collections\Collection
  695. */
  696. public function getMaintainers()
  697. {
  698. return $this->maintainers;
  699. }
  700. /**
  701. * Set type
  702. *
  703. * @param string $type
  704. */
  705. public function setType($type)
  706. {
  707. $this->type = $type;
  708. }
  709. /**
  710. * Get type
  711. *
  712. * @return string
  713. */
  714. public function getType()
  715. {
  716. return $this->type;
  717. }
  718. /**
  719. * Set autoUpdated
  720. *
  721. * @param int $autoUpdated
  722. */
  723. public function setAutoUpdated($autoUpdated)
  724. {
  725. $this->autoUpdated = $autoUpdated;
  726. }
  727. /**
  728. * Get autoUpdated
  729. *
  730. * @return int
  731. */
  732. public function getAutoUpdated()
  733. {
  734. return $this->autoUpdated;
  735. }
  736. /**
  737. * Get autoUpdated
  738. *
  739. * @return Boolean
  740. */
  741. public function isAutoUpdated()
  742. {
  743. return $this->autoUpdated > 0;
  744. }
  745. /**
  746. * Set updateFailureNotified
  747. *
  748. * @param Boolean $updateFailureNotified
  749. */
  750. public function setUpdateFailureNotified($updateFailureNotified)
  751. {
  752. $this->updateFailureNotified = $updateFailureNotified;
  753. }
  754. /**
  755. * Get updateFailureNotified
  756. *
  757. * @return Boolean
  758. */
  759. public function isUpdateFailureNotified()
  760. {
  761. return $this->updateFailureNotified;
  762. }
  763. /**
  764. * @return boolean
  765. */
  766. public function isAbandoned()
  767. {
  768. return $this->abandoned;
  769. }
  770. /**
  771. * @param boolean $abandoned
  772. */
  773. public function setAbandoned($abandoned)
  774. {
  775. $this->abandoned = $abandoned;
  776. }
  777. /**
  778. * @return string
  779. */
  780. public function getReplacementPackage()
  781. {
  782. return $this->replacementPackage;
  783. }
  784. /**
  785. * @param string $replacementPackage
  786. */
  787. public function setReplacementPackage($replacementPackage)
  788. {
  789. $this->replacementPackage = $replacementPackage;
  790. }
  791. public static function sortVersions($a, $b)
  792. {
  793. $aVersion = $a->getNormalizedVersion();
  794. $bVersion = $b->getNormalizedVersion();
  795. $aVersion = preg_replace('{^dev-.*}', '0.0.0-alpha', $aVersion);
  796. $bVersion = preg_replace('{^dev-.*}', '0.0.0-alpha', $bVersion);
  797. // equal versions are sorted by date
  798. if ($aVersion === $bVersion) {
  799. return $b->getReleasedAt() > $a->getReleasedAt() ? 1 : -1;
  800. }
  801. // the rest is sorted by version
  802. return version_compare($bVersion, $aVersion);
  803. }
  804. }