/** * @inheritDoc */ protected function processQuery(JoinWalk $walk) { $this->logger->notice('Doing hard deletion'); // Get query $this->logger->notice('Getting select query for {target}', ['target' => $walk->getTargetId()]); $query = $walk->getQuery(); $this->debugQuery($query); // Output join information $this->logger->info((string) $walk); // Get iterator $iterator = $query->iterate(null); // Iterate through results $this->logger->notice('Iterating through results...'); $i = 0; $total = 0; foreach ($iterator as $result) { $entity = $result[0]; $this->em->remove($entity); // Queue delete $total++; if ($i > $this->chunk->getEstimatedSize()) { $this->flush($i); // Actually apply changes $i = 0; } $i++; } if ($i > 0) { // Remaining in current chunk $this->flush($i); } elseif ($i == 0) { $this->logger->notice('No results.'); } $this->logger->notice('Done with {target} ({total} deleted)', ['target' => $walk->getTargetId(), 'total' => $total]); }
/** * @param JoinWalk $walk * @return void */ protected function processQuery(JoinWalk $walk) { $this->logger->notice('Doing deletion'); // Get query $this->logger->notice('Getting select query for {target}', ['target' => $walk->getTargetId()]); $query = $walk->getQuery(); $this->debugQuery($query); // Output join information $this->logger->info((string) $walk); // Get iterator $iterator = $query->iterate(null); // Output file information $file = $this->fileFactory->getFile($this->getClassName($walk->getTargetId())); $this->logger->notice('Outputting to {file}', ['file' => (string) $file]); // Iterate through results $this->logger->notice('Iterating through results...'); $i = 0; foreach ($iterator as $result) { $entity = $result[0]; $array = $this->entityToArray($entity); $file->writeObject($array); // Write to file $this->em->remove($entity); // Queue delete $i++; if ($i > $this->chunk->getEstimatedSize()) { $this->flush($file, $i); // Actually apply changes $i = 0; } } if ($i > 0) { // Remaining in current chunk $this->flush($file, $i); } elseif ($i == 0) { $this->logger->notice('No results.'); } $this->logger->notice('Done with {target}', ['target' => $walk->getTargetId()]); $file->close(); }