1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Loevgaard\DandomainFoundation\Entity; |
4
|
|
|
|
5
|
|
|
use Assert\Assert; |
6
|
|
|
use Doctrine\ORM\Mapping as ORM; |
7
|
|
|
use Knp\DoctrineBehaviors\Model\Timestampable\Timestampable; |
8
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\QueueItemInterface; |
|
|
|
|
9
|
|
|
use Loevgaard\DandomainFoundation\Entity\Generated\QueueItemTrait; |
|
|
|
|
10
|
|
|
|
11
|
|
|
/** |
12
|
|
|
* This entity represent a queue item which is queued for synchronization. |
13
|
|
|
* |
14
|
|
|
* @ORM\Entity() |
15
|
|
|
* @ORM\Table(name="ldf_queue", indexes={@ORM\Index(columns={"type"})}) |
16
|
|
|
* @ORM\HasLifecycleCallbacks() |
17
|
|
|
*/ |
18
|
|
|
class QueueItem implements QueueItemInterface |
19
|
|
|
{ |
20
|
|
|
use QueueItemTrait; |
21
|
|
|
use Timestampable; |
22
|
|
|
|
23
|
|
|
const TYPE_ORDER = 'order'; |
24
|
|
|
const TYPE_PRODUCT = 'product'; |
25
|
|
|
|
26
|
|
|
const STATUS_PENDING = 'pending'; |
27
|
|
|
const STATUS_PROCESSING = 'processing'; |
28
|
|
|
const STATUS_ERROR = 'error'; |
29
|
|
|
const STATUS_SUCCESS = 'success'; |
30
|
|
|
|
31
|
|
|
/** |
32
|
|
|
* @var int |
33
|
|
|
* |
34
|
|
|
* @ORM\Id |
35
|
|
|
* @ORM\GeneratedValue |
36
|
|
|
* @ORM\Column(type="integer") |
37
|
|
|
**/ |
38
|
|
|
protected $id; |
39
|
|
|
|
40
|
|
|
/** |
41
|
|
|
* @var string |
42
|
|
|
* |
43
|
|
|
* @ORM\Column(type="string", length=191) |
44
|
|
|
*/ |
45
|
|
|
protected $identifier; |
46
|
|
|
|
47
|
|
|
/** |
48
|
|
|
* @var string |
49
|
|
|
* |
50
|
|
|
* @ORM\Column(name="`type`", type="string", length=191) |
51
|
|
|
*/ |
52
|
|
|
protected $type; |
53
|
|
|
|
54
|
|
|
/** |
55
|
|
|
* @var string |
56
|
|
|
* |
57
|
|
|
* @ORM\Column(type="string", length=191) |
58
|
|
|
*/ |
59
|
|
|
protected $status; |
60
|
|
|
|
61
|
|
|
/** |
62
|
|
|
* @var string|null |
63
|
|
|
* |
64
|
|
|
* @ORM\Column(type="text", nullable=true) |
65
|
|
|
*/ |
66
|
|
|
protected $error; |
67
|
|
|
|
68
|
|
|
public function __construct() |
69
|
|
|
{ |
70
|
|
|
$this->status = self::STATUS_PENDING; |
71
|
|
|
} |
72
|
|
|
|
73
|
|
|
/** |
74
|
|
|
* @ORM\PrePersist() |
75
|
|
|
* @ORM\PreUpdate() |
76
|
|
|
*/ |
77
|
|
|
public function validate() |
78
|
|
|
{ |
79
|
|
|
Assert::that($this->identifier)->string()->minLength(1)->maxLength(191); |
80
|
|
|
Assert::that($this->type)->choice(self::getTypes()); |
81
|
|
|
Assert::that($this->status)->choice(self::getStatuses()); |
82
|
|
|
} |
83
|
|
|
|
84
|
|
|
public static function getTypes(): array |
85
|
|
|
{ |
86
|
|
|
return [ |
87
|
|
|
self::TYPE_ORDER => self::TYPE_ORDER, |
88
|
|
|
self::TYPE_PRODUCT => self::TYPE_PRODUCT, |
89
|
|
|
]; |
90
|
|
|
} |
91
|
|
|
|
92
|
|
|
public static function getStatuses(): array |
93
|
|
|
{ |
94
|
|
|
return [ |
95
|
|
|
self::STATUS_PENDING => self::STATUS_PENDING, |
96
|
|
|
self::STATUS_PROCESSING => self::STATUS_PROCESSING, |
97
|
|
|
self::STATUS_ERROR => self::STATUS_ERROR, |
98
|
|
|
self::STATUS_SUCCESS => self::STATUS_SUCCESS, |
99
|
|
|
]; |
100
|
|
|
} |
101
|
|
|
|
102
|
|
|
/** |
103
|
|
|
* The create method creates a valid queue item object. |
104
|
|
|
* |
105
|
|
|
* @param string $identifier |
106
|
|
|
* @param string $type |
107
|
|
|
* |
108
|
|
|
* @return QueueItemInterface |
109
|
|
|
*/ |
110
|
|
|
public static function create(string $identifier, string $type): QueueItemInterface |
111
|
|
|
{ |
112
|
|
|
$queueItem = new self(); |
113
|
|
|
$queueItem |
114
|
|
|
->setIdentifier($identifier) |
115
|
|
|
->setType($type); |
116
|
|
|
|
117
|
|
|
return $queueItem; |
118
|
|
|
} |
119
|
|
|
|
120
|
|
|
/** |
121
|
|
|
* @return int |
122
|
|
|
*/ |
123
|
|
|
public function getId(): int |
124
|
|
|
{ |
125
|
|
|
return (int) $this->id; |
126
|
|
|
} |
127
|
|
|
|
128
|
|
|
/** |
129
|
|
|
* @param int $id |
130
|
|
|
* |
131
|
|
|
* @return QueueItem |
132
|
|
|
*/ |
133
|
|
|
public function setId(int $id) |
134
|
|
|
{ |
135
|
|
|
$this->id = $id; |
136
|
|
|
|
137
|
|
|
return $this; |
138
|
|
|
} |
139
|
|
|
|
140
|
|
|
/** |
141
|
|
|
* @return string |
142
|
|
|
*/ |
143
|
|
|
public function getIdentifier(): string |
144
|
|
|
{ |
145
|
|
|
return (string) $this->identifier; |
146
|
|
|
} |
147
|
|
|
|
148
|
|
|
/** |
149
|
|
|
* @param string $identifier |
150
|
|
|
* |
151
|
|
|
* @return QueueItem |
152
|
|
|
*/ |
153
|
|
|
public function setIdentifier(string $identifier) |
154
|
|
|
{ |
155
|
|
|
$this->identifier = $identifier; |
156
|
|
|
|
157
|
|
|
return $this; |
158
|
|
|
} |
159
|
|
|
|
160
|
|
|
/** |
161
|
|
|
* @return string |
162
|
|
|
*/ |
163
|
|
|
public function getType(): string |
164
|
|
|
{ |
165
|
|
|
return (string) $this->type; |
166
|
|
|
} |
167
|
|
|
|
168
|
|
|
/** |
169
|
|
|
* @param string $type |
170
|
|
|
* |
171
|
|
|
* @return QueueItem |
172
|
|
|
*/ |
173
|
|
|
public function setType(string $type) |
174
|
|
|
{ |
175
|
|
|
$this->type = $type; |
176
|
|
|
|
177
|
|
|
return $this; |
178
|
|
|
} |
179
|
|
|
|
180
|
|
|
/** |
181
|
|
|
* @return string |
182
|
|
|
*/ |
183
|
|
|
public function getStatus(): string |
184
|
|
|
{ |
185
|
|
|
return (string) $this->status; |
186
|
|
|
} |
187
|
|
|
|
188
|
|
|
/** |
189
|
|
|
* @param string $status |
190
|
|
|
* |
191
|
|
|
* @return QueueItem |
192
|
|
|
*/ |
193
|
|
|
public function setStatus(string $status) |
194
|
|
|
{ |
195
|
|
|
$this->status = $status; |
196
|
|
|
|
197
|
|
|
return $this; |
198
|
|
|
} |
199
|
|
|
} |
200
|
|
|
|
The issue could also be caused by a filter entry in the build configuration. If the path has been excluded in your configuration, e.g.
excluded_paths: ["lib/*"]
, you can move it to the dependency path list as follows:For further information see https://scrutinizer-ci.com/docs/tools/php/php-scrutinizer/#list-dependency-paths