SecurityAdvisory.php 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145
  1. <?php declare(strict_types=1);
  2. namespace Packagist\WebBundle\Entity;
  3. use Doctrine\ORM\Mapping as ORM;
  4. use Packagist\WebBundle\SecurityAdvisory\RemoteSecurityAdvisory;
  5. /**
  6. * @ORM\Entity(repositoryClass="Packagist\WebBundle\Entity\SecurityAdvisoryRepository")
  7. * @ORM\Table(
  8. * name="security_advisory",
  9. * uniqueConstraints={@ORM\UniqueConstraint(name="source_remoteid_idx", columns={"source","remoteId"})},
  10. * indexes={
  11. * @ORM\Index(name="package_name_idx",columns={"packageName"}),
  12. * @ORM\Index(name="updated_at_idx",columns={"updatedAt"})
  13. * }
  14. * )
  15. */
  16. class SecurityAdvisory
  17. {
  18. public const PACKAGIST_ORG = 'https://packagist.org';
  19. /**
  20. * @ORM\Id
  21. * @ORM\Column(type="integer")
  22. * @ORM\GeneratedValue(strategy="AUTO")
  23. */
  24. private $id;
  25. /**
  26. * @ORM\Column(type="string")
  27. */
  28. private $remoteId;
  29. /**
  30. * @ORM\Column(type="string")
  31. */
  32. private $packageName;
  33. /**
  34. * @ORM\Column(type="string")
  35. */
  36. private $title;
  37. /**
  38. * @ORM\Column(type="string", nullable=true)
  39. */
  40. private $link;
  41. /**
  42. * @ORM\Column(type="string", nullable=true)
  43. */
  44. private $cve;
  45. /**
  46. * @ORM\Column(type="text")
  47. */
  48. private $affectedVersions;
  49. /**
  50. * @ORM\Column(type="string")
  51. */
  52. private $source;
  53. /**
  54. * @ORM\Column(type="datetime")
  55. */
  56. private $reportedAt;
  57. /**
  58. * @ORM\Column(type="datetime")
  59. */
  60. private $updatedAt;
  61. /**
  62. * @ORM\Column(type="string", nullable=true)
  63. */
  64. private $composerRepository;
  65. public function __construct(RemoteSecurityAdvisory $advisory, string $source)
  66. {
  67. $this->source = $source;
  68. $this->updateAdvisory($advisory);
  69. }
  70. public function updateAdvisory(RemoteSecurityAdvisory $advisory): void
  71. {
  72. if (
  73. $this->remoteId !== $advisory->getId() ||
  74. $this->packageName !== $advisory->getPackageName() ||
  75. $this->title !== $advisory->getTitle() ||
  76. $this->link !== $advisory->getLink() ||
  77. $this->cve !== $advisory->getCve() ||
  78. $this->affectedVersions !== $advisory->getAffectedVersions() ||
  79. $this->reportedAt != $advisory->getDate() ||
  80. $this->composerRepository !== $advisory->getComposerRepository()
  81. ) {
  82. $this->updatedAt = new \DateTime();
  83. $this->reportedAt = $advisory->getDate();
  84. }
  85. $this->remoteId = $advisory->getId();
  86. $this->packageName = $advisory->getPackageName();
  87. $this->title = $advisory->getTitle();
  88. $this->link = $advisory->getLink();
  89. $this->cve = $advisory->getCve();
  90. $this->affectedVersions = $advisory->getAffectedVersions();
  91. $this->composerRepository = $advisory->getComposerRepository();
  92. }
  93. public function getRemoteId(): string
  94. {
  95. return $this->remoteId;
  96. }
  97. public function getPackageName(): string
  98. {
  99. return $this->packageName;
  100. }
  101. public function getTitle(): string
  102. {
  103. return $this->title;
  104. }
  105. public function getLink(): ?string
  106. {
  107. return $this->link;
  108. }
  109. public function getCve(): ?string
  110. {
  111. return $this->cve;
  112. }
  113. public function getAffectedVersions(): string
  114. {
  115. return $this->affectedVersions;
  116. }
  117. public function getSource(): string
  118. {
  119. return $this->source;
  120. }
  121. }