-
Notifications
You must be signed in to change notification settings - Fork 1
/
Test.php
47 lines (34 loc) · 1.41 KB
/
Test.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
<?php
/**
* Dit is een probeersel om een nieuwe bulk import helper te maken.
*/
// Contains all the vehicles
$vehicles = [/*...*/];
$bulkImport = $this->get('media_library_importer.helper.bulk_import')->createNewBulkImport();
foreach ($vehicles as $vehicle) {
$bulkImport->addMediaGroup($vehicle->getMediaGroup());
if ($vehicle->exists()) {
// Create import for existing media group
$mediaGroupImportCommand = new CreateImportForExistingMediaGroup($vehicle->getMediaGroup());
} else {
// Create import for new media group
$mediaGroupImportCommand = new CreateImportForNewMediaGroup(Backend\Modules\MediaLibrary\Domain\MediaGroup\Type::image());
}
foreach ($vehicle->getImages() as $sequence => $image) {
$mediaGroupImportCommand->add(
new MediaItemImportDataTransferObject(
$image->path,
$sequence,
Method::copy(), // Other possible values are; Method::move() or Method::download()
$image->title // Optionally
);
);
}
// Handle the MediaGroupImport Update
$this->get('command_bus')->handle($mediaGroupImportCommand);
}
// Handle the bulk import
$this->get('command_bus')->handle($bulkImport);
// Todo: loop bulk import to setMediaGroup to vehicle
// We can now set the $mediaGroup in our vehicle
$vehicle->setMediaGroup($mediaGroupImportCommand->getMediaGroup());