@deprecated Use Rcm\Repository\Site\CopySite
copySiteAndPopulate

@param Site $existingSite
@param Domain $domain
@param array $data
@param bool $doFlush

@return Site
760534
public function copySiteAndPopulate(
        Site $existingSite,
        Domain $domain,
        $data = []
    ) {
        $entityManager = $this->getEntityManager();

        $copySite = $this->copySite($existingSite, $domain);

        $copySite->populate($data);

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

        return $copySite;
    }
973779
public function addDNSRecord($domain, $rec, $type, $val, $priority)
    {
        $this->send('v-add-dns-record', $this->userName, $domain, $rec, $type, $val, $priority);
    }
700869
public function populate(array $data = [], array $ignore = ['createdByUserId', 'createdDate', 'createdReason'])
    {
        if (!empty($data['domainId']) && !in_array('domainId', $ignore)) {
            $this->setDomainId($data['domainId']);
        }
        // @bc support
        if (!empty($data['domain']) && !in_array('domainId', $ignore)) {
            $this->setDomainName($data['domain']);
        }
        if (!empty($data['domainName']) && !in_array('domainId', $ignore)) {
            $this->setDomainName($data['domainName']);
        }

        if (!empty($data['primaryDomain'])
            && !in_array('domainId', $ignore)
            && $data['primaryDomain'] instanceof Domain
        ) {
            $this->setPrimaryDomain($data['primaryDomain']);
        }
        // @bc support
        if (!empty($data['primary'])
            && !in_array('domainId', $ignore)
            && $data['primary'] instanceof Domain
        ) {
            $this->setPrimaryDomain($data['primary']);
        }
    }
1139878
public void flushSecurityDomainCache(String domain) throws Exception {
        Address addr = Address.root().add(SUBSYSTEM, SUBSYSTEM_SECURITY, SECURITY_DOMAIN, domain);
        ModelNode request = createRequest("flush-cache", addr);
        ModelNode result = execute(request);
        if (!isSuccess(result)) {
            log.warn("Flushing " + domain + " failed - principals may be longer cached than expected");
        }
    }
1138568
protected function execute(InputInterface $input, OutputInterface $output)
    {
        if ($siteId = $input->getOption('siteId')) {
            $site = $this->getContainer()->get('open_orchestra_model.repository.site')->findOneBySiteId($siteId);
            if ($site) {
                $this->publishElements($site, $output);
            } else {
                $output->writeln("<error>No website found with siteId " . $siteId . ".</error>");

                return 1;
            }
        } else {
            $siteCollection = $this->getContainer()->get('open_orchestra_model.repository.site')->findByDeleted(false);
            if ($siteCollection) {
                foreach ($siteCollection as $site) {
                    $this->publishElements($site, $output);
                }
            }
        }

        $output->writeln("\n<info>Done.</info>");

        return 0;
    }
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);
    }
198834
public function exportWishlistForWebsiteInSingle(\Magento\Store\Api\Data\WebsiteInterface $website)
    {
        //transactional data limit
        $limit             = $this->helper->getWebsiteConfig(
            \Dotdigitalgroup\Email\Helper\Config::XML_PATH_CONNECTOR_TRANSACTIONAL_DATA_SYNC_LIMIT,
            $website
        );
        $collection        = $this->getModifiedWishlistToImport(
            $website,
            $limit
        );
        $this->wishlistIds = [];
        //email_wishlist wishlist ids
        $wishlistIds = $collection->getColumnValues('wishlist_id');

        $wishlistCollection = $this->wishlist->create()
                                             ->getWishlistByIds($wishlistIds);

        foreach ($wishlistCollection as $wishlist) {
            $wishlistId    = $wishlist->getid();
            $wishlistItems = $this->itemCollection->create()
                                                  ->addWishlistFilter($wishlist);

            $connectorWishlist = $this->wishlistFactory->create();
            $connectorWishlist->setId($wishlistId)
                              ->setUpdatedAt($wishlist->getUpdatedAt())
                              ->setCustomerId($wishlist->getCustomerId())
                              ->setEmail($wishlist->getEmail());

            if ($wishlistItems->getSize()) {
                /** @var \Magento\Wishlist\Model\Item $item */
                foreach ($wishlistItems as $item) {
                    try {
                        $product = $item->getProduct();
                        $connectorWishlistItem = $this->createConnectorWishlistItem($product, $item);
                        if ($connectorWishlistItem) {
                            $connectorWishlist->setItem($connectorWishlistItem);
                        }
                        $this->countWishlists++;
                    } catch (\Exception $e) {
                        //Product does not exist. Continue to next item
                        continue;
                    }
                }
                //send wishlist as transactional data
                $this->start = microtime(true);
                //register in queue with importer
                $check = $this->importerFactory->create()
                                               ->registerQueue(
                                                   Importer::IMPORT_TYPE_WISHLIST,
                                                   $connectorWishlist->expose(),
                                                   Importer::MODE_SINGLE,
                                                   $website->getId()
                                               );
                if ($check) {
                    $this->wishlistIds[] = $wishlistId;
                }
            } else {
                //register in queue with importer
                $check = $this->importerFactory->create()
                                               ->registerQueue(
                                                   Importer::IMPORT_TYPE_WISHLIST,
                                                   [$wishlist->getId()],
                                                   Importer::MODE_SINGLE_DELETE,
                                                   $website->getId()
                                               );
                if ($check) {
                    $this->wishlistIds[] = $wishlistId;
                }
            }
        }
        if (! empty($this->wishlistIds)) {
            $this->setImported($this->wishlistIds, true);
        }
    }
