protected function removeAbstractAndUndefinedNodes($workspaceName)
    {
        $this->dispatch(self::EVENT_NOTICE, 'Checking for nodes with abstract or undefined node types ...');

        $abstractNodeTypes = [];
        $nonAbstractNodeTypes = [];
        foreach ($this->nodeTypeManager->getNodeTypes() as $nodeType) {
            /** @var NodeType $nodeType */
            if ($nodeType->isAbstract()) {
                $abstractNodeTypes[] = $nodeType->getName();
            } else {
                $nonAbstractNodeTypes[] = $nodeType->getName();
            }
        }

        /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
        $queryBuilder = $this->entityManager->createQueryBuilder();

        $queryBuilder
            ->select('n')
            ->distinct()
            ->from(NodeData::class, 'n')
            ->where('n.nodeType NOT IN (:excludeNodeTypes)')
            ->setParameter('excludeNodeTypes', $nonAbstractNodeTypes)
            ->andWhere('n.workspace = :workspace')
            ->setParameter('workspace', $workspaceName);

        $nodes = $queryBuilder->getQuery()->getArrayResult();

        $removableNodesCount = count($nodes);
        if ($removableNodesCount === 0) {
            return;
        }

        foreach ($nodes as $node) {
            $name = $node['path'] === '/' ? '' : substr($node['path'], strrpos($node['path'], '/') + 1);
            $type = in_array($node['nodeType'], $abstractNodeTypes) ? 'abstract' : 'undefined';
            $this->dispatch(self::EVENT_NOTICE, sprintf('Found node with %s node type named "<i>%s</i>" (<i>%s</i>) in "<i>%s</i>"', $type, $name, $node['nodeType'], $node['path']));
        }
        $taskDescription = sprintf('Remove <i>%d</i> node%s with abstract or undefined node types', $removableNodesCount, $removableNodesCount > 1 ? 's' : '');
        $taskClosure = function () use ($nodes) {
            foreach ($nodes as $node) {
                $this->removeNode($node['identifier'], $node['dimensionsHash']);
            }
        };
        $taskRequiresConfirmation = true;
        $this->dispatch(self::EVENT_TASK, $taskDescription, $taskClosure, $taskRequiresConfirmation);
    }