Updates or creates a site with the given $siteNodeName

@param string $siteNodeName
@return Site
199062
protected function getSiteByNodeName($siteNodeName)
    {
        $site = $this->siteRepository->findOneByNodeName($siteNodeName);

        if ($site === null) {
            $site = new Site($siteNodeName);
            $this->siteRepository->add($site);
        } else {
            $this->siteRepository->update($site);
        }

        return $site;
    }
1026114
public function isValidNodename($nodeName)
    {
        try {
            $parts = explode(':', $nodeName);
            if (1 > count($parts) || 2 < count($parts)) {
                return new RepositoryException("Name contains illegal characters: $nodeName");
            }
            if (0 === strlen($parts[0])) {
                return new RepositoryException("Name may not be empty: $nodeName");
            }
            PathHelper::assertValidLocalName($parts[0]);
            if (2 == count($parts)) {
                // [0] was the namespace prefix, also check the name
                PathHelper::assertValidLocalName($parts[1]);
                if (0 === strlen($parts[1])) {
                    return new RepositoryException("Local name may not be empty: $nodeName");
                }
            }
        } catch (RepositoryException $e) {
            return $e;
        }
    }
191954
protected function prepareNewSite(
        Site $newSite,
        array $defaultSiteSettings,
        string $createdByUserId,
        string $createdReason
    ) {
        $siteId = $newSite->getSiteId();
        if (!empty($siteId)) {
            throw new \Exception(
                "Site ID must be empty to create new site, id {$siteId} given."
            );
        }

        if (empty($newSite->getDomain())) {
            throw new \Exception('Domain is required to create new site.');
        }

        return $this->prepareDefaultValues(
            $newSite,
            $defaultSiteSettings,
            $createdByUserId,
            $createdReason
        );
    }
1266058
private function createRootPage($site, $layout)
    {
        $pagebuilder = $this->bbapp->getContainer()->get('pagebuilder');
        $pagebuilder
            ->setUid(md5('root-' . $site->getLabel()))
            ->setTitle('Home')
            ->setLayout($layout)
            ->setSite($site)
            ->setUrl('/')
            ->putOnlineAndHidden()
        ;

        $page = $pagebuilder->getPage();
        $this->entyMgr->persist($page);
        $this->entyMgr->flush($page);

        return $page;
    }
564485
protected function exportSite(Site $site, $nodeTypeFilter)
    {
        /** @var ContentContext $contentContext */
        $contentContext = $this->contextFactory->create([
            'currentSite' => $site,
            'invisibleContentShown' => true,
            'inaccessibleContentShown' => true
        ]);

        $siteNode = $contentContext->getCurrentSiteNode();

        $this->xmlWriter->startElement('site');
        $this->xmlWriter->writeAttribute('name', $site->getName());
        $this->xmlWriter->writeAttribute('state', $site->getState());
        $this->xmlWriter->writeAttribute('siteResourcesPackageKey', $site->getSiteResourcesPackageKey());
        $this->xmlWriter->writeAttribute('siteNodeName', $siteNode->getName());

        $this->nodeExportService->export($siteNode->getPath(), $contentContext->getWorkspaceName(), $this->xmlWriter, false, false, $this->resourcesPath, $nodeTypeFilter);

        $this->xmlWriter->endElement();
    }
81717
public function createReferenceBulkForNode($nodeId, $siteIdList)
    {
        // @todo Optimize me
        foreach ($siteIdList as $siteId) {
            $this
                ->db
                ->merge('ucms_site_node')
                ->key(['nid' => $nodeId, 'site_id' => $siteId])
                ->execute()
            ;
        }

        $this
            ->entityManager
            ->getStorage('node')
            ->resetCache([$nodeId])
        ;

        $this->eventDispatcher->dispatch(NodeEvents::ACCESS_CHANGE, new ResourceEvent('node', [$nodeId]));
        $this->eventDispatcher->dispatch(SiteEvents::EVENT_ATTACH, new SiteAttachEvent($siteIdList, $nodeId));
    }
