@deprecated Use Rcm\Repository\Site\CopySite
copySite

@param Site $existingSite
@param Domain $domain

@return Site
162281
protected function copySite(
        Site $existingSite,
        Domain $domain
    ) {
        $entityManager = $this->getEntityManager();

        $user = $this->getCurrentUserTracking();

        $domain->setModifiedByUserId(
            $user->getId(),
            'Copy site in ' . get_class($this)
        );

        $copySite = $existingSite->newInstance(
            $user->getId(),
            'Copy site in ' . get_class($this),
            false
        );
        $entityManager->persist($copySite);

        $copySite->setSiteId(null);
        $copySite->setDomain($domain);

//        $entityManager->flush($domain);
//        $entityManager->flush($copySite);

        // NOTE: site::newInstance() does page copy too

        $containers = $copySite->getContainers();
        $containerRevisions = [];

        /** @var Container $container */
        foreach ($containers as $container) {
            $containerRevision = $container->getPublishedRevision();
            $containerRevisions[] = $containerRevision;
            $entityManager->persist($container);
            $entityManager->persist($containerRevision);
        }

        $entityManager->flush($containers->toArray());
        $entityManager->flush($containerRevisions);
        $entityManager->flush($domain);
        $entityManager->flush($copySite);

        foreach ($containers as $container) {
            $this->immutableSiteWideContainerRepo->duplicateBc(
                new SiteWideContainerLocator($existingSite->getSiteId(), $container->getName()),
                new SiteWideContainerLocator($copySite->getSiteId(), $container->getName()),
                new ContainerContent($this->pageContentFactory->pluginWrappersToFlatBlockInstances(
                    $container->getPublishedRevision()->getPluginWrappers()->toArray()
                )),
                $this->getCurrentUserTracking()->getId(),
                __CLASS__ . '::' . __FUNCTION__
            );
        }


        /** @var Page $page */
        foreach ($existingSite->getPages() as $page) {
            if (empty($page->getPublishedRevision())) {
                continue; //Don't copy unpublished pages
            }
            $destinationPage = $this->pageMutationService->duplicatePage(
                $user,
                $page,
                $copySite->getSiteId(),
                $page->getName()
            );
        }

        return $copySite;
    }
1102993
public function build($locale, $domain = 'gui')
    {
        $cache = new ConfigCache($this->cacheDir.'/translations-'.$locale.'.js', $this->debug);

        if (!$cache->isFresh()) {
            $content = $this->buildContent($locale, $domain);

            $cache->write($content->getContent(), $content->getResources());

            if (!$this->debug) {
                $this->compressor->compressFile((string) $cache);
            }
        }

        return new Asset((string) $cache);
    }
283711
public static function currentOrFailByDomain($domain)
	{
		$factor = static::all()->whereEquals('user_id', User::get('id'))
		                       ->whereEquals('domain', $domain)
		                       ->row();

		return ($factor->isNew()) ? false : $factor;
	}
1299539
public function pruneSite(Site $site)
    {
        $siteNodePath = NodePaths::addNodePathSegment(static::SITES_ROOT_PATH, $site->getNodeName());
        $this->nodeDataRepository->removeAllInPath($siteNodePath);
        $siteNodes = $this->nodeDataRepository->findByPath($siteNodePath);
        foreach ($siteNodes as $siteNode) {
            $this->nodeDataRepository->remove($siteNode);
        }

        $site->setPrimaryDomain(null);
        $this->siteRepository->update($site);

        $domainsForSite = $this->domainRepository->findBySite($site);
        foreach ($domainsForSite as $domain) {
            $this->domainRepository->remove($domain);
        }
        $this->persistenceManager->persistAll();

        $this->siteRepository->remove($site);

        $this->emitSitePruned($site);
    }
619833
public static function createXDomain($domain)
	{
		$db = \App::get('db');

		if (empty($domain) || ($domain == 'hubzero'))
		{
			return false;
		}

		$query = 'SELECT domain_id FROM `#__xdomains` WHERE ' .
				 '#__xdomains.domain=' . $db->quote($domain);

		$db->setQuery($query);

		$result = $db->loadObject();

		if (empty($result))
		{
			$query = 'INSERT INTO `#__xdomains` (domain) VALUES (' . $db->quote($domain) . ')';

			$db->setQuery($query);

			$db->query();

			$domain_id = $db->insertid();
		}
		else
		{
			$domain_id = $result->domain_id;
		}

		return $domain_id;
	}
580226
public function setDomain(?string $domain) : Cookie
    {
        if ($domain !== null) {
            $domain = (string) $domain;
        }

        $this->domain = $domain;

        return $this;
    }
1178584
public function duplicateToSubsite($subsiteID = null, $includeChildren = false)
    {
        $clone = $this->owner->duplicateToSubsitePrep($subsiteID, $includeChildren);
        $clone->invokeWithExtensions('onBeforeDuplicateToSubsite', $this->owner);

        if (!$includeChildren) {
            // Write the new page if "include children" is false, because it is written by default when it's true.
            $clone->write();
        }
        // Deprecated: manually duplicate any configured relationships
        $clone->duplicateSubsiteRelations($this->owner);

        $clone->invokeWithExtensions('onAfterDuplicateToSubsite', $this->owner);

        return $clone;
    }