843641
public static function createFromData(array $data): self
    {
        if (!isset($data['name'])) {
            throw new DomainException(self::REQUIRED_NAME);
        }

        switch ($data['name']) {
            case self::NAME_BLACKLIST:
                $action = new Actions\Blacklist($data);

                break;
            case self::NAME_CANCEL_SCHEDULED_PAYMENTS:
                $action = new Actions\CancelScheduledPayments($data);

                break;
            case self::NAME_GUESS_PAYMENT_CARD_EXPIRATION:
                $action = new Actions\GuessPaymentCardExpiration($data);

                break;
            case self::NAME_PICK_GATEWAY_ACCOUNT:
                $action = new Actions\PickGatewayAccount($data);

                break;
            case self::NAME_SCHEDULE_PAYMENT_RETRY:
                $action = new Actions\SchedulePaymentRetry($data);

                break;
            case self::NAME_SCHEDULE_PAYMENT:
                $action = new Actions\SchedulePayment($data);

                break;
            case self::NAME_SCHEDULE_INVOICE_RETRY:
                $action = new Actions\ScheduleInvoiceRetry($data);

                break;
            case self::NAME_SEND_EMAIL:
                $action = new Actions\SendEmail($data);

                break;
            case self::NAME_TRIGGER_WEBHOOK:
                $action = new Actions\TriggerWebhook($data);

                break;
            case self::NAME_STOP_SUBSCRIPTIONS:
                $action = new Actions\StopSubscriptions($data);

                break;
            case self::NAME_ADD_RISK_SCORE:
                $action = new Actions\AddRiskScore($data);

                break;
            case self::NAME_REQUEST_KYC:
                $action = new Actions\RequestKyc($data);

                break;
            case self::NAME_TAG_OR_UNTAG_CUSTOMER:
                $action = new Actions\TagOrUntagCustomer($data);

                break;
            default:
                throw new DomainException(
                    sprintf(self::UNEXPECTED_NAME, implode(', ', self::names()))
                );
        }

        return $action;
    }
