src/JanusHercules/HighVolumeProcess/Domain/Entity/HighVolumeProcessTask.php line 22

Open in your IDE?
  1. <?php
  2. namespace JanusHercules\HighVolumeProcess\Domain\Entity;
  3. use App\Utility\DatabaseIdGenerator;
  4. use App\Utility\DateTimeUtility;
  5. use DateTime;
  6. use Doctrine\DBAL\Types\Types;
  7. use Doctrine\ORM\Mapping as ORM;
  8. use Exception;
  9. use ValueError;
  10. #[ORM\Entity]
  11. #[ORM\Table(name: 'high_volume_process_tasks')]
  12. #[ORM\UniqueConstraint(
  13. name : 'unique_process_item',
  14. columns: ['high_volume_processes_id', 'item_id']
  15. )]
  16. #[ORM\Index(columns: ['high_volume_processes_id'], name: 'IDX_D76C3F96CE20091')]
  17. #[ORM\Index(columns: ['high_volume_processes_id', 'finished_at', 'error_message'], name: 'idx_task_status')]
  18. #[ORM\Index(columns: ['finished_at'], name: 'idx_task_finished')]
  19. class HighVolumeProcessTask
  20. {
  21. /**
  22. * @throws Exception
  23. */
  24. public function __construct(
  25. HighVolumeProcess $process,
  26. string $itemId
  27. ) {
  28. if (mb_strlen($itemId) > 128) {
  29. throw new ValueError('The itemId cannot exceed 128 characters.');
  30. }
  31. $this->process = $process;
  32. $this->itemId = $itemId;
  33. $this->createdAt = DateTimeUtility::createDateTimeUtc();
  34. }
  35. #[ORM\Id]
  36. #[ORM\GeneratedValue(strategy: 'CUSTOM')]
  37. #[ORM\CustomIdGenerator(class: DatabaseIdGenerator::class)]
  38. #[ORM\Column(
  39. type : Types::GUID,
  40. unique: true
  41. )]
  42. private ?string $id = null;
  43. public function getId(): ?string
  44. {
  45. return $this->id;
  46. }
  47. #[ORM\ManyToOne(
  48. targetEntity: HighVolumeProcess::class
  49. )]
  50. #[ORM\JoinColumn(
  51. name : 'high_volume_processes_id',
  52. referencedColumnName: 'id',
  53. nullable : false,
  54. onDelete : 'CASCADE'
  55. )]
  56. private HighVolumeProcess $process;
  57. public function getProcess(): HighVolumeProcess
  58. {
  59. return $this->process;
  60. }
  61. #[ORM\Column(
  62. type: Types::DATETIME_MUTABLE
  63. )]
  64. private DateTime $createdAt;
  65. public function getCreatedAt(): DateTime
  66. {
  67. return $this->createdAt;
  68. }
  69. #[ORM\Column(
  70. type : Types::DATETIME_MUTABLE,
  71. nullable: true
  72. )]
  73. private ?DateTime $finishedAt = null;
  74. public function getFinishedAt(): ?DateTime
  75. {
  76. return $this->finishedAt;
  77. }
  78. public function setFinishedAt(DateTime $finishedAt): void
  79. {
  80. $this->finishedAt = $finishedAt;
  81. }
  82. #[ORM\Column(
  83. type : Types::TEXT,
  84. nullable: true
  85. )]
  86. private ?string $errorMessage = null;
  87. public function getErrorMessage(): ?string
  88. {
  89. return $this->errorMessage;
  90. }
  91. public function setErrorMessage(string $errorMessage): void
  92. {
  93. $this->errorMessage = mb_substr($errorMessage, 0, 1024);
  94. }
  95. #[ORM\Column(
  96. type : Types::STRING,
  97. length : 128,
  98. nullable: false
  99. )]
  100. private string $itemId;
  101. public function getItemId(): string
  102. {
  103. return $this->itemId;
  104. }
  105. #[ORM\Column(
  106. type : Types::STRING,
  107. length : 512,
  108. nullable: true
  109. )]
  110. private ?string $resultValue = null;
  111. public function getResultValue(): ?string
  112. {
  113. return $this->resultValue;
  114. }
  115. public function setResultValue(string $resultValue): void
  116. {
  117. if (mb_strlen($resultValue) > 512) {
  118. throw new ValueError('The resultValue cannot exceed 512 characters.');
  119. }
  120. $this->resultValue = $resultValue;
  121. }
  122. }