1
|
|
|
<?php |
2
|
|
|
|
3
|
|
|
namespace Backend\Modules\MediaLibraryImporter\Domain\MediaItemImport; |
4
|
|
|
|
5
|
|
|
use Backend\Modules\MediaLibrary\Domain\MediaFolder\MediaFolder; |
6
|
|
|
use Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup; |
7
|
|
|
use Backend\Modules\MediaLibrary\Domain\MediaItem\MediaItem; |
8
|
|
|
use Doctrine\ORM\Mapping as ORM; |
9
|
|
|
|
10
|
|
|
/** |
11
|
|
|
* MediaItemImport |
12
|
|
|
* |
13
|
|
|
* @ORM\Entity(repositoryClass="Backend\Modules\MediaLibraryImporter\Domain\MediaItemImport\MediaItemImportRepository") |
14
|
|
|
* @ORM\HasLifecycleCallbacks |
15
|
|
|
*/ |
16
|
|
|
class MediaItemImport |
17
|
|
|
{ |
18
|
|
|
/** |
19
|
|
|
* @var string |
20
|
|
|
* |
21
|
|
|
* @ORM\Id() |
22
|
|
|
* @ORM\GeneratedValue(strategy="UUID") |
23
|
|
|
* @ORM\Column(type="guid") |
24
|
|
|
*/ |
25
|
|
|
protected $id; |
26
|
|
|
|
27
|
|
|
/** |
28
|
|
|
* @var Status |
29
|
|
|
* |
30
|
|
|
* @ORM\Column(type="media_item_import_status") |
31
|
|
|
*/ |
32
|
|
|
protected $status; |
33
|
|
|
|
34
|
|
|
/** |
35
|
|
|
* @var Method |
36
|
|
|
* |
37
|
|
|
* @ORM\Column(type="media_item_import_method") |
38
|
|
|
*/ |
39
|
|
|
protected $method; |
40
|
|
|
|
41
|
|
|
/** |
42
|
|
|
* @var int |
43
|
|
|
* |
44
|
|
|
* @ORM\Column(type="integer") |
45
|
|
|
*/ |
46
|
|
|
protected $sequence; |
47
|
|
|
|
48
|
|
|
/** |
49
|
|
|
* @var string |
50
|
|
|
* |
51
|
|
|
* @ORM\Column(type="string") |
52
|
|
|
*/ |
53
|
|
|
protected $path; |
54
|
|
|
|
55
|
|
|
/** |
56
|
|
|
* @var string|null |
57
|
|
|
* |
58
|
|
|
* @ORM\Column(type="string", nullable=true) |
59
|
|
|
*/ |
60
|
|
|
protected $title; |
61
|
|
|
|
62
|
|
|
/** |
63
|
|
|
* @var MediaGroup |
64
|
|
|
* |
65
|
|
|
* @ORM\ManyToOne( |
66
|
|
|
* targetEntity="Backend\Modules\MediaLibrary\Domain\MediaGroup\MediaGroup", |
67
|
|
|
* cascade="persist", |
68
|
|
|
* fetch="EAGER" |
69
|
|
|
* ) |
70
|
|
|
* @ORM\JoinColumn( |
71
|
|
|
* name="mediaGroupId", |
72
|
|
|
* referencedColumnName="id", |
73
|
|
|
* onDelete="cascade", |
74
|
|
|
* nullable=false |
75
|
|
|
* ) |
76
|
|
|
*/ |
77
|
|
|
protected $mediaGroup; |
78
|
|
|
|
79
|
|
|
/** |
80
|
|
|
* @var MediaItem|null |
81
|
|
|
* |
82
|
|
|
* @ORM\ManyToOne( |
83
|
|
|
* targetEntity="Backend\Modules\MediaLibrary\Domain\MediaItem\MediaItem", |
84
|
|
|
* cascade="persist" |
85
|
|
|
* ) |
86
|
|
|
* @ORM\JoinColumn( |
87
|
|
|
* name="mediaItemId", |
88
|
|
|
* referencedColumnName="id", |
89
|
|
|
* onDelete="cascade" |
90
|
|
|
* ) |
91
|
|
|
*/ |
92
|
|
|
protected $mediaItem; |
93
|
|
|
|
94
|
|
|
/** |
95
|
|
|
* @var \DateTime |
96
|
|
|
* |
97
|
|
|
* @ORM\Column(type="datetime") |
98
|
|
|
*/ |
99
|
|
|
protected $createdOn; |
100
|
|
|
|
101
|
|
|
/** |
102
|
|
|
* @var \DateTime |
103
|
|
|
* |
104
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
105
|
|
|
*/ |
106
|
|
|
protected $executedOn; |
107
|
|
|
|
108
|
|
|
/** |
109
|
|
|
* @var \DateTime |
110
|
|
|
* |
111
|
|
|
* @ORM\Column(type="datetime", nullable=true) |
112
|
|
|
*/ |
113
|
|
|
protected $importedOn; |
114
|
|
|
|
115
|
|
|
/** |
116
|
|
|
* @var string |
117
|
|
|
* |
118
|
|
|
* @ORM\Column(type="text", nullable=true) |
119
|
|
|
*/ |
120
|
|
|
protected $errorMessage; |
121
|
|
|
|
122
|
|
|
/** |
123
|
|
|
* @param MediaGroup $mediaGroup |
124
|
|
|
* @param string $path |
125
|
|
|
* @param int $sequence |
126
|
|
|
* @param Method $method |
127
|
|
|
* @param string $title |
128
|
|
|
*/ |
129
|
|
|
private function __construct( |
130
|
|
|
MediaGroup $mediaGroup, |
131
|
|
|
string $path, |
132
|
|
|
int $sequence, |
133
|
|
|
Method $method, |
134
|
|
|
string $title = null |
135
|
|
|
) { |
136
|
|
|
$this->mediaGroup = $mediaGroup; |
137
|
|
|
$this->path = $path; |
138
|
|
|
$this->sequence = $sequence; |
139
|
|
|
$this->method = $method; |
140
|
|
|
$this->title = $title; |
141
|
|
|
} |
142
|
|
|
|
143
|
|
|
/** |
144
|
|
|
* @param MediaItemImportDataTransferObject $mediaItemDataTransferObject |
145
|
|
|
* @return MediaItemImport |
146
|
|
|
*/ |
147
|
|
|
public static function fromDataTransferObject( |
148
|
|
|
MediaItemImportDataTransferObject $mediaItemDataTransferObject |
149
|
|
|
): MediaItemImport { |
150
|
|
|
return new self( |
151
|
|
|
$mediaItemDataTransferObject->getMediaGroup(), |
152
|
|
|
$mediaItemDataTransferObject->path, |
153
|
|
|
$mediaItemDataTransferObject->sequence, |
154
|
|
|
$mediaItemDataTransferObject->method, |
155
|
|
|
$mediaItemDataTransferObject->title |
156
|
|
|
); |
157
|
|
|
} |
158
|
|
|
|
159
|
|
|
/** |
160
|
|
|
* Gets the value of id. |
161
|
|
|
* |
162
|
|
|
* @return string |
163
|
|
|
*/ |
164
|
|
|
public function getId(): string |
165
|
|
|
{ |
166
|
|
|
return $this->id; |
167
|
|
|
} |
168
|
|
|
|
169
|
|
|
/** |
170
|
|
|
* @return Status |
171
|
|
|
*/ |
172
|
|
|
public function getStatus(): Status |
173
|
|
|
{ |
174
|
|
|
return $this->status; |
175
|
|
|
} |
176
|
|
|
|
177
|
|
|
/** |
178
|
|
|
* @param string $errorMessage |
179
|
|
|
*/ |
180
|
|
|
public function changeStatusToError(string $errorMessage) |
181
|
|
|
{ |
182
|
|
|
$this->errorMessage = $errorMessage; |
183
|
|
|
$this->status = Status::error(); |
184
|
|
|
} |
185
|
|
|
|
186
|
|
|
/** |
187
|
|
|
* @param MediaItem $mediaItem |
188
|
|
|
*/ |
189
|
|
|
public function changeStatusToExisting(MediaItem $mediaItem) |
190
|
|
|
{ |
191
|
|
|
$this->errorMessage = null; |
192
|
|
|
$this->mediaItem = $mediaItem; |
193
|
|
|
$this->status = Status::existing(); |
194
|
|
|
|
195
|
|
|
if ($this->title !== null && $this->title !== $mediaItem->getTitle()) { |
196
|
|
|
$mediaItem->setTitle($this->title); |
197
|
|
|
} |
198
|
|
|
} |
199
|
|
|
|
200
|
|
|
/** |
201
|
|
|
* @param string $path |
202
|
|
|
* @param MediaFolder $mediaFolder |
203
|
|
|
* @param int $userId |
204
|
|
|
*/ |
205
|
|
|
public function changeStatusToImported( |
206
|
|
|
string $path, |
207
|
|
|
MediaFolder $mediaFolder, |
208
|
|
|
int $userId |
209
|
|
|
) { |
210
|
|
|
$this->mediaItem = MediaItem::createFromLocalStorageType( |
211
|
|
|
$path, |
212
|
|
|
$mediaFolder, |
213
|
|
|
$userId |
214
|
|
|
); |
215
|
|
|
|
216
|
|
|
$this->errorMessage = null; |
217
|
|
|
$this->status = Status::imported(); |
218
|
|
|
$this->importedOn = new \Datetime(); |
219
|
|
|
} |
220
|
|
|
|
221
|
|
|
/** |
222
|
|
|
* @return Method |
223
|
|
|
*/ |
224
|
|
|
public function getMethod(): Method |
225
|
|
|
{ |
226
|
|
|
return $this->method; |
227
|
|
|
} |
228
|
|
|
|
229
|
|
|
/** |
230
|
|
|
* @return string |
231
|
|
|
*/ |
232
|
|
|
public function getPath(): string |
233
|
|
|
{ |
234
|
|
|
return $this->path; |
235
|
|
|
} |
236
|
|
|
|
237
|
|
|
/** |
238
|
|
|
* @return int |
239
|
|
|
*/ |
240
|
|
|
public function getSequence(): int |
241
|
|
|
{ |
242
|
|
|
return $this->sequence; |
243
|
|
|
} |
244
|
|
|
|
245
|
|
|
/** |
246
|
|
|
* Gets the value of createdOn. |
247
|
|
|
* |
248
|
|
|
* @return \DateTime |
249
|
|
|
*/ |
250
|
|
|
public function getCreatedOn(): \DateTime |
251
|
|
|
{ |
252
|
|
|
return $this->createdOn; |
253
|
|
|
} |
254
|
|
|
|
255
|
|
|
/** |
256
|
|
|
* @return \DateTime |
257
|
|
|
*/ |
258
|
|
|
public function getImportedOn(): \DateTime |
259
|
|
|
{ |
260
|
|
|
return $this->importedOn; |
261
|
|
|
} |
262
|
|
|
|
263
|
|
|
/** |
264
|
|
|
* @return \DateTime |
265
|
|
|
*/ |
266
|
|
|
public function getExecutedOn(): \DateTime |
267
|
|
|
{ |
268
|
|
|
return $this->executedOn; |
269
|
|
|
} |
270
|
|
|
|
271
|
|
|
/** |
272
|
|
|
* @return MediaGroup |
273
|
|
|
*/ |
274
|
|
|
public function getMediaGroup(): MediaGroup |
275
|
|
|
{ |
276
|
|
|
return $this->mediaGroup; |
277
|
|
|
} |
278
|
|
|
|
279
|
|
|
/** |
280
|
|
|
* @return MediaItem|null |
281
|
|
|
*/ |
282
|
|
|
public function getMediaItem() |
283
|
|
|
{ |
284
|
|
|
return $this->mediaItem; |
285
|
|
|
} |
286
|
|
|
|
287
|
|
|
/** |
288
|
|
|
* @return string|null |
289
|
|
|
*/ |
290
|
|
|
public function getTitle(): string |
291
|
|
|
{ |
292
|
|
|
return $this->title; |
293
|
|
|
} |
294
|
|
|
|
295
|
|
|
/** |
296
|
|
|
* @return string |
297
|
|
|
*/ |
298
|
|
|
public function getErrorMessage(): string |
299
|
|
|
{ |
300
|
|
|
return $this->errorMessage; |
301
|
|
|
} |
302
|
|
|
|
303
|
|
|
/** |
304
|
|
|
* @ORM\PrePersist |
305
|
|
|
*/ |
306
|
|
|
public function onPrePersist() |
307
|
|
|
{ |
308
|
|
|
$this->createdOn = new \Datetime(); |
309
|
|
|
} |
310
|
|
|
|
311
|
|
|
/** |
312
|
|
|
* @ORM\PreUpdate |
313
|
|
|
*/ |
314
|
|
|
public function onPreUpdate() |
315
|
|
|
{ |
316
|
|
|
$this->executedOn = new \Datetime(); |
317
|
|
|
} |
318
|
|
|
} |
319
|
|
|
|