583886
public function update($siteId, $data)
    {
        //ACCESS CHECK
        if (!$this->isAllowed(
            ResourceName::RESOURCE_SITES,
            'admin'
        )
        ) {
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_401);

            return $this->getResponse();
        }

        if (!is_array($data)) {
            throw new \Exception('Invalid data format');
        }

        /** @var \Doctrine\ORM\EntityManager $entityManager */
        $entityManager = $this->getEntityManager();

        /** @var \Rcm\Repository\Site $siteRepo */
        $siteRepo = $entityManager->getRepository(\Rcm\Entity\Site::class);

        if (!$siteRepo->isValidSiteId($siteId)) {
            $this->getResponse()->setStatusCode(Response::STATUS_CODE_400);

            return $this->getResponse();
        }

        /** @var \Rcm\Entity\Site $site */
        $site = $siteRepo->findOneBy(['siteId' => $siteId]);

        $newStatus = $site->getStatus();

        if ($data['status'] == 'D') {
            $newStatus = 'D';
        }
        if ($data['status'] == 'A') {
            $newStatus = 'A';
        }

        $site->setStatus($newStatus);

        $site->setModifiedByUserId(
            $this->getCurrentUserId(),
            "Update site status to {$newStatus} in " . get_class($this)
        );

        $entityManager->persist($site);
        $entityManager->flush($site);

        $this->siteVersionRepo->publish(
            new SiteLocator($site->getDomainName()),
            $this->getSiteManager()->siteToImmutableSiteContent($site),
            $this->getCurrentUserTracking()->getId(),
            __CLASS__ . '::' . __FUNCTION__,
            $site->getSiteId()
        );

        return new JsonModel($site);
    }
763905
public function setSite(Site $site)
    {
        if ($this->site !== $site) {
            $this->site = $site;
            $this->multilingualSections = null;
            $this->isMultilingualEnabled = null;
        }

        return $this;
    }
69391
public function getRoot()
    {
        $cacheKey = 'coral.sitemap.nodes';
        if(false === ($root = $this->cache->fetch($cacheKey)))
        {
            $root = $this->readNode($this->contentPath);

            if(!$this->cache->save($cacheKey, $root))
            {
                // @codeCoverageIgnoreStart
                throw new \Coral\SiteBundle\Exception\SitemapException("Unable to store into cache.");
                // @codeCoverageIgnoreEnd
            }
        }

        return $root;
    }
580608
static function SitemapCacheFile(Site $site)
    {
        $cacheFolder = Path::Combine(PHINE_PATH, 'App/Phine/Cache/Sitemap');
        $filename = Path::AddExtension($site->GetID(), 'xml');
        return Path::Combine($cacheFolder, $filename);
    }
817854
public function setSite(\BlackForest\PiwikBundle\Entity\PiwikSite $site = null)
    {
        $this->site = $site;

        return $this;
    }
272701
public function deleteReferenceBulkFromSite($siteId, $nodeIdList)
    {
        if (!$nodeIdList) {
            return;
        }

        $this
            ->db
            ->delete('ucms_site_node')
            ->condition('nid', $nodeIdList)
            ->condition('site_id', $siteId)
            ->execute()
        ;

        $this
            ->entityManager
            ->getStorage('node')
            ->resetCache($nodeIdList)
        ;

        $this->eventDispatcher->dispatch(NodeEvents::ACCESS_CHANGE, new ResourceEvent('node', $nodeIdList));
        $this->eventDispatcher->dispatch(SiteEvents::EVENT_DETACH, new SiteAttachEvent($siteId, $nodeIdList));
    }
1246815
public function setTitle($title, $siteName = null, $separator = null)
    {
        $this->meta()->setTitle($title, null, $separator);
        $this->openGraph()->setTitle($title);
        $this->twitter()->setTitle($title);

        return $this->setSiteName($siteName);
    }
756201
public function onSiteClone(SiteCloneEvent $event)
    {
        $source = $event->getTemplateSite();
        $target = $event->getSite();

        $this->ensureSiteMenus($source);
        $this->ensureSiteMenus($target);

        if ($this->treeManager && $this->allowedMenus) {
            foreach (array_keys($this->allowedMenus) as $prefix) {

                $sourceName = $prefix . '-' . $source->getId();
                $targetName = $prefix . '-' . $target->getId();

                $this->treeManager->cloneMenuIn($sourceName, $targetName);
            }
        }
    }
1280390
public function svnUsers($site)
    {
        $variables = array('site' => $site);
        $request = $this->get(array('{+base_path}/sites/{site}/svnusers.json', $variables));
        return new Response\SvnUsers($request);
    }
519339
protected function FormUrl(Site $site = null)
    {
        $args = array();
        if ($site)
        {
            $args['site'] = $site->GetID();
        }
        return BackendRouter::ModuleUrl(new SiteForm(), $args);
    }
84956
protected function prepareNewSite(Site $newSite)
    {
        $siteId = $newSite->getSiteId();
        if (!empty($siteId)) {
            throw new \Exception(
                "Site ID must be empty to create new site, id {$siteId} given."
            );
        }

        if (empty($newSite->getDomain())) {
            throw new \Exception('Domain is required to create new site.');
        }

        return $this->prepareDefaultValues($newSite);
    }