1181439
public function duplicate($doWrite = true, $manyMany = 'many_many')
    {
        $duplicate = parent::duplicate($doWrite);

        $oldSubsiteID = SubsiteState::singleton()->getSubsiteId();
        self::changeSubsite($this->ID);

        /*
         * Copy data from this object to the given subsite. Does this using an iterative depth-first search.
         * This will make sure that the new parents on the new subsite are correct, and there are no funny
         * issues with having to check whether or not the new parents have been added to the site tree
         * when a page, etc, is duplicated
         */
        $stack = [[0, 0]];
        while (count($stack) > 0) {
            list($sourceParentID, $destParentID) = array_pop($stack);
            $children = Versioned::get_by_stage('Page', 'Live', "\"ParentID\" = $sourceParentID", '');

            if ($children) {
                foreach ($children as $child) {
                    self::changeSubsite($duplicate->ID); //Change to destination subsite

                    $childClone = $child->duplicateToSubsite($duplicate, false);
                    $childClone->ParentID = $destParentID;
                    $childClone->writeToStage('Stage');
                    $childClone->copyVersionToStage('Stage', 'Live');

                    self::changeSubsite($this->ID); //Change Back to this subsite

                    array_push($stack, [$child->ID, $childClone->ID]);
                }
            }
        }

        self::changeSubsite($oldSubsiteID);

        return $duplicate;
    }
326008
public function deleteDomainAction(Domain $domain)
    {
        $site = $domain->getSite();
        if ($site->getPrimaryDomain() === $domain) {
            $site->setPrimaryDomain(null);
            $this->siteRepository->update($site);
        }
        $this->domainRepository->remove($domain);
        $this->addFlashMessage('The domain "%s" has been deleted.', 'Domain deleted', Message::SEVERITY_OK, [htmlspecialchars($domain)], 1412373310);
        $this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $site]);
    }
1039776
public function createPointer($domain, $alias = false)
    {
        $parameters = [
            'domain' => $this->domainName,
            'from' => $domain,
            'action' => 'add',
        ];
        if ($alias) {
            $parameters['alias'] = 'yes';
            $list = &$this->aliases;
        } else {
            $list = &$this->pointers;
        }
        $this->getContext()->invokeApiPost('DOMAIN_POINTER', $parameters);
        $list[] = $domain;
        $list = array_unique($list);
    }
1271371
public function setActiveSite(SiteInterface $site = null)
    {
        $this->site = $site;
        $this->app->instance(SiteModel::class, $site);

        return $this;
    }
235099
public function createForSite(SiteInterface $site)
    {
        $listRedirection = $this->redirectionRepository->findBySiteId($site->getSiteId());
        $siteLanguages = $site->getLanguages();
        $routes = array();

        foreach ($siteLanguages as $language) {
            $nodes = $this->nodeRepository->findPublishedByLanguageAndSiteId($language, $site->getSiteId());
            $routePattern = $this->nodeRepository->findAllRoutePattern($language, $site->getSiteId());
            $routePattern = $this->computeRoutePattern($routePattern);
            foreach ($nodes as $node) {
                $routes = array_merge($this->generateRoutesForNode($node, $site, $routePattern), $routes);
            }
        }

        foreach ($listRedirection as $redirection) {
            $routes = array_merge($this->generateRoutesForRedirection($redirection, $site), $routes);
        }

        return $routes;
    }
848957
public function newDomainAction(Domain $domain = null, Site $site = null)
    {
        $this->view->assignMultiple([
            'domain' => $domain,
            'site' => $site,
            'schemes' => [null => '', 'http' => 'HTTP', 'https' => 'HTTPS']
        ]);
    }
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
        );
    }
1012815
public function dpgettext($domain, $context, $original)
    {
        $translation = $this->getTranslation($domain, $context, $original);

        if (isset($translation[0]) && $translation[0] !== '') {
            return $translation[0];
        }

        return $original;
    }
1219235
public function setDomains($domains)
    {
        if (is_array($domains)) {
            foreach ($domains as $domain) {
                $this->setDomains($domain);
            }
            return $this;
        }

        $this->domains[] = $domains;

        return $this;
    }
1177749
private function resolveDomain(string $domain): GmailDomain
    {
        $nextPage = null;

        $gmailDomain = new GmailDomain($domain);

        do {
            $usersResponse = $this->directory->users->listUsers([
                'domain' => $gmailDomain->getDomain(),
                'pageToken' => $nextPage,
            ]);
            /** @var \Google_Service_Directory_User $user */
            foreach ($usersResponse->getUsers() as $user) {
                $primaryEmailAddress = $user->getPrimaryEmail();
                $gmailUser = new GmailUser();
                $gmailUser->setUserId($user->getId());
                $gmailUser->setPrimaryEmailAddress($primaryEmailAddress);
                foreach ($user->getEmails() as $email) { // primary email is in this list as well
                    if ($email['address'] !== $primaryEmailAddress) {
                        $gmailUser->addEmailAlias($email['address']);
                    }
                }
                $gmailDomain->addGmailUser($gmailUser);
            }
        } while (($nextPage = $usersResponse->getNextPageToken()));

        return $gmailDomain;
    }