Skip to content
Closed
Show file tree
Hide file tree
Changes from 7 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
12852a9
[Feature] enable exporting and importing several pages by ONE yaml file
mike4git Feb 28, 2025
3647382
[Fix] use ['page'] instead of config
mike4git Feb 28, 2025
ac6271e
[Feature] Add integration tests for PageExporter
mike4git Mar 1, 2025
d1754f9
[Feature] Moved import menu to main menu toolbar
mike4git Mar 1, 2025
f0f8f47
[Feature] Test PageImporter and adapt way of saving
mike4git Mar 2, 2025
884f2f1
[Export All] new command for export all pages
mike4git Mar 14, 2025
69e2ff6
[Chore] fix general code styles
lukadschaak Mar 14, 2025
f2f05d1
[Chore] readme: edit how tests must be executed
lukadschaak Mar 14, 2025
1654f74
[Export All][Refactoring] remove duplicated code
mike4git Mar 15, 2025
eaba65f
Update src/Controller/Admin/PageImportController.php
mike4git Mar 15, 2025
248bacb
Update tests/Integration/Documents/Export/PageExporterTest.php
mike4git Mar 15, 2025
8953203
Update tests/Integration/Documents/Export/PageImporterTest.php
mike4git Mar 15, 2025
a4a3de0
Update tests/Integration/Documents/Export/PageImporterTest.php
mike4git Mar 15, 2025
65eabf9
Update translations/admin.de.yaml
mike4git Mar 15, 2025
c9a4b4e
Update translations/admin.en.yaml
mike4git Mar 15, 2025
725fbb9
Update tests/Integration/Documents/Export/PageImporterTest.php
mike4git Mar 15, 2025
8d987ab
Update tests/Integration/Documents/Export/PageImporterTest.php
mike4git Mar 15, 2025
9343665
[Export All][Tests] add expected yaml files
mike4git Mar 15, 2025
158f981
[Export All][Tests] fix it
mike4git Mar 15, 2025
3514a1f
[Export All][Refactoring] (#12)
mike4git Mar 19, 2025
7b6a683
[Export All][Refactoring][New Commands] add test results
mike4git Mar 19, 2025
af03dc1
Update tests/Integration/Documents/Export/PageExporterTest.php
mike4git Mar 19, 2025
c4704c2
[Export All][Refactoring][New Commands] adapt naming import to export
mike4git Mar 19, 2025
fa97083
[Export All][Refactoring][New Commands] fix test
mike4git Mar 19, 2025
c0c6bb2
Update src/Controller/Admin/PageImportController.php
mike4git Mar 19, 2025
a77952e
Update src/Command/ExportPagesCommand.php
mike4git Mar 19, 2025
8844cd1
Update src/Command/ImportPagesCommand.php
mike4git Mar 19, 2025
57e9853
Update src/Command/ImportPagesCommand.php
mike4git Mar 19, 2025
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 25 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,18 @@
## Installation

1. **Require the bundle**

```shell
composer require teamneusta/pimcore-import-export-bundle
```

2. **Enable the bundle**
2. **Enable the bundle**

Add the Bundle to your `config/bundles.php`:

```php
Neusta\Pimcore\ImportExportBundle\NeustaPimcoreImportExportBundle::class => ['all' => true],
```
```php
Neusta\Pimcore\ImportExportBundle\NeustaPimcoreImportExportBundle::class => ['all' => true],
```

## Usage

Expand All @@ -25,7 +25,9 @@ After enabling the bundle you should see a new menu item in the context menu of
(german translation)

### Page Export

The selected page will be exported into YAML format:

```yaml
page:
id: 123
Expand All @@ -43,7 +45,7 @@ page:
main:
type: areablock
name: main
data: [{ key: '1', type: text-editor, hidden: false }]
data: [ { key: '1', type: text-editor, hidden: false } ]
...
```

Expand All @@ -53,7 +55,23 @@ In the same way you can re-import your yaml file again by selecting: `Import fro

### Page Import

The import process will create a new page with the given data.
The import process will create pages with the given data.

The following rule applies:

If the parseYaml method of the `PageImporter` is not called with `forcedSave`, the data from the provided YAML will be
adopted, regardless of whether it makes sense or not, and without checking whether the page could be saved that way.

If `forcedSave` is set to `true`, the ID will be retained (Caution – this can overwrite an existing page).
If a `parentId` is specified, the corresponding document will be searched for.
If it exists, it will be set as the parent (Note: This may override the `path` specification).
If the `parentId` does not exist, an attempt will be made to find a parent using the `path` specification.
If such a parent exists, the `parentId` will be set accordingly and saved.

If neither is found, an InvalidArgumentException will be thrown, and the save operation will be aborted.

If multiple pages are imported and a path specification changes py the applied rules, this path specification will be
replaced with the new, correct path specification in all provided page configurations.

## Contribution

Expand Down
2 changes: 1 addition & 1 deletion compose.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ services:
timeout: 10s

php:
image: pimcore/pimcore:php8.3-latest
image: pimcore/pimcore:php8.3-debug-latest
volumes:
- ./:/var/www/html/
environment:
Expand Down
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@
"phpstan/phpstan-symfony": "^1.3.8",
"phpunit/phpunit": "^9.5",
"pimcore/admin-ui-classic-bundle": "^1.6",
"spatie/phpunit-snapshot-assertions": "^4.2",
"teamneusta/pimcore-testing-framework": "^0.12"
},
"autoload": {
Expand Down
63 changes: 63 additions & 0 deletions config/converters_populators.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
services:
_defaults:
autowire: true
autoconfigure: true

###########################################################
# Import Populator (YamlExportPage -> Page)
###########################################################
Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImportPopulator: ~

Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImporter:
arguments:
$yamlToPageConverter: '@neusta_pimcore_import_export.import_page'

###########################################################
# Export Converter (Document -> YamlExportPage)
###########################################################
neusta_pimcore_import_export.export_document:
class: Neusta\Pimcore\ImportExportBundle\Documents\Export\Converter\DocumentTypeStrategyConverter
arguments:
$type2ConverterMap:
Pimcore\Model\Document\Page: '@neusta_pimcore_import_export.export_page'
Pimcore\Model\Document\Snippet: '@neusta_pimcore_import_export.export_page_snippet'
Pimcore\Model\Document\Folder: '@neusta_pimcore_import_export.export_folder'


###########################################################
# Export Populator (Page -> YamlExportPage)
###########################################################
neusta_pimcore_import_export.page.editables.populator:
class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator
arguments:
$converter: '@neusta_pimcore_import_export.editable_converter'
$sourceArrayPropertyName: 'editables'
$targetPropertyName: 'editables'

neusta_pimcore_import_export.page.property.language.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'language'
$targetProperty: 'language'
$skipNull: true

neusta_pimcore_import_export.page.property.navigation_title.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'navigation_title'
$targetProperty: 'navigation_title'
$skipNull: true

neusta_pimcore_import_export.page.property.navigation_name.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'navigation_name'
$targetProperty: 'navigation_name'
$skipNull: true

###########################################################
# Export Populator (Editable -> YamlExportEditable)
###########################################################
neusta_pimcore_import_export.editable.data.populator:
class: Neusta\Pimcore\ImportExportBundle\Documents\Export\Populator\EditableDataPopulator

40 changes: 39 additions & 1 deletion config/pimcore/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -31,10 +31,28 @@ neusta_converter:
path:
source: path
default: '/'
skip_null: true
parentId:
source: parentId
default: 0

###########################################################
# Export Converter (Folder -> YamlExportPage)
###########################################################
neusta_pimcore_import_export.export_folder:
target: Neusta\Pimcore\ImportExportBundle\Documents\Export\YamlExportPage
populators:
- neusta_pimcore_import_export.page.property.language.populator
- neusta_pimcore_import_export.page.property.navigation_title.populator
- neusta_pimcore_import_export.page.property.navigation_name.populator
properties:
id: ~
key: ~
type: ~
published: ~
path: ~
parentId: ~

###########################################################
# Export Converter (Page -> YamlExportPage)
###########################################################
Expand All @@ -55,9 +73,29 @@ neusta_converter:
path: ~
parentId: ~

###########################################################
# Export Converter (Snippet -> YamlExportPage)
###########################################################
neusta_pimcore_import_export.export_page_snippet:
target: Neusta\Pimcore\ImportExportBundle\Documents\Export\YamlExportPage
populators:
- neusta_pimcore_import_export.page.property.language.populator
- neusta_pimcore_import_export.page.property.navigation_title.populator
- neusta_pimcore_import_export.page.property.navigation_name.populator
- neusta_pimcore_import_export.page.editables.populator
properties:
id: ~
key: ~
controller: ~
type: ~
published: ~
path: ~
parentId: ~

neusta_pimcore_import_export.editable_converter:
target: Neusta\Pimcore\ImportExportBundle\Documents\Export\YamlExportEditable
populators:
- neusta_pimcore_import_export.editable.data.populator
properties:
type: ~
name: ~
data: ~
61 changes: 20 additions & 41 deletions config/services.yaml
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
imports:
- { resource: 'converters_populators.yaml' }

services:
_defaults:
autowire: true
Expand All @@ -6,9 +9,16 @@ services:
Neusta\Pimcore\ImportExportBundle\Toolbox\:
resource: '../src/Toolbox'

###########################################################
# Controller
###########################################################
############
# Commands #
############
Neusta\Pimcore\ImportExportBundle\Command\ExportAllPagesCommand:
public: true
tags: [ 'console.command' ]

##############
# Controller #
##############
Neusta\Pimcore\ImportExportBundle\Controller\Admin\PageExportController:
public: true
tags: [ 'controller.service_arguments' ]
Expand All @@ -17,47 +27,16 @@ services:
public: true
tags: [ 'controller.service_arguments' ]

###########################################################
# Import Populator (YamlExportPage -> Page)
###########################################################
Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImportPopulator: ~

Neusta\Pimcore\ImportExportBundle\Documents\Import\PageImporter:
arguments:
$yamlToPageConverter: '@neusta_pimcore_import_export.import_page'

###########################################################
# Export Populator (Page -> YamlExportPage)
###########################################################
neusta_pimcore_import_export.page.editables.populator:
class: Neusta\ConverterBundle\Populator\ArrayConvertingPopulator
arguments:
$converter: '@neusta_pimcore_import_export.editable_converter'
$sourceArrayPropertyName: 'editables'
$targetPropertyName: 'editables'

neusta_pimcore_import_export.page.property.language.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'language'
$targetProperty: 'language'

neusta_pimcore_import_export.page.property.navigation_title.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'navigation_title'
$targetProperty: 'navigation_title'

neusta_pimcore_import_export.page.property.navigation_name.populator:
class: Neusta\Pimcore\ImportExportBundle\PimcoreConverter\Populator\PropertyBasedMappingPopulator
arguments:
$propertyKey: 'navigation_name'
$targetProperty: 'navigation_name'

#############
# Documents #
#############
Neusta\Pimcore\ImportExportBundle\Documents\Export\PageExporter:
arguments:
$pageToYamlConverter: '@neusta_pimcore_import_export.export_page'
$pageToYamlConverter: '@neusta_pimcore_import_export.export_document'

#################
# EventListener #
#################
Neusta\Pimcore\ImportExportBundle\EventListener\PimcoreAdminListener:
tags:
- { name: kernel.event_listener, event: pimcore.bundle_manager.paths.js, method: addJSFiles }
10 changes: 10 additions & 0 deletions public/js/exportPage.js
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ neusta_pimcore_import_export.plugin.page.export = Class.create({
onPrepareDocumentTreeContextMenu: function (e) {
let menu = e.detail.menu;
let document = e.detail.document;

// Export page into yaml file
menu.add("-");
menu.add(new Ext.menu.Item({
Expand All @@ -17,6 +18,15 @@ neusta_pimcore_import_export.plugin.page.export = Class.create({
pimcore.helpers.download(Routing.generate('neusta_pimcore_import_export_page_export', {page_id: document.data.id}));
}
}));

// Export page and children into yaml file
menu.add(new Ext.menu.Item({
text: t('neusta_pimcore_import_export_export_with_children_menu_label'),
iconCls: "pimcore_icon_export",
handler: function () {
pimcore.helpers.download(Routing.generate('neusta_pimcore_import_export_page_export_with_children', {page_id: document.data.id}));
}
}));
},

});
Expand Down
Loading