Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
NiklasBr opened this issue Feb 13, 2024 · 9 comments · Fixed by #262
Closed

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

NiklasBr opened this issue Feb 13, 2024 · 9 comments · Fixed by #262

Comments

@NiklasBr
Copy link
Contributor

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 NiklasBr added the Bug label Feb 13, 2024
@NiklasBr
Copy link
Contributor Author

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
Copy link
Contributor Author

NiklasBr commented Mar 1, 2024

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.

@jtwogw
Copy link
Contributor

jtwogw commented Mar 4, 2024

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

@NiklasBr
Copy link
Contributor Author

NiklasBr commented Mar 4, 2024

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

@NiklasBr
Copy link
Contributor Author

NiklasBr commented Mar 5, 2024

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

@jtwogw
Copy link
Contributor

jtwogw commented Mar 18, 2024

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

@NiklasBr
Copy link
Contributor Author

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');

jtwogw added a commit to jtwogw/advanced-object-search that referenced this issue Mar 19, 2024
@jtwogw
Copy link
Contributor

jtwogw commented Mar 19, 2024

@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.
jtwogw@2ed21e8

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/

Copy link

github-actions bot commented Apr 9, 2024

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants