-
-
Notifications
You must be signed in to change notification settings - Fork 97
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
Retrieve locales for non-persisted documents #372
Conversation
Hacky fix to retrieve locales for not-yet-in-storage documents
Infact, I remember having a similar discussion about this a while back with @dbu when I had to add the following code to determine if a document existed. protected function documentIsPersisted($document)
{
$metadata = $this->dm->getClassMetadata(get_class($document));
$id = $metadata->getIdentifierValue($document);
$phpcrSession = $this->dm->getPhpcrSession();
return $phpcrSession->nodeExists($id);
} So its a question of if the UnitOfWork should be able to determine if a document has actually exists in storage - I think it should. |
there is |
That does not tell you if the document is persisted or not. It only says On Sat, Oct 26, 2013 at 08:26:35AM -0700, Lukas Kahwe Smith wrote:
|
Ah, I think now I remember the previous discussion. However I am not sure if |
Yeah, sorry, the above code was just to illustrate where I had to work around this - a better method name should probably use the word "comitted", e.g. This PR adds a try/catch to |
$node = $this->session->getNode($this->getDocumentId($document)); | ||
$locales = $this->dm->getTranslationStrategy($metadata->translator)->getLocalesFor($document, $node, $metadata); | ||
} catch (PathNotFoundException $e) { | ||
$locales = array(); |
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 this is a lie, right? i mean the document will currently have a locale, which it will have once flushed. and if we previously called bindTranslation, there might even exist several translations. you could try to look into $this->documentTranslations[$oid] which has a list of currently bound locales (and then the actual fields under each locale).
messing with the states is difficult, and starting to have some sort of sub-state is tricky as well. when looking into |
Actually this really hits the wall with: symfony-cmf/routing-auto-bundle#33 Basically I need not only to get the locales, but the translated fields also before flush and the UOW makes my head spin round. |
oh, i see. i think it would be the correct behaviour for both findTranslation and getLocalesFor to work on unflushed documents. find(null, '/path') works if the document is existing but not flushed, right? then it would be logical for the others to work as well. all translations are stored in $this->documentTranslations by oid and locale. this should be usable to restore the document to a different translation. |
Replaced by : #375 |
Hacky fix to retrieve locales for not-yet-in-storage documents. Currently if you try
getLocalesFor
on a new and persisted document the UOW will call the session to get the node which will throw a "node not found in workspace" exception.This PR adds a try catch - but this should not be necessary.
Basically we just need to determine if this document has been loaded by the UOW - but there is no
STATE_*
constant that corresponds to this -- is there a better way to do this today?