-
-
Notifications
You must be signed in to change notification settings - Fork 101
Fix children translation based on the parent document. #226
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
Fix children translation based on the parent document. #226
Conversation
(Before the children locale was the request one)
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 proper way would be to get the locale via the ClassMetadata.
if ($class->localeMapping) {
$childrenHints = array('locale' => $class->reflFields[$class->localeMapping]->getValue($document));
} else {
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.
I saw a isDocumentTranslatable method which is not based on localeMapping but
return !empty($metadata->translator)
&& is_string($metadata->translator)
&& count($metadata->translatableFields) !== 0;
Shouldn't be cleaner to do this :
$metadata = $this->dm->getClassMetadata(get_class($document));
if ($this->isDocumentTranslatable($metadata)) {
}
?
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.
i dont think that this is necessary .. the hint is then passed to loadTranslations() which in turn calls isDocumentTranslatable()
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.
but the code i gave you is indeed wrong .. sine this will only work if the locale is mapped in the document
the better way to get the current locale would be:
$oid = spl_object_hash($document);
if (isset($this->documentLocales[$oid]['current'])) {
$childrenHints = array('locale' => $this->documentLocales[$oid]['current']);
} else {
Correction the way to retrieve locale : lukas review
|
could you also try to add a functional test for this? |
|
doh .. i also just found |
|
I'm on the functional test but right now I'm stick with this error (I try to run the tests without my modification first): Fatal error: Call to a member function getRootNode() on a non-object in /home-filer21/nbastien/Workspace/PrestaConcept/website/vendor/doctrine/phpcr-odm/tests/Doctrine/Tests/ODM/PHPCR/Functional/Translation/AttributeTranslationStrategyTest.php on line 218 |
|
Ok I just didn't initialized my testing database ! |
- add test on $doc->getChildren which already works before my modification - add $dm->getChildren($doc) to test my modification of UnitOfWork
|
So here is the functionnal test, I added a Comment entity adn a getChildren method on article I my testCase you will noticed I test on $doc->getChildren() and $dm->getChildren($doc) My modification corrects the $dm->getChildren($doc). I'm waiting for your review ! |
Fix children translation based on the parent document.
|
when we wrote the multilang things, we did not do this on purpose. the reasoning was: the document object only ever exists in one language at the same time. so assume i load one of the children in english, then load its parent in french => the child will change its content to french at this point. or assume i load the parent in french and then again load the child through the document manager. now the child will have changed its language to english because of the dm. see also the discussion on https://github.com/doctrine/phpcr-odm/wiki/Multilanguage - there we thought we would need to load children detached to avoid those issues. i think the use case you fix in this pull request is far more natural and common than the weird thing i describe :-) so maybe indeed its better to do things this way - but then we need to put a warning into the documentation about the issue when working with several languages in parallel. for the content of this PR: the locale is passed along to the proxy, right? |
Hi David, I don't get what you want to do in the proxy ? |
|
are the children documents not proxy objects? so they are not loaded right away but only later if you actually try to access a value of them... oh, and the language propagating does not happen for references, right? maybe it would be more consequent to do that as well. |
|
In this PR I just add the locale in the getChildren method, and simply add the locale in the hint when children document is created so I don't really see where proxy objects are important. For the reference, yes I think you are right. So from my little understanding, I should modify the getReferrers method, right ? |
|
@dbu: i see .. i think that in general we should tell people to really only work with one language per request. if they do work with different locales then they should always load documents as explicit as possible. now i do agree that we should propagate the locale as much as possible. this also means that if you use |
|
ok, makes sense to recommend only one language per request (or really understand what you do). propagating sounds right. what happens right now if the child is already loaded? is it reloaded in another language? regarding proxy, @lsmith77 can you explain this better than i? or am i just confused and we don't use proxies here? @nicolas-bastien referrers are the documents that point to this document, so the inverse relation of the references. there is ReferenceOne and ReferenceMany with the weak and strong options. (but all going through the same code i think.) i think if we propagate, we should do it for all cases, so references and referrers. |
|
so i think what we need to do is the following:
then in a 2nd step we need to review if we need to do anything to assist in the workflow of working with multiple locales in a single request. especially when working with a single document in different locales within the same request non sequentially (ie. i am manipulating the documents in the different locales and i am going back and forth). i see the following scenarios:
|
|
@nicolas-bastien would you be willing to take the lead here? |
|
Hi Lukas, ok I booked tomorrow morning to work on it. I don't know if my phpcr-odm understanding allow me to be lead but I can Nico On 26 January 2013 12:23, Lukas Kahwe Smith [email protected]:
|
|
ok good :) |
|
@nicolas-bastien: step one can be to create test cases for the desired behavior |
|
Hi Lukas, I have been reassigned this week so I will work on it this Nico On 30 January 2013 08:55, Lukas Kahwe Smith [email protected]:
|
|
we recently noticed there is another issue. i did not yet get around to write the test but it seems the scenario is:
now the problem is that "a" now has a translation duplicated for locale en in addition to still have the de translation. |
Fix children translation based on the parent document.
(Before the children locale was the request one)