SecurityAdvisory.php 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  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()
  7. * @ORM\Table(
  8. * name="security_advisory",
  9. * uniqueConstraints={@ORM\UniqueConstraint(name="source_packagename_idx", columns={"source","packageName"})},
  10. * indexes={
  11. * @ORM\Index(name="package_name_idx",columns={"packageName"})
  12. * }
  13. * )
  14. */
  15. class SecurityAdvisory
  16. {
  17. /**
  18. * @ORM\Id
  19. * @ORM\Column(type="integer")
  20. * @ORM\GeneratedValue(strategy="AUTO")
  21. */
  22. private $id;
  23. /**
  24. * @ORM\Column(type="string")
  25. */
  26. private $remoteId;
  27. /**
  28. * @ORM\Column(type="string")
  29. */
  30. private $packageName;
  31. /**
  32. * @ORM\Column(type="string")
  33. */
  34. private $title;
  35. /**
  36. * @ORM\Column(type="string", nullable=true)
  37. */
  38. private $link;
  39. /**
  40. * @ORM\Column(type="string", nullable=true)
  41. */
  42. private $cve;
  43. /**
  44. * @ORM\Column(type="string")
  45. */
  46. private $affectedVersions;
  47. /**
  48. * @ORM\Column(type="string")
  49. */
  50. private $source;
  51. public function __construct(RemoteSecurityAdvisory $advisory, string $source)
  52. {
  53. $this->source = $source;
  54. $this->updateAdvisory($advisory);
  55. }
  56. public function updateAdvisory(RemoteSecurityAdvisory $advisory): void
  57. {
  58. $this->remoteId = $advisory->getId();
  59. $this->packageName = $advisory->getPackageName();
  60. $this->title = $advisory->getTitle();
  61. $this->link = $advisory->getLink();
  62. $this->cve = $advisory->getCve();
  63. $this->affectedVersions = $advisory->getAffectedVersions();
  64. }
  65. public function getRemoteId(): string
  66. {
  67. return $this->remoteId;
  68. }
  69. }