Skip to content

Commit 6114d66

Browse files
authored
[Improvement]: Possibility to include Pimcore core version in JSON export filenames (#1030)
* Update filename format for JSON export response * add v prefix to version number * apply to all
1 parent 80f5e09 commit 6114d66

File tree

5 files changed

+42
-5
lines changed

5 files changed

+42
-5
lines changed

CHANGELOG.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
#### v2.3.0
2+
- Added `pimcore_admin:export:add_suffix` configuration option to add the Core version as suffix to exported data object type configuration (e.g. `class_Product_export_v1211.json`).
3+
4+
15
#### v2.1.0
26
- Added the possibility to set default values for multi select fields in class definitions.
37

config/pimcore/default.yaml

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@ pimcore_admin:
1111
translations:
1212
path: "@PimcoreCoreBundle/translations"
1313

14+
export:
15+
version_suffix: false
16+
1417
user:
1518
default_key_bindings:
1619
save:

src/Controller/Admin/DataObject/ClassController.php

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -616,6 +616,19 @@ public function getAllLayoutsAction(Request $request): JsonResponse
616616
return $this->adminJson(['data' => $resultList]);
617617
}
618618

619+
private function getExportFileName(string $prefix, ?string $filename = null, ?bool $add_suffix = null): string
620+
{
621+
$addVersionSuffix = $add_suffix
622+
?? \Pimcore::getContainer()
623+
->getParameter('pimcore_admin.config')['export']['version_suffix'];
624+
625+
return sprintf(
626+
'%s%s_export%s.json',
627+
$prefix,
628+
$filename ? '_' . $filename : '',
629+
$addVersionSuffix ? '_v' . \Pimcore\Version::getVersion() : ''
630+
);
631+
}
619632
#[Route('/export-class', name: 'exportclass', methods: ['GET'])]
620633
public function exportClassAction(Request $request): Response
621634
{
@@ -629,11 +642,13 @@ public function exportClassAction(Request $request): Response
629642
throw $this->createNotFoundException($errorMessage);
630643
}
631644

645+
$filename = $this->getExportFileName('class', $class->getName());
646+
632647
$json = DataObject\ClassDefinition\Service::generateClassDefinitionJson($class);
633648

634649
$response = new Response($json);
635650
$response->headers->set('Content-type', 'application/json');
636-
$response->headers->set('Content-Disposition', 'attachment; filename="class_' . $class->getName() . '_export.json"');
651+
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
637652

638653
return $response;
639654
}
@@ -647,11 +662,13 @@ public function exportCustomLayoutDefinitionAction(Request $request): Response
647662
$customLayout = DataObject\ClassDefinition\CustomLayout::getById($id);
648663
if ($customLayout) {
649664
$name = $customLayout->getName();
665+
$filename = $this->getExportFileName('custom_definition', $name);
666+
650667
$json = DataObject\ClassDefinition\Service::generateCustomLayoutJson($customLayout);
651668

652669
$response = new Response($json);
653670
$response->headers->set('Content-type', 'application/json');
654-
$response->headers->set('Content-Disposition', 'attachment; filename="custom_definition_' . $name . '_export.json"');
671+
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
655672

656673
return $response;
657674
}
@@ -765,10 +782,12 @@ public function exportFieldcollectionAction(Request $request): Response
765782
throw $this->createNotFoundException($errorMessage);
766783
}
767784

785+
$filename = $this->getExportFileName('fieldcollection', $fieldCollection->getKey());
786+
768787
$json = DataObject\ClassDefinition\Service::generateFieldCollectionJson($fieldCollection);
769788
$response = new Response($json);
770789
$response->headers->set('Content-type', 'application/json');
771-
$response->headers->set('Content-Disposition', 'attachment; filename="fieldcollection_' . $fieldCollection->getKey() . '_export.json"');
790+
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
772791

773792
return $response;
774793
}
@@ -1117,10 +1136,12 @@ public function exportObjectbrickAction(Request $request): Response
11171136
throw $this->createNotFoundException($errorMessage);
11181137
}
11191138

1139+
$filename = $this->getExportFileName('objectbrick', $objectBrick->getKey());
1140+
11201141
$xml = DataObject\ClassDefinition\Service::generateObjectBrickJson($objectBrick);
11211142
$response = new Response($xml);
11221143
$response->headers->set('Content-type', 'application/json');
1123-
$response->headers->set('Content-Disposition', 'attachment; filename="objectbrick_' . $objectBrick->getKey() . '_export.json"');
1144+
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
11241145

11251146
return $response;
11261147
}
@@ -1629,11 +1650,12 @@ public function doBulkExportAction(Request $request): Response
16291650
}
16301651
}
16311652
}
1653+
$filename = $this->getExportFileName('bulk');
16321654

16331655
$result = json_encode($result, JSON_PRETTY_PRINT);
16341656
$response = new Response($result);
16351657
$response->headers->set('Content-type', 'application/json');
1636-
$response->headers->set('Content-Disposition', 'attachment; filename="bulk_export.json"');
1658+
$response->headers->set('Content-Disposition', 'attachment; filename="' . $filename . '"');
16371659

16381660
return $response;
16391661
}

src/DependencyInjection/Configuration.php

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,13 @@ public function getConfigTreeBuilder(): TreeBuilder
4545
->prototype('scalar')
4646
->end()
4747
->end()
48+
->arrayNode('export')
49+
->children()
50+
->booleanNode('version_suffix')
51+
->defaultFalse()
52+
->end()
53+
->end()
54+
->end()
4855
->arrayNode('csrf_protection')
4956
->addDefaultsIfNotSet()
5057
->children()

src/DependencyInjection/PimcoreAdminExtension.php

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,7 @@ public function load(array $configs, ContainerBuilder $container): void
8989
$container->setParameter(self::PARAM_DOCUMENTS_NOTES_EVENTS_TYPES, $config['documents']['notes_events']['types']);
9090
$container->setParameter('pimcore_admin.csrf_protection.excluded_routes', $config['csrf_protection']['excluded_routes']);
9191
$container->setParameter('pimcore_admin.admin_languages', $config['admin_languages']);
92+
$container->setParameter('pimcore_admin.export', $config['export']);
9293
$container->setParameter('pimcore_admin.custom_admin_path_identifier', $config['custom_admin_path_identifier']);
9394
$container->setParameter('pimcore_admin.custom_admin_route_name', $config['custom_admin_route_name']);
9495
$container->setParameter('pimcore_admin.user', $config['user']);

0 commit comments

Comments
 (0)