advanced-object-search
advanced-object-search copied to clipboard
[Bug]: Xlsx export issue with ES8 and Advanced Object Search 5
Expected behavior
A file to be downloaded.
Actual behavior
Pimcore\Model\DataObject\Service::getCsvData(): Argument #4 ($fields) must be of type array, null given,
called in /var/www/pimcore/vendor/pimcore/admin-ui-classic-bundle/src/Controller/Admin/DataObject/DataObjectHelperController.php on line 1351
Issue can be seen here where $fields
is null
.
Steps to reproduce
- Save a search.
- Try to export with Excel from said search.
It appears that $request->get('field')
in DataObjectHelperController::doExportAction()
now contains an array like this:
[
0 = "ArticleId",
1 = "#62ffa09829873",
2 = "SystemArticleName",
3 = "MainMaterialCompositions",
4 = "MainGroup",
5 = "ArtGroup",
6 = "Subgroup",
7 = "#62ffa09829875",
8 = "#62ffa09829876",
9 = "#62ffa09829877",
10 = "#62ffa09829878",
11 = "#62ffa09829879",
12 = "#62ffa0982987a",
]
But it should be something like according to Service.php
:
[
0 = ['key' => something, 'label' => something else ],
1 = ['key' => something, 'label' => something else ],
2 = ['key' => something, 'label' => something else ],
3 = ['key' => something, 'label' => something else ],
4 = ['key' => something, 'label' => something else ],
and so on…
]
I don't know if this is a case of missing migration due to changed configuration data structure in Pimcore 11 vs 10 or something else.
@NiklasBr we also encountered the same issue. https://github.com/orgs/pimcore/discussions/16706 Any possible fix?
@jtwogw unfortunately I have not been able to find any solution.
@jtwogw I think this patch for pimcore/admin-ui-classic-bundle
's file pimcore/vendor/pimcore/admin-ui-classic-bundle/src/Controller/Admin/DataObject/DataObjectHelperController.php
could work, can you try it on your end and see if you have any success?
Index: src/Controller/Admin/DataObject/DataObjectHelperController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Controller/Admin/DataObject/DataObjectHelperController.php b/src/Controller/Admin/DataObject/DataObjectHelperController.php
--- a/src/Controller/Admin/DataObject/DataObjectHelperController.php
+++ b/src/Controller/Admin/DataObject/DataObjectHelperController.php (date 1709637349450)
@@ -1340,7 +1340,13 @@
$list = $beforeListExportEvent->getArgument('list');
- $fields = json_decode($request->get('fields')[0], true);
+ $fields = [];
+ foreach ($request->get('fields') as $field) {
+ $fields[] = [
+ 'key' => $field,
+ 'label' => $field,
+ ];
+ }
$addTitles = (bool) $request->get('initial');
I have no idea if it has any side effects or if there is a better way to fix it, but now we can at least export from Advanced Object Search again.
@NiklasBr it has a side effect, After this code, Data object => folder, export has empty rows.
"[{"key":"id","label":"id"},{"key":"fullpath","label":"fullpath"},{"key":"published","label":"published"},{"key":"name","label":"Name"}]" "" "" "" "" "" "" "" ""
That's a good catch @jtwogw, try this adjusted patch which should work on both regular grid view and Advanced Object Search:
Index: src/Controller/Admin/DataObject/DataObjectHelperController.php
IDEA additional info:
Subsystem: com.intellij.openapi.diff.impl.patch.CharsetEP
<+>UTF-8
===================================================================
diff --git a/src/Controller/Admin/DataObject/DataObjectHelperController.php b/src/Controller/Admin/DataObject/DataObjectHelperController.php
--- a/src/Controller/Admin/DataObject/DataObjectHelperController.php
+++ b/src/Controller/Admin/DataObject/DataObjectHelperController.php (date 1709637349450)
@@ -1340,7 +1340,17 @@
$list = $beforeListExportEvent->getArgument('list');
- $fields = json_decode($request->get('fields')[0], true);
+ if (json_validate($request->get('fields')[0])) {
+ $fields = json_decode($request->get('fields')[0], true);
+ } else {
+ $fields = [];
+ foreach ($request->get('fields') as $field) {
+ $fields[] = [
+ 'key' => $field,
+ 'label' => $field,
+ ];
+ }
+ }
$addTitles = (bool) $request->get('initial');
@NiklasBr
I had reverted the changes on DataObjectHelperController and kept the original code from the pimcore.
Made this temporary fix, this change the request parameter from Advanced-Object-Search module instead of changing on Pimcore DataObjectHelperController. https://github.com/jtwogw/advanced-object-search/commit/2ed21e800ca21bd6159d811c2850c9543062f0ae
From here: src/Resources/public/js/searchConfig/resultPanel.js
Not sure if this is a good place to fix the issue, anyway this works for both cases in my case.
--- For Prod ENV -- cache:clear and pimcore:cache:clear did not worked for prod ENV. had to delete /public/bundles/ Run Composer install to regenerate /public/bundles/
Thanks a lot for reporting the issue. We did not consider the issue as "Pimcore:Priority", "Pimcore:ToDo" or "Pimcore:Backlog", so we're not going to work on that anytime soon. Please create a pull request to fix the issue if this is a bug report. We'll then review it as quickly as possible. If you're interested in contributing a feature, please contact us first here before creating a pull request. We'll then decide whether we'd accept it or not. Thanks for your understanding.