public function checkIntegrity() { $resources = $this->resourceNodeRepo->findAll(); $batchSize = 500; $i = 0; foreach ($resources as $resource) { if ($resource->getWorkspace() === null && ($parent = $resource->getParent())) { if ($workspace = $parent->getWorkspace()) { $resource->setWorkspace($workspace); $this->om->persist($workspace); $this->log('Set workspace ' . $workspace->getName() . ' for ' . $resource->getName()); ++$i; if ($batchSize % $i === 0) { $this->om->flush(); } } } } $this->om->flush(); }