Skip to content

Commit de90b88

Browse files
lukadschaakmike4gitjdreesen
authored
bugfix: [inherited-properties] add inherited field to export and skip inherited properties on import (#25)
* [inherited-properties] skip inherited properties and set inheritable on merge * [inherited-properties] added inherited property to Document Property in Import --------- Co-authored-by: Michael Albrecht <m.albrecht@neusta.de> Co-authored-by: Jacob Dreesen <jacob@hdreesen.de>
1 parent c6e4554 commit de90b88

File tree

11 files changed

+29
-125
lines changed

11 files changed

+29
-125
lines changed

config/pimcore/export/documents/converters_populators.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,7 @@ neusta_converter:
7070
properties:
7171
key: name
7272
type: ~
73+
inherited: ~
7374

7475
services:
7576
_defaults:

src/Import/Strategy/Document/UpdateExistingPageStrategy.php

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,11 @@ public function mergeAndSave(AbstractElement $oldElement, AbstractElement $newEl
3434
foreach ($newElement->getProperties() as $property) {
3535
$name = $property->getName();
3636
$type = $property->getType();
37-
if (null === $name || null === $type) {
38-
continue; // Skip invalid properties
37+
$inherited = $property->getInherited();
38+
if (null === $name || null === $type || true === $inherited) {
39+
continue; // Skip invalid and inherited properties
3940
}
40-
$oldElement->setProperty($name, $type, $property->getData());
41+
$oldElement->setProperty($name, $type, $property->getData(), false, $property->getInheritable());
4142
}
4243
$oldElement->save(['versionNote' => 'overwritten by pimcore-import-export-bundle']);
4344
}

src/Model/Property.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,4 +7,5 @@ class Property
77
public string $key;
88
public string $type;
99
public mixed $value;
10+
public bool $inherited;
1011
}

src/Populator/Document/PropertiesPopulator.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ public function populate(object $target, object $source, ?object $ctx = null): v
3838
} else {
3939
$value = $property['value'];
4040
}
41-
$target->setProperty($property['key'], $property['type'], $value);
41+
$target->setProperty($property['key'], $property['type'], $value, $property['inherited'] ?? false);
4242
}
4343
}
4444
}

tests/Integration/Export/ExporterTest.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -141,7 +141,7 @@ private function createPageWithInputEditable(): Page
141141
$page->setPublished(false);
142142
$page->setPath('/test/');
143143
$page->setKey('test_document_1');
144-
$page->setProperty('language', 'string', 'en');
144+
$page->setProperty('language', 'string', 'en', true);
145145
$page->setProperty('navigation_name', 'string', 'My Document');
146146
$page->setProperty('navigation_title', 'string', 'My Document - Title');
147147
$page->setTitle('The Title of my document');

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_export__1.yaml

Lines changed: 0 additions & 27 deletions
This file was deleted.

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_export_json__1.json

Lines changed: 0 additions & 38 deletions
This file was deleted.

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_export_with_ids__1.yaml

Lines changed: 0 additions & 29 deletions
This file was deleted.

tests/Integration/Export/__snapshots__/ExporterTest__test_single_page_snippet_export__1.yaml

Lines changed: 0 additions & 26 deletions
This file was deleted.

tests/Integration/data/Page Snippet.yaml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,23 +232,29 @@ elements:
232232
key: language
233233
type: text
234234
value: ''
235+
inherited: false
235236
neusta_trinity_pimcore_footer:
236237
key: neusta_trinity_pimcore_footer
237238
type: document
238239
value: ~
240+
inherited: false
239241
neusta_trinity_pimcore_footer_visible:
240242
key: neusta_trinity_pimcore_footer_visible
241243
type: bool
242244
value: true
245+
inherited: false
243246
neusta_trinity_pimcore_header:
244247
key: neusta_trinity_pimcore_header
245248
type: document
246249
value: ~
250+
inherited: false
247251
neusta_trinity_pimcore_header_visible:
248252
key: neusta_trinity_pimcore_header_visible
249253
type: bool
250254
value: true
255+
inherited: false
251256
slotName:
252257
key: slotName
253258
type: text
254259
value: footer
260+
inherited: true

0 commit comments

Comments
 (0)