public function getSiteByDomain($domain)
    {
        $queryBuilder = $this->_em->createQueryBuilder();
        $queryBuilder->select('domain, site, primaryDomain')
            ->from(\Rcm\Entity\Domain::class, 'domain')
            ->leftJoin('domain.site', 'site')
            ->leftJoin('domain.primaryDomain', 'primaryDomain')
            ->where('domain.domain = :domainName')
            ->setParameter('domainName', $domain);

        try {
            /** @var \Rcm\Entity\Domain $domain */
            $domain = $queryBuilder->getQuery()->getSingleResult();
        } catch (NoResultException $e) {
            return null;
        }

        if ($domain->getPrimary()) {
            $site = $domain->getPrimary()->getSite();
            $this->_em->detach($site);
            $this->_em->detach($domain);
            $site->setDomain($domain);
        } else {
            $site = $domain->getSite();
        }

        return $site;
    }