protected function removeOrphanEntities(
        InputInterface $input,
        OutputInterface $output,
        EntityManagerInterface $manager,
        ResourceTypeConfiguration $resourceConfiguration,
        array $foundEntities
    ) {
        $className = $resourceConfiguration->getEntity();
        $metadata = $manager->getClassMetadata($className);
        /** @var EntityRepository $repository */
        $repository = $manager->getRepository($className);
        $ids = isset($foundEntities[$className]) ? $foundEntities[$className] : [];
        $qb = $repository
            ->createQueryBuilder('e')
            ->where("e.{$metadata->getSingleIdentifierColumnName()} NOT IN (:ids)")
            ->setParameter('ids', $ids);

        $results = [];
        foreach ($qb->getQuery()->getResult() as $result) {
            if (!$result instanceof ResourceInterface) {
                throw new \UnexpectedValueException('Results should implement ResourceInterface');
            }
            // We filter the results based on their type, it's really important with single-table inheritance as
            // Doctrine will load all subtype for a current class and this cannot be done easily in the query.
            if ($result->getType() !== $resourceConfiguration->getCode()) {
                continue;
            }
            $results[] = $result;
        }

        $messages = $this->getEntityRemovalMessages($metadata, $results);
        if (!$this->askQuestion($input, $output, $results, $messages)) {
            return;
        }

        foreach ($results as $result) {
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
                $m = "<comment>Removing {$result->getType()}";
                $m .= " : {$result->getPath()} - {$result->getOriginalFileName()}</comment>";
                $output->writeln($m);
            }
            if (!$input->getOption('simulate')) {
                try {
                    $manager->remove($result);
                    $manager->flush($result);
                } catch (\Exception $e) {
                    $m = "<error>An error occured while trying to delete #{$result->getIdentifier()} ";
                    $m .= "{$result->getOriginalFileName()}: {$e->getMessage()}</error>";
                    $output->writeln($m);
                }
            }
        }
    }
protected function removeOrphanEntities(
        InputInterface $input,
        OutputInterface $output,
        EntityManagerInterface $manager,
        ResourceTypeConfiguration $resourceConfiguration,
        array $foundEntities
    ) {
        $className = $resourceConfiguration->getEntity();
        $metadata = $manager->getClassMetadata($className);
        /** @var EntityRepository $repository */
        $repository = $manager->getRepository($className);
        $ids = isset($foundEntities[$className]) ? $foundEntities[$className] : [];
        $qb = $repository
            ->createQueryBuilder('e')
            ->where("e.{$metadata->getSingleIdentifierColumnName()} NOT IN (:ids)")
            ->setParameter('ids', $ids);

        $results = [];
        foreach ($qb->getQuery()->getResult() as $result) {
            if (!$result instanceof ResourceInterface) {
                throw new \UnexpectedValueException('Results should implement ResourceInterface');
            }
            // We filter the results based on their type, it's really important with single-table inheritance as
            // Doctrine will load all subtype for a current class and this cannot be done easily in the query.
            if ($result->getType() !== $resourceConfiguration->getCode()) {
                continue;
            }
            $results[] = $result;
        }

        $messages = $this->getEntityRemovalMessages($metadata, $results);
        if (!$this->askQuestion($input, $output, $results, $messages)) {
            return;
        }

        foreach ($results as $result) {
            if ($output->getVerbosity() >= OutputInterface::VERBOSITY_VERY_VERBOSE) {
                $m = "<comment>Removing {$result->getType()}";
                $m .= " : {$result->getPath()} - {$result->getOriginalFileName()}</comment>";
                $output->writeln($m);
            }
            if (!$input->getOption('simulate')) {
                try {
                    $manager->remove($result);
                    $manager->flush($result);
                } catch (\Exception $e) {
                    $m = "<error>An error occured while trying to delete #{$result->getIdentifier()} ";
                    $m .= "{$result->getOriginalFileName()}: {$e->getMessage()}</error>";
                    $output->writeln($m);
                }
            }
        }
    }
@param InputInterface            $input
@param OutputInterface           $output
@param EntityManagerInterface    $manager
@param ResourceTypeConfiguration $resourceConfiguration
@param array                     $foundEntities

@throws \UnexpectedValueException
@throws \InvalidArgumentException
@throws MappingException
@throws InvalidArgumentException
@throws LogicException
@throws RuntimeException
@throws \BadMethodCallException