Skip to content

Commit 267f49d

Browse files
committed
[With or With IDs][Review] by J-Cop
1 parent f65536d commit 267f49d

File tree

11 files changed

+85
-38
lines changed

11 files changed

+85
-38
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.5.4",
16+
"pimcore/pimcore": "^11.0",
1717
"symfony/config": "^6.4",
1818
"symfony/console": "^6.4",
1919
"symfony/dependency-injection": "^6.4",

src/Export/Exporter.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public function export(iterable $elements, string $format, array $ctxParams = []
5151
$yamlContent = $this->typeToConverterMap[$type]->convert($element, $ctx);
5252
$yamlExportElements[] = [$type => $yamlContent];
5353
} catch (ConverterException $e) {
54-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::FAILED, $type, [], $element, null, $e->getMessage()));
54+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Failed, $type, [], $element, null, $e->getMessage()));
5555
}
5656
continue 2;
5757
}

src/Import/Event/ImportStatus.php

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44

55
enum ImportStatus: string
66
{
7-
case SKIPPED = 'SKIPPED';
8-
case CREATED = 'CREATED';
9-
case UPDATED = 'UPDATED';
10-
case INCONSISTENCY = 'INCONSISTENCY';
11-
case FAILED = 'FAILED';
7+
case Skipped = 'SKIPPED';
8+
case Created = 'CREATED';
9+
case Updated = 'UPDATED';
10+
case Inconsistency = 'INCONSISTENCY';
11+
case Failed = 'FAILED';
1212
}

src/Import/EventSubscriber/ImportLoggingEventSubscriber.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@ public function logImportEvent(ImportEvent $event): void
3333

3434
if (\in_array(
3535
$event->getStatus(),
36-
[ImportStatus::INCONSISTENCY, ImportStatus::FAILED]
36+
[ImportStatus::Inconsistency, ImportStatus::Failed]
3737
)) {
3838
$this->writeApplicationError($event);
3939
} else {

src/Import/Importer.php

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -78,22 +78,22 @@ 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));
81+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Created, $typeKey, $element, $result, null));
8282
} catch (\Exception $e) {
83-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::FAILED, $typeKey, $element, $result, $oldElement, $e->getMessage()));
83+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Failed, $typeKey, $element, $result, $oldElement, $e->getMessage()));
8484
}
8585
} elseif ($overwrite) {
8686
if ($this->newElementHasNoValidId($result) || $this->bothHaveSameId($oldElement, $result)) {
8787
// Update existing element by new one
8888
try {
8989
$mergeStrategy->mergeAndSave($oldElement, $result);
90-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::UPDATED, $typeKey, $element, $result, $oldElement));
90+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Updated, $typeKey, $element, $result, $oldElement));
9191
} catch (\Exception $e) {
92-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::FAILED, $typeKey, $element, $result, $oldElement, $e->getMessage()));
92+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Failed, $typeKey, $element, $result, $oldElement, $e->getMessage()));
9393
}
9494
} else {
9595
$this->dispatcher->dispatch(new ImportEvent(
96-
ImportStatus::INCONSISTENCY, $typeKey, $element, $result, $oldElement,
96+
ImportStatus::Inconsistency, $typeKey, $element, $result, $oldElement,
9797
<<<ERR_MESSAGE
9898
Two elements with same key (%s) and path (%s) but different IDs (new ID: %d, old ID: %d) found.
9999
This seems to be an inconsistency of your importing data. Please check your import file.
@@ -104,7 +104,7 @@ public function import(string $yamlInput, string $format, bool $forcedSave, bool
104104
}
105105
} else {
106106
// Don't overwrite existing element
107-
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::SKIPPED, $typeKey, $element, $result, $oldElement));
107+
$this->dispatcher->dispatch(new ImportEvent(ImportStatus::Skipped, $typeKey, $element, $result, $oldElement));
108108
}
109109
}
110110
}

src/Serializer/Normalizer/PrioritizedAttributesNormalizer.php

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
namespace Neusta\Pimcore\ImportExportBundle\Serializer\Normalizer;
44

5+
use Neusta\Pimcore\ImportExportBundle\Model\Element;
56
use Symfony\Component\Serializer\Normalizer\NormalizerInterface;
67
use Symfony\Component\Serializer\Normalizer\ObjectNormalizer;
78

