Skip to content

Commit 8544d8b

Browse files
committed
[With or With IDs][Review] fix failing tests
1 parent fb75517 commit 8544d8b

File tree

6 files changed

+67
-28
lines changed

6 files changed

+67
-28
lines changed

composer.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@
1313
"require": {
1414
"php": "~8.1.0 || ~8.2.0 || ~8.3.0",
1515
"ext-zip": "*",
16-
"pimcore/pimcore": "^11.0",
16+
"pimcore/pimcore": "^11.5.4",
1717
"symfony/config": "^6.4",
1818
"symfony/console": "^6.4",
1919
"symfony/dependency-injection": "^6.4",

src/Import/EventSubscriber/ImportLoggingEventSubscriber.php

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,9 +17,9 @@ public function __construct(
1717
public static function getSubscribedEvents()
1818
{
1919
return [
20-
// ImportEvent::class => [
21-
// ['logImportEvent', 100],
22-
// ],
20+
ImportEvent::class => [
21+
['logImportEvent', 100],
22+
],
2323
];
2424
}
2525

src/Import/Importer.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,10 +78,10 @@ public function import(string $yamlInput, string $format, bool $forcedSave, bool
7878
$this->parentRelationResolver->resolve($result);
7979
try {
8080
$result->save(['versionNote' => 'created by pimcore-import-export-bundle']);
81+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::CREATED, $typeKey, $element, $result, null));
8182
} catch (\Exception $e) {
8283
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::FAILED, $typeKey, $element, $result, $oldElement, $e->getMessage()));
8384
}
84-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::CREATED, $typeKey, $element, $result, null));
8585
} elseif ($overwrite) {
8686
if ($this->newElementHasNoValidId($result) || $this->bothHaveSameId($oldElement, $result)) {
8787
// Update existing element by new one

src/Populator/PageImportPopulator.php

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,20 +30,20 @@ public function __construct(
3030
*/
3131
public function populate(object $target, object $source, ?object $ctx = null): void
3232
{
33-
if ($target instanceof PimcoreDocument\PageSnippet && \is_array($source['properties'])) {
34-
foreach ($source['properties'] as $property) {
35-
if ($property['value'] && 'asset' === $property['type']) {
36-
$value = $this->assetRepository->getByPath($property['value']);
37-
} elseif ($property['value'] && 'document' === $property['type']) {
38-
$value = $this->documentRepository->getByPath($property['value']);
39-
} elseif ($property['value'] && 'object' === $property['type']) {
40-
$value = $this->objectRepository->getByPath($property['value']);
41-
} else {
42-
$value = $property['value'];
43-
}
44-
$target->setProperty($property['key'], $property['type'], $value);
33+
foreach ($source['properties'] ?? [] as $property) {
34+
if ($property['value'] && 'asset' === $property['type']) {
35+
$value = $this->assetRepository->getByPath($property['value']);
36+
} elseif ($property['value'] && 'document' === $property['type']) {
37+
$value = $this->documentRepository->getByPath($property['value']);
38+
} elseif ($property['value'] && 'object' === $property['type']) {
39+
$value = $this->objectRepository->getByPath($property['value']);
40+
} else {
41+
$value = $property['value'];
4542
}
43+
$target->setProperty($property['key'], $property['type'], $value);
44+
}
4645

46+
if ($target instanceof PimcoreDocument\PageSnippet) {
4747
/** @var array{type: string, data: mixed} $editable */
4848
foreach ($source['editables'] ?? [] as $key => $editable) {
4949
if (!isset($editable['data'])) {

tests/Integration/Import/ImporterTest.php

Lines changed: 44 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -51,12 +51,22 @@ public function testSinglePageExport_regular_case_parent_id(): void
5151
type: email
5252
published: false
5353
path: /path/will/be/overwritten/by/parent_id/
54-
language: fr
55-
navigation_name: 'My Document'
56-
navigation_title: 'My Document - Title'
5754
key: test_document_1
5855
title: 'The Title of My Document'
5956
controller: /Some/Controller
57+
properties:
58+
language:
59+
type: string
60+
key: language
61+
value: fr
62+
navigation_name:
63+
type: string
64+
key: navigation_name
65+
value: 'My Document'
66+
navigation_title:
67+
type: string
68+
key: navigation_title
69+
value: 'My Document - Title'
6070
YAML;
6171

6272
$pages = $this->importer->import($yaml, 'yaml', true, true);
@@ -85,9 +95,6 @@ public function testSinglePageExport_regular_case_json(): void
8595
"type": "email",
8696
"published": false,
8797
"path": "\/path\/will\/be\/overwritten\/by\/parent_id/\/",
88-
"language": "fr",
89-
"navigation_name": "My Document",
90-
"navigation_title": "My Document - Title",
9198
"key": "test_document_1",
9299
"title": "The Title of My Document",
93100
"controller": "\/Some\/Controller",
@@ -97,7 +104,24 @@ public function testSinglePageExport_regular_case_json(): void
97104
"name": "textInput",
98105
"data": "some text input"
99106
}
100-
]
107+
],
108+
"properties": {
109+
"language": {
110+
"type": "string",
111+
"key": "language",
112+
"value": "fr"
113+
},
114+
"navigation_name": {
115+
"type": "string",
116+
"key": "navigation_name",
117+
"value": "My Document"
118+
},
119+
"navigation_title": {
120+
"type": "string",
121+
"key": "navigation_title",
122+
"value": "My Document - Title"
123+
}
124+
}
101125
}
102126
}
103127
]
@@ -129,12 +153,22 @@ public function testSinglePageExport_regular_case_path(): void
129153
type: email
130154
published: false
131155
path: /
132-
language: en
133-
navigation_name: 'My Document'
134-
navigation_title: 'My Document - Title'
135156
key: test_document_1
136157
title: 'The Title of My Document'
137158
controller: /Some/Controller
159+
properties:
160+
language:
161+
type: string
162+
key: language
163+
value: en
164+
navigation_name:
165+
type: string
166+
key: navigation_name
167+
value: 'My Document'
168+
navigation_title:
169+
type: string
170+
key: navigation_title
171+
value: 'My Document - Title'
138172
YAML;
139173

140174
$pages = $this->importer->import($yaml, 'yaml', true, true);

tests/app/config/services.yaml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ services:
4343
##################
4444
# Merge Strategy #
4545
##################
46-
Neusta\Pimcore\ImportExportBundle\Import\Strategy\Page\UpdateExistingPageStrategy:
46+
Neusta\Pimcore\ImportExportBundle\Import\Strategy\Document\UpdateExistingPageStrategy:
4747
tags:
4848
- { name: 'neusta.import_export.merge_strategy', type: 'Pimcore\Model\Document' }
4949
- { name: 'neusta.import_export.merge_strategy', type: 'Pimcore\Model\Document\Page' }
@@ -68,3 +68,8 @@ services:
6868
- { name: 'neusta.import_export.repository', type: 'Pimcore\Model\Document\Page' }
6969
- { name: 'neusta.import_export.repository', type: 'Pimcore\Model\Document\PageSnippet' }
7070

71+
72+
## In our integration tests we have no installed Pimcore Application Logger bundle at the moment.
73+
## so we skip the ImportLoggingEventSubscriber here:
74+
Neusta\Pimcore\ImportExportBundle\Import\EventSubscriber\ImportLoggingEventSubscriber:
75+
tags: []

0 commit comments

Comments
 (0)