Symfony2: Doctrine extension Softdeleteable is permanently deleting Translatable elements - php

I'm using the latest version dev-master of Doctrine extensions with Symfony2.7.0.
I added both extensions Softdeleteable and Translatable to my entity. The problem is that when the entity gets soft-deleted its translation gets hard-deleted.
Is there a workaround this?
Edit
I have found this issue on Github, but I can't make much of the answer.

After reviewing the github issues and the proposed "fixes" and consulting experts I have decided that this was more trouble than its worth.
The problem is obviously the listner, and I shouldn't be messing with the bundles under vendor.
When translatables get the 'delete' from my soft-deleted object, these "children" of my object are not really objects of their own thus can't be configured to be soft-deleted.
My solution is to add a deletedAt attribute, NULL by default and when in my controller I used to execute $entityManager->delete($object) I now, just have to change the value of deletedAt to the current DateTime. $object->setDeletedAt($date).
And when retrieving objects I just add a clause SELECT * FROM table_name WHERE deletedAt IS NULL;
This implies changing a lot of queries but it is the simplest option while waiting for a fix.

Related

Doctrine MongoDB ODM does not persist

I'm trying to start using MongoDB with Doctrine MongoDB ODM 1.1.3 and Laravel 5.4. Everything had been going fine before I removed the database called "doctrine" manually (the default database name I guess) in order to clean up the rubbish in it, so basically I just wanted to remove the database and was hoping that Doctrine will create a new one. Now when I'm trying to call
$mgr->persist($divRoot);
$mgr->flush();
It assigns an ID to the $divRoot object, but doesn't persist it. I.e. when I then call the findAll() method on the repo, it returns nothing. And it doesn't create any databases anymore. The $divRoot has changing fields every time I'm trying to save it. I've got really stuck, please help
UPDATE 1
If I initialize a new DocumentManager specifying a new path to the documents (AnnotationDriver::create($documents)), the ODM works normally persisting and retrieving the documents.
I've figured out what was wrong. I was working only with embedded documents whereas it must be at least one root Document. Originally all of them were marked as Documents that's why I was able to persist them, it's nothing to do with the database removal.
So, I was trying to persist a composite consisting out EmbeddedDocuments only.
The solution was to create a root wrapper for the composite marked as Document.

How to log users activity in Symfony

Very simple question I'm not able to find a good answer for...
I have a lot of Entities in my Symfony 2.6 - when ever a user makes some changes to any one of them I would like to have a log entry with who/what/where.
Who maked the changes. (user id)
What did he/she do. ( POST/PUT data)
Where was this done (which entity / url)
[EDIT]
It could perhaps just be a table with these columns:
userid
data
entity
created
[/EDIT]
Is there a bundle for this?
For my projects I usually use the EntityAudit bundle. What it does is save a copy of the old state whenever an audited entity is changed. By comparing those to the current version you can see what has changed.
It also gives you a revision history that lists all the entities that have changed in your database.
You have several Bundles out there that do this, a couple of which have already been mentioned. I've had a lot of success with Gedmo Doctrine Extensions.
Some Documentation here: http://symfony.com/doc/current/cookbook/doctrine/common_extensions.html
And installation instructions here:
https://github.com/Atlantic18/DoctrineExtensions/blob/master/doc/symfony2.md
The installation is the tough part. Once that's done, all you need to do is annotate any entity fields you wish to log.

DoctrineExtensions, does entity have translation in current locale?

I'm using DoctrineExtensions in order to get my entities translated. It works really fine, but i don't know how to resolve this issue :
I use translation fallback, personal translations and ORM query hint in order to reduce DB queries. If the translation doesn't exist, so it will fallback to default values. Till here, there's no problem.
But (this is my question) how could I know that entity has fallen back into the default values ? I mean, if an entity has no translation, is there a way to check it ?
For example, if we want to process this entity somehow whenever there's no translation. Something like :
if (!entity.isTranslated) {
//do something here
}
Of course, just for simplicity, we consider that all fields have been translated or not.
I hope I've been clear enough.
Thanks
I don't think you can do it for now (v2.*).
There is a big refactoring for v3.0, in Translatable there will be no default locale anymore.
See the pull request here: https://github.com/l3pp4rd/DoctrineExtensions/pull/764
no more default locale, all locales are persisted as translations, translatable entity fields serve only as proxy and representation

Doctrine isn't working After version upgrade

I do generate entities from database. Here is a file that I generated before updating to new version of doctrine and with the latest version of doctrine:
http://pastebin.com/g8DsUjmm
You will see, it adds an extra 'ORM' in annotations on new ones.
I am now having problem(Exception) while executing doctrine code which says:
Class GdCities does not exist and could not be loaded /my_path/application/third_party/Doctrine/Common/Persistence/Mapping/RuntimeReflectionService.php
Anyone have any idea, why this is happening. before updating, with old entities and doctrine version, it was working fine.
I did get this resolved by removing the "ORM\" part from all entities' table and column name. Not sure, if its a doctrine bug or I am doing something in different way.

Change a symfony plugin's model

I'm using the symfony plugin "sfMultipleAjaxUploadGalleryPlugin", and I would like to modify it's model.
I want to change the "Photo" class, removing the field "title" and adding the fields "description_fr" and "description_en".
I've made the changes in phpmyadmin, and, in the plugin, I've edited the schema, and the models, filters, and forms to reflect the changes.
I've emptied the cache, but I get doctrine errors concerning the new fields. This plugin is like the admin generator, it extends the class "autosomething", created in the cache at runtime.
Any ideas ? Where else could the photos' model be defined ?
Since it is in the plugins/ folder, I can't just recreate everything using the command-line client.
I am afraid the changes in phpMyAdmin are completely useless, since once you will do a build everything in the database will be managed by symfony itself.
You should first make the wanted changes in the schema, then adjust the relevant classes
in the model
sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/model/doctrine/Photo.class.php and sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/model/doctrine/PhotoTable.class.php,
in the form sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/form/doctrine/PhotoForm.class.php
and possibly in the filters sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/filter/doctrine/PhotoFormFilter.class.php
and check also possible helpers
in sf_plugin_dir/sfMultipleAjaxUploadGalleryPlugin/lib/helper/.
Then you should check every action/template using the changed Photo model (if any) and adjust accordingly.
Finally empty the cache
symfony cc
be sure the changes are reflected in all the model classes (not really important, but still)
symfony doctrine:clean
rebuild everything
symfony doctrine:build --all --no-confirmation
it should work now.

Categories