l3pp4rd/DoctrineExtensions — pull request #576 by rjbijl (2013-01-23 07:11:33+00:00)
Title: Fatal error, call to undefined function getObject() in TranslatableListener

The situation is a follows:
- I use the translatableListener, with setPersistDefaultLocaleTranslation=true
- I have an entity which uses a non-personalised translation entity
- I have existing data in this entity, and the translation table is filled
- | add a new translated property to the existing entity
- I try to add translations for this new property to existing row, by using the standard translate() function

I now get a fatal error when trying to add the translation for the new property in the default language:

This is caused by the following if statement in the translation listener (around line 503)
```php
if ($locale !== $this->defaultLocale
&& get_class($trans) === $translationClass
&& $trans->getLocale() === $this->defaultLocale
&& $trans->getField() === $field
&& $trans->getObject() === $object) {
```

The thing is that the $trans object does not necessarily has a getObject function, since it does not have to be a personalized translation. It does not crash for the other translations, because they never arrive that deep in the if statement to make the call to getObject.

I fixed it by replacing the final clause of the AND statement by a call to a new function objectBelongsTo(), that does the same check, but keeps in mind that we are dealing with either an instance of AbstractTranslation, or an instance of AbstractPersonalTranslation. Otherwise, it throws an exception.