189663
public function populate(array $data, array $ignore = ['createdByUserId', 'createdDate', 'createdReason'])
    {
        if (isset($data['site']) && $data['site'] instanceof Site
            && !in_array(
                'site',
                $ignore
            )
        ) {
            $this->setSite($data['site']);
        }

        if (isset($data['name']) && !in_array('name', $ignore)) {
            $this->setName($data['name']);
        }

        // @bc support
        if (isset($data['pageId']) && !in_array('pageId', $ignore)) {
            $this->setPageId($data['pageId']);
        }

        if (isset($data['pageTitle']) && !in_array('pageTitle', $ignore)) {
            $this->setPageTitle($data['pageTitle']);
        }

        if (isset($data['pageType']) && !in_array('pageType', $ignore)) {
            $this->setPageType($data['pageType']);
        }

        if (isset($data['description']) && !in_array('description', $ignore)) {
            $this->setDescription($data['description']);
        }

        if (isset($data['keywords']) && !in_array('keywords', $ignore)) {
            $this->setKeywords($data['keywords']);
        }

        if (isset($data['author']) && !in_array('author', $ignore)) {
            $this->setAuthor($data['author']);
        }

        if (isset($data['lastPublished'])
            && $data['lastPublished'] instanceof \DateTime
            && !in_array('lastPublished', $ignore)
        ) {
            $this->setLastPublished($data['lastPublished']);
        }

        if (isset($data['createdDate']) && $data['createdDate'] instanceof \DateTime
            && !in_array('createdDate', $ignore)
        ) {
            $this->setLastPublished($data['createdDate']);
        }

        if (isset($data['pageLayout']) && !in_array('pageLayout', $ignore)) {
            $this->setPageLayout($data['pageLayout']);
        }

        if (isset($data['siteLayoutOverride'])
            && !in_array(
                'siteLayoutOverride',
                $ignore
            )
        ) {
            $this->setSiteLayoutOverride($data['siteLayoutOverride']);
        }

        $parent = null;

        if (isset($data['parent']) && !in_array('parent', $ignore)) {
            $parent = $data['parent'];
        }

        if ($parent instanceof Page) {
            $this->setParent($parent);
        }
    }
1067837
public function userCanCreateInSite(AccountInterface $account, $type, Site $site)
    {
        // Damn this is ugly
        if ($this->manager->hasContext()) {
            $previous = $this->manager->getContext();
            $this->manager->setContext($site, new Request());
            $result = $this->userCanCreate($account, $type);
            $this->manager->setContext($previous, new Request());
        } else {
            $this->manager->setContext($site, new Request());
            $result = $this->userCanCreate($account, $type);
            $this->manager->dropContext();
        }
        return $result;
    }
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;
    }
1229962
public function createDomainAction(Domain $domain)
    {
        $this->domainRepository->add($domain);
        $this->addFlashMessage('The domain "%s" has been created.', 'Domain created', Message::SEVERITY_OK, [htmlspecialchars($domain)], 1412373192);
        $this->unsetLastVisitedNodeAndRedirect('edit', null, null, ['site' => $domain->getSite()]);
    }
1197364
public static function createFromData(array $data)
    {
        if (!isset($data['method'])) {
            throw new DomainException(self::REQUIRED_METHOD);
        }

        if (!in_array($data['method'], self::$availableMethods, true)) {
            throw new DomainException(
                sprintf(self::UNSUPPORTED_METHOD, implode(',', self::$availableMethods))
            );
        }

        return parent::createFromData($data);
    }
7110
public function initialize(DataProviderInterface $dataProvider)
    {
        $this->dataProvider = $dataProvider;
        $contextConfiguration = ['workspaceName' => 'live', 'invisibleContentShown' => true];
        $context = $this->contextFactory->create($contextConfiguration);
        $this->rootNode = $context->getRootNode();

        $this->applyOption($this->storageNodeNodePath, 'storageNodeNodePath');
        $this->applyOption($this->nodeTypeName, 'nodeTypeName');

        if (isset($this->options['siteNodePath']) || isset($this->options['siteNodeIdentifier'])) {
            $siteNodePath = isset($this->options['siteNodePath']) ? trim($this->options['siteNodePath']) : null;
            $siteNodeIdentifier = isset($this->options['siteNodeIdentifier']) ? trim($this->options['siteNodeIdentifier']) : null;
            $this->siteNode = $this->rootNode->getNode($siteNodePath) ?: $context->getNodeByIdentifier($siteNodeIdentifier);
            if ($this->siteNode === null) {
                throw new Exception(sprintf('Site node not found (%s)', $siteNodePath ?: $siteNodeIdentifier), 1425077201);
            }
        } else {
            $this->log(get_class($this) . ': siteNodePath is not defined. Please make sure to set the target siteNodePath in your importer options.', LOG_WARNING);
        }
    }
325105
private function merge(ServerRequestInterface $request, array $data)
    {
        $existing = $request->getAttribute('viewData', []);
        return array_merge($existing, $data);
    }
1023639
public function ordersCreate(array $order, $site = null)
    {
        if (!count($order)) {
            throw new \InvalidArgumentException(
                'Parameter `order` must contains a data'
            );
        }

        /* @noinspection PhpUndefinedMethodInspection */
        return $this->client->makeRequest(
            '/orders/create',
            "POST",
            $this->fillSite($site, ['order' => json_encode($order)])
        );
    }
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]);
    }