public function purgeDatabase($persistence, $databaseName = null, $withTruncate = false)
    {
        $purgetools = array(
            'orm'       => array(
                'purger'    => 'Doctrine\Common\DataFixtures\Purger\ORMPurger',
                'executor'  => 'Doctrine\Common\DataFixtures\Executor\ORMExecutor',
            ),
            'mongodb'   => array(
                'purger'    => 'Doctrine\Common\DataFixtures\Purger\MongoDBPurger',
                'executor'  => 'Doctrine\Common\DataFixtures\Executor\MongoDBExecutor',
            )
        );
        // Retrieve the correct purger and executor
        $purge_class = $purgetools[$persistence]['purger'];
        $executor_class = $purgetools[$persistence]['executor'];

        // Instanciate purger and executor
        $persister = $this->getPersister($persistence);
        $entityManagers = ($databaseName)
            ? array($persister->getManager($databaseName))
            : $persister->getManagers();

        foreach ($entityManagers as $entityManager) {
            $purger = new $purge_class($entityManager);
            if ($withTruncate && $purger instanceof ORMPurger) {
                $purger->setPurgeMode(ORMPurger::PURGE_MODE_TRUNCATE);
            }
            $executor = new $executor_class($entityManager, $purger);
            // purge
            $executor->purge();
        }
    }