Fixed some ugly issues with entities where certain changes where not written to database, after the event logger subscriber were called.

This commit is contained in:
Jan Böhmer 2023-01-24 22:55:03 +01:00
parent d06701fa87
commit 6296cac962
2 changed files with 30 additions and 4 deletions

View file

@ -76,6 +76,26 @@ class EventLogger
return false;
}
/**
* Same as log(), but this function can be safely called from within the onFlush() doctrine event, as it
* updated the changesets of the unit of work.
* @param AbstractLogEntry $logEntry
* @return bool
*/
public function logFromOnFlush(AbstractLogEntry $logEntry): bool
{
if ($this->log($logEntry)) {
$uow = $this->em->getUnitOfWork();
//As we call it from onFlush, we have to recompute the changeset here, according to https://www.doctrine-project.org/projects/doctrine-orm/en/2.14/reference/events.html#reference-events-on-flush
$uow->computeChangeSet($this->em->getClassMetadata(get_class($logEntry)), $logEntry);
return true;
}
//If the normal log function does not added the log entry, we just do nothing
return false;
}
/**
* Adds the given log entry to the Log, if the entry fullfills the global configured criterias and flush afterwards.
*