Add a helper method to refresh all (or some) entities of a given class
[MAILPOET-5845]
This commit is contained in:
@@ -111,6 +111,24 @@ abstract class Repository {
|
||||
$this->entityManager->refresh($entity);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param callable(T): bool|null $filter
|
||||
*/
|
||||
public function refreshAll(callable $filter = null): void {
|
||||
$className = $this->getEntityClassName();
|
||||
$rootClassName = $this->entityManager->getClassMetadata($className)->rootEntityName;
|
||||
$entities = $this->entityManager->getUnitOfWork()->getIdentityMap()[$rootClassName] ?? [];
|
||||
foreach ($entities as $entity) {
|
||||
if (!($entity instanceof $className)) {
|
||||
continue;
|
||||
}
|
||||
if ($filter && !$filter($entity)) {
|
||||
continue;
|
||||
}
|
||||
$this->entityManager->refresh($entity);
|
||||
}
|
||||
}
|
||||
|
||||
public function flush() {
|
||||
$this->entityManager->flush();
|
||||
}
|
||||
|
Reference in New Issue
Block a user