@@ -48,6 +49,6 @@ public function normalize($object, ?string $format = null, array $context = [])
4849

4950
public function supportsNormalization($data, ?string $format = null): bool
5051
{
51-
return \is_object($data) && $this->normalizer->supportsNormalization($data, $format);
52+
return $data instanceof Element && $this->normalizer->supportsNormalization($data, $format);
5253
}
5354
}

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_export__1.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,14 +14,14 @@ elements:
1414
data: 'some text input'
1515
properties:
1616
language:
17-
type: string
1817
key: language
18+
type: string
1919
value: en
2020
navigation_name:
21-
type: string
2221
key: navigation_name
22+
type: string
2323
value: 'My Document'
2424
navigation_title:
25-
type: string
2625
key: navigation_title
26+
type: string
2727
value: 'My Document - Title'

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_export_with_ids__1.yaml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,14 @@ elements:
1616
data: 'some text input'
1717
properties:
1818
language:
19-
type: string
2019
key: language
20+
type: string
2121
value: en
2222
navigation_name:
23-
type: string
2423
key: navigation_name
24+
type: string
2525
value: 'My Document'
2626
navigation_title:
27-
type: string
2827
key: navigation_title
28+
type: string
2929
value: 'My Document - Title'

tests/Integration/Import/ImporterExporterTest.php

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ protected function setUp(): void
3030
$asset = new Asset();
3131
$asset->setParentId(1);
3232
$asset->setPath('/');
33-
$asset->setKey('logo_desktop_' . uniqid() . '.svg');
33+
$asset->setKey('logo_desktop.svg');
3434
$asset->save();
3535
self::assertNotNull($asset->getId(), 'Asset should be saved successfully');
3636

@@ -49,6 +49,6 @@ public function testImportExport_regular_case(): void
4949
$document = Page::getByPath('/Test-Import-Export');
5050
$yamlExported = $this->exporter->export([$document], 'yaml');
5151

52-
self::assertEquals(yaml_parse($yamlToImport), yaml_parse($yamlExported));
52+
self::assertEquals($yamlToImport, $yamlExported);
5353
}
5454
}

tests/Integration/data/Text Editor.yaml

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -134,62 +134,62 @@ elements:
134134
data: 1col
135135
properties:
136136
navigation_accesskey:
137-
type: text
138137
key: navigation_accesskey
138+
type: text
139139
value: ''
140140
navigation_anchor:
141-
type: text
142141
key: navigation_anchor
142+
type: text
143143
value: ''
144144
navigation_class:
145-
type: text
146145
key: navigation_class
146+
type: text
147147
value: ''
148148
navigation_exclude:
149-
type: bool
150149
key: navigation_exclude
150+
type: bool
151151
value: false
152152
navigation_name:
153-
type: text
154153
key: navigation_name
154+
type: text
155155
value: ''
156156
navigation_parameters:
157-
type: text
158157
key: navigation_parameters
158+
type: text
159159
value: ''
160160
navigation_relation:
161-
type: text
162161
key: navigation_relation
162+
type: text
163163
value: ''
164164
navigation_tabindex:
165-
type: text
166165
key: navigation_tabindex
166+
type: text
167167
value: ''
168168
navigation_target:
169-
type: text
170169
key: navigation_target
170+
type: text
171171
value: ~
172172
navigation_title:
173-
type: text
174173
key: navigation_title
174+
type: text
175175
value: ''
176176
testPropertyAsset:
177-
type: asset
178177
key: testPropertyAsset
178+
type: asset
179179
value: /logo_desktop.svg
180180
testPropertyCheckbox:
181-
type: bool
182181
key: testPropertyCheckbox
182+
type: bool
183183
value: false
184184
testPropertyKey:
185-
type: document
186185
key: testPropertyKey
186+
type: document
187187
value: '/Text für viele'
188188
testPropertyObject:
189-
type: object
190189
key: testPropertyObject
190+
type: object
191191
value: ~
192192
testPropertyString:
193-
type: text
194193
key: testPropertyString
194+
type: text
195195
value: 'Ich bin eine Zeichenkette'

0 commit comments

Comments
 (0)