Skip to content

fix: read timezone from config#186

Open
Dennis Garding (DennisGarding) wants to merge 9 commits into
trunkfrom
14186/time-zone-diff
Open

fix: read timezone from config#186
Dennis Garding (DennisGarding) wants to merge 9 commits into
trunkfrom
14186/time-zone-diff

Conversation

@DennisGarding
Copy link
Copy Markdown
Contributor

Comment thread src/Profile/Shopware/Premapping/TimezoneReader.php Outdated
@DennisGarding Dennis Garding (DennisGarding) marked this pull request as draft May 4, 2026 14:09
Comment thread src/Profile/Shopware/Gateway/Local/Reader/TimezoneReader.php Outdated
Comment thread src/Profile/Shopware/Premapping/TimezoneReader.php Outdated
Comment thread src/Profile/Shopware/Converter/ShopwareConverter.php Outdated
Comment thread src/Profile/Shopware/Gateway/Local/Reader/EnvironmentReader.php Outdated
Comment thread src/Profile/Shopware/Gateway/Local/Reader/EnvironmentReader.php Outdated
@DennisGarding Dennis Garding (DennisGarding) marked this pull request as ready for review May 8, 2026 06:13
Comment thread src/Profile/Shopware/Converter/ShopwareConverter.php
Comment thread src/Profile/Shopware/Gateway/Api/Reader/EnvironmentReader.php
@@ -0,0 +1,12 @@
<?php declare(strict_types=1);
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is this needed? I would prefer to not mixin php to the acceptance code base

Comment thread tests/acceptance/tests/MigrationTest.spec.ts
Comment thread src/Profile/Shopware/Converter/ShopwareConverter.php
Comment thread src/Profile/Shopware/Converter/ShopwareConverter.php
Comment thread src/Profile/Shopware/Gateway/Local/Reader/EnvironmentReader.php
@MalteJanz Malte Janz (MalteJanz) self-requested a review May 8, 2026 08:32
Copy link
Copy Markdown
Contributor

@MalteJanz Malte Janz (MalteJanz) left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The more I think about it, the more I think the extra effort for reading the SW5 configured timezone isn't worth it. Sorry for leading you down this EnvironmentReader path with my previous comment and our short talk.

What if we apply the simplest solution we could come up with here, just a few of my thoughts (feel free to explore a simpler approach on your own / deviate from this):

  • No reading (or guessing) from the source system at all
  • Premapping has a option for setting the "storage timezone" of the source system, which is like all other premappings put into the mapping table and can be used from there
  • possible choices would be all valid timezones
  • we could think about defaulting / pre-selecting "UTC", if that works for the majority of cases and otherwise the user can still adjust it and migrate again
  • I still like your approach of using Converter->convertValue(..., TYPE_DATETIME) to do the correct conversion automatically, but I would prefer if we could get rid of the extra Context parameter there and initialize the internal used source timezone differently from the mapping

My reasoning behind this:

  • Doing a full "read environment" call is expensive and should not really be necessary. I previously thought we might store the values of that somewhere in the DB but I was wrong about that (turns out we store it on the swag_migration_run but at the premapping stage we don't have a run yet)
  • The other premapping readers also sometimes read from the source system, but they only use a dedicated $gateway->readTable API. In our case we don't need DB data but rather configuration values stored as a file. Introducing extra APIs for that seems not worth the effort
  • Reading the SW5 config from a PHP file is error prone, e.g. they could also store the timezone in a variable and use that in multiple places 'timezone' => $timezone or other strange things
  • (Not sure about this one) but is that config.php really the single source of truth for this configuration in SW5? Is it not possible to override / provide config values via environment variables or other ways, where this config.php value could be wrong / unused?
  • The only reliable way I see would be asking the SW5 backend itself (e.g. they executed config.php and can tell what value is "active"), but that wouldn't work for our local gateway and doesn't seem worth the effort just for giving the user a little more convenience

Comment thread src/DependencyInjection/shopware.php
Comment thread src/Profile/Shopware/Converter/ShopwareConverter.php
Comment on lines +213 to +215
$connectionId = $this->migrationContext->getConnection()->getId();
if (!\array_key_exists($connectionId, $this->timezoneCache)) {
$this->timezoneCache[$connectionId] = $this->mappingService->getValue(
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In addition to what Lars wrote that its not a great idea to have a cache without reset interface in this parent class:

We are only ever dealing with a single connection during the whole migration process. Means there is no point in caching values "per connection", so your cache could just be a ?string instance variable instead of an associative array

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Additionally, if you consider this lookup only needs to happen once per PHP process / request, I'm not even sure if its worth it to put the Context in the method signatures just for that edge case.

E.g. you could also run this lookup once elsewhere, like a dedicated service and in it's constructor, and every convertDateTime then just uses that value and consequently you don't need to pass in the Context at all, means you also don't need error handling when the developer forgots to pass it and its not really a breaking change anymore 🤔

Comment thread src/Profile/Shopware/Gateway/Api/Reader/EnvironmentReader.php
Comment thread src/Migration/EnvironmentInformation.php
Comment thread src/Profile/Shopware/Gateway/Local/Reader/EnvironmentReader.php
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Timezone differences between source and target systems

4 participants