From 56ec5f68e39f63c1b80c03606698155698e92f52 Mon Sep 17 00:00:00 2001 From: markus-moser Date: Mon, 3 Jun 2024 15:29:18 +0200 Subject: [PATCH] Respect the user's timezone in the version preview and in CSV exports --- public/js/pimcore/asset/versions.js | 5 ++++- .../js/pimcore/element/helpers/gridColumnConfig.js | 1 + public/js/pimcore/functions.js | 4 ++++ public/js/pimcore/object/versions.js | 12 +++++++++--- src/Controller/Admin/Asset/AssetController.php | 2 ++ .../Admin/DataObject/DataObjectController.php | 5 +++++ .../Admin/DataObject/DataObjectHelperController.php | 1 + 7 files changed, 26 insertions(+), 4 deletions(-) diff --git a/public/js/pimcore/asset/versions.js b/public/js/pimcore/asset/versions.js index c3927b3d65..ce97d65ec9 100644 --- a/public/js/pimcore/asset/versions.js +++ b/public/js/pimcore/asset/versions.js @@ -155,7 +155,10 @@ pimcore.asset.versions = Class.create({ var data = grid.getStore().getAt(rowIndex).data; var versionId = data.id; - var url = Routing.generate('pimcore_admin_asset_showversion', {id: versionId}); + var url = Routing.generate('pimcore_admin_asset_showversion', { + id: versionId, + userTimezone: getUserTimezone() + }); Ext.get(this.frameId).dom.src = url; }, diff --git a/public/js/pimcore/element/helpers/gridColumnConfig.js b/public/js/pimcore/element/helpers/gridColumnConfig.js index dc8b0018fc..2dfe01828b 100644 --- a/public/js/pimcore/element/helpers/gridColumnConfig.js +++ b/public/js/pimcore/element/helpers/gridColumnConfig.js @@ -857,6 +857,7 @@ pimcore.element.helpers.gridColumnConfig = { this.exportParameters.initial = initial ? 1 : 0; this.exportParameters.language = this.gridLanguage; this.exportParameters.context = Ext.encode(this.context); + this.exportParameters.userTimezone = getUserTimezone(); Ext.Ajax.request({ url: this.exportProcessUrl, diff --git a/public/js/pimcore/functions.js b/public/js/pimcore/functions.js index 2680cfe8ad..fd5eff5c00 100644 --- a/public/js/pimcore/functions.js +++ b/public/js/pimcore/functions.js @@ -1793,3 +1793,7 @@ function htmlspecialchars (string, quoteStyle, charset, doubleEncode) { return string } + +function getUserTimezone() { + return Intl.DateTimeFormat().resolvedOptions().timeZone; +} \ No newline at end of file diff --git a/public/js/pimcore/object/versions.js b/public/js/pimcore/object/versions.js index d21d42e11e..4bede8287e 100644 --- a/public/js/pimcore/object/versions.js +++ b/public/js/pimcore/object/versions.js @@ -201,7 +201,11 @@ pimcore.object.versions = Class.create({ var selections = grid.getSelectionModel().getSelection(); - var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', {from: selections[0].data.id, to: selections[1].data.id}); + var url = Routing.generate('pimcore_admin_dataobject_dataobject_diffversions', { + from: selections[0].data.id, + to: selections[1].data.id, + userTimezone: getUserTimezone() + }); Ext.get(this.iframeId).dom.src = url; } }, @@ -211,8 +215,10 @@ pimcore.object.versions = Class.create({ var store = grid.getStore(); var data = store.getAt(rowIndex).data; var versionId = data.id; - - var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', {id: versionId}); + var url = Routing.generate('pimcore_admin_dataobject_dataobject_previewversion', { + id: versionId, + userTimezone: getUserTimezone() + }); Ext.get(this.iframeId).dom.src = url; }, diff --git a/src/Controller/Admin/Asset/AssetController.php b/src/Controller/Admin/Asset/AssetController.php index 6abb13ce50..4378cb8d8f 100644 --- a/src/Controller/Admin/Asset/AssetController.php +++ b/src/Controller/Admin/Asset/AssetController.php @@ -937,6 +937,8 @@ public function showVersionAction(Request $request): Response } } + Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone')); + $loader = \Pimcore::getContainer()->get('pimcore.implementation_loader.asset.metadata.data'); return $this->render( diff --git a/src/Controller/Admin/DataObject/DataObjectController.php b/src/Controller/Admin/DataObject/DataObjectController.php index 726c3a4296..06b5d8c462 100644 --- a/src/Controller/Admin/DataObject/DataObjectController.php +++ b/src/Controller/Admin/DataObject/DataObjectController.php @@ -1596,6 +1596,9 @@ public function previewVersionAction(Request $request): Response $object = $version?->loadData(); if ($object) { + + Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone')); + if (method_exists($object, 'getLocalizedFields')) { /** @var DataObject\Localizedfield $localizedFields */ $localizedFields = $object->getLocalizedFields(); @@ -1651,6 +1654,8 @@ public function diffVersionsAction(Request $request, int $from, int $to): Respon throw $this->createNotFoundException('Version with id [' . $id2 . "] doesn't exist"); } + Tool\UserTimezone::setUserTimezone($request->query->get('userTimezone')); + if (method_exists($object2, 'getLocalizedFields')) { /** @var DataObject\Localizedfield $localizedFields2 */ $localizedFields2 = $object2->getLocalizedFields(); diff --git a/src/Controller/Admin/DataObject/DataObjectHelperController.php b/src/Controller/Admin/DataObject/DataObjectHelperController.php index a519f3200d..7bd1c56d36 100644 --- a/src/Controller/Admin/DataObject/DataObjectHelperController.php +++ b/src/Controller/Admin/DataObject/DataObjectHelperController.php @@ -1219,6 +1219,7 @@ public function doExportAction( $settings = json_decode($request->get('settings'), true); $delimiter = $settings['delimiter'] ?? ';'; $header = $settings['header'] ?? 'title'; + Tool\UserTimezone::setUserTimezone($request->request->get('userTimezone')); $allParams = array_merge($request->request->all(), $request->query->all());