advanced-object-search icon indicating copy to clipboard operation
advanced-object-search copied to clipboard

[Bug]: Xlsx export issue with ES8 and Advanced Object Search 5

Open NiklasBr opened this issue 1 year ago • 9 comments

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.

Screenshot 2024-02-13 at 14 33 35

Steps to reproduce

Screenshot 2024-02-13 at 14 34 28

  1. Save a search.
  2. Try to export with Excel from said search.

NiklasBr avatar Feb 13 '24 13:02 NiklasBr

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…
]

NiklasBr avatar Feb 27 '24 15:02 NiklasBr

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 avatar Mar 01 '24 11:03 NiklasBr

@NiklasBr we also encountered the same issue. https://github.com/orgs/pimcore/discussions/16706 Any possible fix?

jtwogw avatar Mar 04 '24 08:03 jtwogw

@jtwogw unfortunately I have not been able to find any solution.

NiklasBr avatar Mar 04 '24 16:03 NiklasBr

@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 avatar Mar 05 '24 12:03 NiklasBr

@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"}]" "" "" "" "" "" "" "" ""

jtwogw avatar Mar 18 '24 12:03 jtwogw

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 avatar Mar 18 '24 16:03 NiklasBr

@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/

jtwogw avatar Mar 19 '24 19:03 jtwogw

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.

github-actions[bot] avatar Apr 09 '24 07:04 github-actions[bot]