-
Notifications
You must be signed in to change notification settings - Fork 121
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
Softdeleteable Entities not Logging Deletion #323
Comments
I managed somehow to fix it by overwriting the DoctrineSubscriber priority like this (in my app ./config/services.yaml file):
This results in having on the audit table a |
The same bug here. v. 5.0.0 |
I had to overwrite the priority of the services above to have some sort of working solution. using version 5.2 of the auditor bundle |
Hi,
I investigated this issue based on the comments here and found a bit of hacky but less disrupting way around this issue without duplicate or inconsistent audit logs by implementing a preFlush event listener which could be helpful for others as well as long as this issue persists. <?php
namespace App\EventListener;
use Doctrine\Bundle\DoctrineBundle\Attribute\AsDoctrineListener;
use Doctrine\ORM\Event\PreFlushEventArgs;
use Doctrine\ORM\Events;
use Gedmo\SoftDeleteable\SoftDeleteableListener;
#[AsDoctrineListener(event: Events::preFlush)]
class PreFlushListener
{
/**
* Hacky way to swap the priority of the {@see SoftDeleteableListener} to be applied after the {@see DoctrineSubscriber}.
* @param PreFlushEventArgs $eventArgs
* @return void
*/
public function preFlush(PreFlushEventArgs $eventArgs): void
{
$eventManager = $eventArgs->getObjectManager()->getEventManager();
$eventListeners = $eventManager->getListeners(Events::onFlush);
foreach ($eventListeners as $eventListener) {
if ($eventListener instanceof SoftDeleteableListener) {
$softDeleteableListener = $eventListener;
$eventManager->removeEventListener(Events::onFlush, $softDeleteableListener);
break;
}
}
if (isset($softDeleteableListener)) {
$eventManager->addEventListener(Events::onFlush, $softDeleteableListener);
}
}
} |
Notes: I have notes in one of my subscribers while listening to LifeCycle events. |
auditor-bundle
versionSummary
Almost exactly the same issue as #122, entities tagged as soft-deletable do not seem to fire an audit event. Regular deletions are logged, updates and insertions are also logged. The
deletedAt
column is updated with the time when a soft-delete happens. Usingv1.7.0
of StofDoctrineExtensionsBundleCurrent behavior
When removing an entity annotated with
@Gedmo\SoftDeletable
(also tried with YAML mapping previously and did not work) with$entitymanager->remove($entity);
, the entity is soft deleted as expected but no audit log entry appears for the deletion.How to reproduce
@Gedmo\SoftDeleteable(fieldName="deletedAt", timeAware=false)
Expected behavior
Entity should be soft deleted, an update audit entry showing the setting of
deletedAt
field should be generated.The text was updated successfully, but these errors were encountered: