-
Notifications
You must be signed in to change notification settings - Fork 152
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
Add command to change system language #24
Add command to change system language #24
Conversation
6f5694d
to
46a4d61
Compare
hey @JoshuaBehrens |
46a4d61
to
21c8093
Compare
Feels like a simple rebase is not the solution :D |
21c8093
to
d502e0f
Compare
|
||
private function getLocaleId(string $iso): string | ||
{ | ||
$stmt = $this->connection->prepare('SELECT locale.id FROM locale WHERE LOWER(locale.code) = LOWER(?)'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you can use like. it's faster.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A like is case insensitive? ... When I just read this. I could've input the argument lowered first 😅 If I use like I have to escape the right-hand-side.
And if we change something here we have to change it in shopware/recovery as well.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The usage of function on the left side is slow, because it can't use the index.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, having a function on the left is slow. Good thing it is not used very frequent. But does like really help here?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it is case insenstive only if the column uses a _ci
collation which I think is the case with Shopware columns.
In that case =
actually already does the trick. If necessary one can do something like code = 'de-de' COLLATE utf8mb4_unicode_ci
to ensure case insensitive column comparison is used. But as mentioned I think Shopware creates columns case insensitive, so it should not be necessary.
$output->section('Shop locale'); | ||
|
||
$locale = $input->getArgument('locale'); | ||
$this->setDefaultLanguage($locale); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you definetly have to clear the cache after you changed the system language,
the whole entity cache is stale at this point leading to numerous ugly bugs 😆
Been there, done that 🤣
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How do suggest to clear the cache? I thought I've done that here. I must admit I am a bit out of the topic by now :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You've done that when the command get's called as part of the system install command, not if it is run by itself.
You can inject the \Shopware\Core\Framework\Adapter\Cache\CacheClearer
into the service and use the clear()
method.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Hey @JoshuaBehrens, could you take care of the comment from @keulinho? 🙂
Additionally this can never fully work after the fact: We should clearly state that shortcomming in the description of the command and maybe even prefix that command with It totally makes sense to add the locale option to the system:install command, adding a command in general that allows changing the system default language at any time needs some more consideration. |
Hey @keulinho I am on it shopware/shopware#860 with the guys from wexo for the command that can be run anytime you want. That is capable of changing every translation at runtime. I run 5 or 6 installations with this pull request and German as default language. At the time of this pull request the boost days were far away. I just need this command to easily integrate it into the setup command. |
d502e0f
to
35c24c3
Compare
@keulinho I did some changes to prevent unintended execution. With this lock the cache will get cleared by the followed command in any case so that is not a problem either anymore. My locking might be just a bit... exotic :) |
Language creation is missing when it's not existing by default |
What about currency etc.? Also why not use the ShopService from Recovery for this? might require it to be moved elsewhere? |
Without adjusting the /**
* @param array<string, array<string, string>> $commands
*
* @return int
*/
private function runCommands(array $commands, OutputInterface $output): int
{
foreach ($commands as $parameters) {
$output->writeln('');
$command = $this->getApplication()->find($parameters['command']);
if (!$command->getDefinition()->hasArgument('command')) {
unset($parameters['command']);
}
$returnCode = $command->run(new ArrayInput($parameters, $command->getDefinition()), $output);
if ($returnCode !== 0) {
return $returnCode;
}
}
return 0;
} |
@AndreasA this is a problem of this repository. There is already a pull request solving this. I like your approach to exit early when a command fails. |
OK. Thanks for the informatin. One other thing. In the shopService the swap language command does not disable foreign key checks which is important as otherwise, e.g. the mail template contents will not be switched. It is done like this: private function swapDefaultLanguageId(string $newLanguageId): void
{
$stmt = $this->connection->prepare(
'UPDATE language
SET id = :newId
WHERE id = :oldId'
);
// assign new uuid to old DEFAULT
$stmt->execute(
[
'newId' => Uuid::randomBytes(),
'oldId' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
]
);
// change id to DEFAULT
$stmt->execute(
[
'newId' => Uuid::fromHexToBytes(Defaults::LANGUAGE_SYSTEM),
'oldId' => $newLanguageId,
]
);
} |
|
||
private function swapDefaultLanguageId(string $newLanguageId): void | ||
{ | ||
$this->connection->exec('SET FOREIGN_KEY_CHECKS = 0'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
as mentioned in comments, in recovery's ShopService they are not disabled which is a better solution as CASCADE UPDATE takes care of all necessary changes and this way, the content of mail templates etc. is correctly assigned.
Even better would be to re-assign everything correctly afterwards but...
One more question: In case the system default language is part of a language pack. How would one ensure the language pack is loaded prior to executing the system default change command? Although I guess it does not matter if it is installed afterwards? |
This PR was closed due to inactivity. If this change is still important to you, feel free to create a new pull request. |
Hi @JoshuaBehrens , as Niklas said, we'd like to integrate this change, do you think you'll find the time to complete this? |
Hi @philipgatzka Not before Saturday. Should this make it into the 6.4? |
Glad to hear that, merging this before 6.4 is not a requirement and too short of a timeframe either way I think. I didn't intend to build up pressure here, just wanted to know whether/how we can proceed 🙂 As far as I can tell there's one suggestion still open, just let us know if you need any information or assistance with this or any other roadblocks. |
I see this pull request is labeled as "scheduled", when can I expect this PR to merged and make it into a future Shopware update? I'm also in need of this feature! 😎 |
Hi @dfsoeten , as mentioned above, this PR is still incomplete (I forgot to set the label correctly the last time, sorry for that 🙈). We intend to include the change as soon as it's finished. |
Ah, that's a mistake on my part then. Haven't read the entire conversation carefully enough. Thank you for clarifying |
SO adding the last suggestion from @keulinho, and PR will be completed? @JoshuaBehrens @shyim AFAIK: Change this
To:
ANd than use the cache clearer, since the cache clearer is is clearing in the SystemLocaleCommand?
|
@unugiyen I'll have a look at that :) thank you very much |
Hi @JoshuaBehrens, |
I had a look at @unugiyen changes and they were good but I didn't integrate them yet. Shall I? :) |
Hi @JoshuaBehrens, |
Please i need this commit in the original shopware production template git <3 @JoshuaBehrens |
We will provide an option to do this "shortly" ™️ in the shopware platform, |
@keulinho I think it is now, so I guess this PR could be closed? After all with 6.4.6.0, there is a command to change it: and it can also be set at the beginning: |
@AndreasA Yep v6.4.6.0 already includes a command to change the language afterward, and you can set it during CLI set up, so i'm closing this PR. If you have any issues or anything is missing in those commands, please open another issue or another PR. |
WE HAVE A COMMAND NOW :O 💙 💙 💙 💙 💙 💙 💙 💙 |
I had a look at it and yes, I will amend it :) nothing troublesome so far. We will see how well it does in our next projects. Thank you so much @keulinho for this command! |
For all that are running into this. The command is not perfect yet! Change your default language ASAP after installation |
Now you can run and get an administration using German as system language. Useful for German only shops that don't force the users to enter English data first. Can be applied to any other locale that shopware ships.
Lots of it is 📋🍝 from recovery.