Get a clone with special logic

@param string $createdByUserId
@param string $createdReason

@return PluginWrapper
325931
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var PluginWrapper $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        // if no id, then it has not been save and can be returned
        if (empty($new->pluginWrapperId)) {
            return $new;
        }

        $new->pluginWrapperId = null;

        // @deprecated <deprecated-site-wide-plugin>
        //if (!$new->instance->isSiteWide()) {
            $pluginInstance = $new->instance->newInstance(
                $createdByUserId,
                $createdReason
            );
            $new->instance = $pluginInstance;
        //}

        return $new;
    }
797583
public function newInstanceIfHasRevision(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var ContainerInterface|ContainerAbstract $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        $publishedRevision = $new->getPublishedRevision();

        if (empty($publishedRevision)) {
            return null;
        }

        $new->lastPublished = new \DateTime();

        $new->revisions = new ArrayCollection();
        $new->stagedRevision = null;
        $new->stagedRevisionId = null;

        $new->setPublishedRevision(
            $publishedRevision->newInstance(
                $createdByUserId,
                $createdReason
            )
        );

        return $new;
    }
1185314
public function copy($userId, $contentTypeId, $status)
    {
        $createStruct = $this->mapper->createCreateStructFromType(
            $this->load($contentTypeId, $status)
        );
        $createStruct->modifierId = $userId;
        $createStruct->created = $createStruct->modified = time();
        $createStruct->creatorId = $userId;
        $createStruct->remoteId = md5(uniqid(get_class($createStruct), true));

        // extract actual identifier name, without "copy_of_" and number
        $originalIdentifier = preg_replace('/^copy_of_(.+)_\d+$/', '$1', $createStruct->identifier);

        // set temporary identifier
        $createStruct->identifier = $createStruct->remoteId;

        // Set FieldDefinition ids to null to trigger creating new id
        foreach ($createStruct->fieldDefinitions as $fieldDefinition) {
            $fieldDefinition->id = null;
        }

        $contentTypeCopy = $this->internalCreate($createStruct);
        $updateStruct = $this->mapper->createUpdateStructFromType($contentTypeCopy);
        $updateStruct->identifier = 'copy_of_' . $originalIdentifier . '_' . $contentTypeCopy->id;

        return $this->update($contentTypeCopy->id, $contentTypeCopy->status, $updateStruct);
    }
217622
static function create( $contentObjectID, $userIdentifier, $creatorID = false )
    {
        $timestamp = time();

        if ( $creatorID === false )
        {
            $user = eZUser::currentUser();
            $creatorID = $user->id();
        }
        $row = array( 'contentobject_id' => $contentObjectID,
                      'user_identifier' => $userIdentifier,
                      'creator_id' => $creatorID,
                      'created' => $timestamp,
                      'modified' => $timestamp );
        return new eZInformationCollection( $row );
    }
654922
public function getDefaultSiteValues(
        array $defaultSiteSettings,
        string $createdByUserId,
        string $createdReason
    ) {
        // Site Id
        if (empty($defaultSiteSettings['siteId'])) {
            $defaultSiteSettings['siteId'] = null;
        }

        // Language
        if (empty($defaultSiteSettings['languageIso6392t'])) {
            $defaultSiteSettings['languageIso6392t'] = $this->defaultLanguageIso6392t;
        }

        // Country
        if (empty($defaultSiteSettings['countryId'])) {
            $defaultSiteSettings['countryId'] = $this->defaultCountryIso3;
        }

        return $this->prepareSiteData(
            $defaultSiteSettings,
            $createdByUserId,
            $createdReason
        );
    }
782151
protected function buildDomain(
        array $siteData,
        string $createdByUserId,
        string $createdReason
    ) {
        if (!empty($siteData['domain']) && $siteData['domain'] instanceof Domain) {
            return $siteData['domain'];
        }

        if (!empty($siteData['domainName'])) {
            $domain = $this->domainRepository->findOneBy(
                ['domain' => $siteData['domainName']]
            );

            if (!empty($domain)) {
                throw new DomainAlreadyExistsException(
                    "Domain {$siteData['domainName']} was found and should not be duplicated."
                );
            }

            return $this->domainRepository->createDomain(
                $siteData['domainName'],
                $createdByUserId,
                'Create new domain in ' . get_class($this)
                . ' for: ' . $createdReason
            );
        }

        return null;
    }
489320
public static function create($parsed)
    {
        $result = new self();
        $name = Utilities::tryGetValue($parsed, Resources::XTAG_NAME);
        $label = Utilities::tryGetValue($parsed, Resources::XTAG_LABEL);
        $url = Utilities::tryGetValue($parsed, Resources::XTAG_URL);
        $locked = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_LOCKED
        );
        $rollbackAllowed = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_ROLLBACK_ALLOWED
        );
        $sdkVersion = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_SDK_VERSION
        );
        $inputEndpointList = Utilities::tryGetKeysChainValue(
            $parsed,
            Resources::XTAG_INPUT_ENDPOINT_LIST,
            Resources::XTAG_INPUT_ENDPOINT
        );
        $roleList = Utilities::tryGetKeysChainValue(
            $parsed,
            Resources::XTAG_ROLE_LIST,
            Resources::XTAG_ROLE
        );
        $roleInstanceList = Utilities::tryGetKeysChainValue(
            $parsed,
            Resources::XTAG_ROLE_INSTANCE_LIST,
            Resources::XTAG_ROLE_INSTANCE
        );
        $status = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_STATUS
        );
        $slot = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_DEPLOYMENT_SLOT
        );
        $privateId = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_PRIVATE_ID
        );
        $configuration = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_CONFIGURATION
        );
        $upgradeDomainCount = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_UPGRADE_DOMAIN_COUNT
        );
        $upgradeStatus = Utilities::tryGetValue(
            $parsed,
            Resources::XTAG_UPGRADE_STATUS
        );

        $result->setConfiguration($configuration);
        $result->setLabel($label);
        $result->setLocked(Utilities::toBoolean($locked));
        $result->setName($name);
        $result->setPrivateId($privateId);
        $result->setRollbackAllowed(Utilities::toBoolean($rollbackAllowed));
        $result->setSdkVersion($sdkVersion);
        $result->setSlot($slot);
        $result->setStatus($status);
        $result->setUpgradeDomainCount(intval($upgradeDomainCount));
        $result->setUpgradeStatus(UpgradeStatus::create($upgradeStatus));
        $result->setUrl($url);
        $result->setRoleInstanceList(
            Utilities::createInstanceList(
                Utilities::getArray($roleInstanceList),
                'WindowsAzure\ServiceManagement\Models\RoleInstance'
            )
        );
        $result->setRoleList(
            Utilities::createInstanceList(
                Utilities::getArray($roleList),
                'WindowsAzure\ServiceManagement\Models\Role'
            )
        );
        $result->setInputEndpointList(
            Utilities::createInstanceList(
                Utilities::getArray($inputEndpointList),
                'WindowsAzure\ServiceManagement\Models\InputEndpoint'
            )
        );

        return $result;
    }
89377
public function createContainer(
        SiteEntity $site,
        string $name,
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON,
        $author = Tracking::UNKNOWN_AUTHOR
    ) {
        $container = new ContainerEntity(
            $createdByUserId,
            $createdReason
        );
        $container->setName($name);
        $container->setSite($site);
        $container->setAuthor($author);

        $this->_em->persist($container);
        $this->_em->flush($container);

        return $container;
    }
824927
public function newTokenAction(Request $request, $userClass)
    {
        try {
            $this->get('bengor_user.' . $userClass . '.api_command_bus')->handle(
                new LogInUserCommand(
                    $request->getUser(),
                    $request->getPassword()
                )
            );
        } catch (UserDoesNotExistException $exception) {
            return new JsonResponse('', 400);
        } catch (UserEmailInvalidException $exception) {
            return new JsonResponse('', 400);
        } catch (UserInactiveException $exception) {
            return new JsonResponse('Inactive user', 400);
        } catch (UserPasswordInvalidException $exception) {
            return new JsonResponse('', 400);
        }
        $token = $this->get('lexik_jwt_authentication.encoder.default')->encode(['email' => $request->getUser()]);

        return new JsonResponse(['token' => $token]);
    }
483026
public function create($siteId, $userAgent = '', $requestIPAddress = '')
    {
        if (empty($siteId)) {
            throw new \Exception('Cannot create an instance without a site id');
        }

        $cookie = new Cookie();

        $userId = $cookie->getCookie(CookieNames::USER_ID);
        $userId = ! empty($userId) ? $userId : Uuid::v4();

        $payload = new Payload(new Cookie(), $siteId, $userId);

        $requestHeaders = [];

        $browserUserAgent = !empty($userAgent) ? $userAgent : Browser::getUserAgent();
        $browserIPAddress = !empty($requestIPAddress) ? $requestIPAddress : Browser::getRequestIPAddress();

        if (! empty($browserUserAgent)) {
            $requestHeaders['X-Original-User-Agent'] = $browserUserAgent;
        }

        if (! empty($browserIPAddress)) {
            $requestHeaders['X-Original-Request-IP-Address'] = $browserIPAddress;
        }

        $client = new Client([
            'base_uri' => API::ENDPOINT,
            RequestOptions::HEADERS => $requestHeaders,
            RequestOptions::HTTP_ERRORS => false,
            RequestOptions::VERIFY => false
        ]);

        return new Tracker($cookie, $payload, $client);
    }
1236604
public function updatePlugin(
        $pluginData,
        SiteEntity $site,
        string $modifiedByUserId,
        string $modifiedReason = Tracking::UNKNOWN_REASON,
        $forceSave = false,
        $doFlush = true
    ) {
        $pluginData = $this->prepareData($pluginData);

        if ($pluginData['pluginInstanceId'] > 0) {
            return $this->updateExistingPlugin(
                $pluginData,
                $site,
                $modifiedByUserId,
                $modifiedReason,
                $forceSave,
                $doFlush
            );
        }

        return $this->createPluginInstance(
            $pluginData,
            $site,
            $modifiedByUserId,
            $modifiedReason,
            null,
            $doFlush
        );
    }
808125
public function newInstance(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        /** @var static $new */
        $new = parent::newInstance(
            $createdByUserId,
            $createdReason
        );

        return $new;
    }
241542
public function newInstance($cloned = array())
    {
        if ($cloned instanceof Model) {
            $cloned = $cloned->toArray(Model::FETCH_PUBLISHED);
        }

        if (isset($this->options['model'])) {
            $Model = $this->options['model'];
            return new $Model($cloned, array('collection' => $this));
        } else {
            return new Model($cloned, array('collection' => $this));
        }
    }
189107
function createUser({ username, group="public" }, done) {
  return getGroup(group, function(getGroupErr, theGroup) {
    if (getGroupErr) {
      return done(getGroupErr);
    }

    if (!theGroup) {
      return done(new Error(`group '${group}' not found`));
    }

    theGroup.members.add({ username });
    return theGroup.save(done);
  });
}
435322
public static function createFrom(
        Storage $persistenceProvider,
        Storage $cacheProvider,
        LoggerInterface $logger = null
    ) {
        /** @var $userAgentHandlerChain \Wurfl\Handlers\Chain\UserAgentHandlerChain */
        $userAgentHandlerChain = $cacheProvider->load('UserAgentHandlerChain');

        if (!($userAgentHandlerChain instanceof UserAgentHandlerChain)) {
            $userAgentHandlerChain = self::init();
            $cacheProvider->save('UserAgentHandlerChain', $userAgentHandlerChain, 3600);
        }

        $userAgentHandlerChain->setLogger($logger);

        foreach ($userAgentHandlerChain->getHandlers() as $handler) {
            /* @var $handler \Wurfl\Handlers\AbstractHandler */
            $handler
                ->setLogger($logger)
                ->setPersistenceProvider($persistenceProvider);
        }

        return $userAgentHandlerChain;
    }
195732
protected function createGetUserRequest(Message $message, NodeRef $nodeRef, Pbjx $pbjx): GetUserRequest
    {
        /** @var GetUserRequest $request */
        $request = GetUserRequestV1Mixin::findOne()->createMessage();
        return $request;
    }
34159
public function newInstanceIfHasRevision(
        string $createdByUserId,
        string $createdReason = Tracking::UNKNOWN_REASON
    ) {
        $new = parent::newInstanceIfHasRevision(
            $createdByUserId,
            $createdReason
        );

        if (empty($new)) {
            return null;
        }

        $new->pageId = null;
        $new->parent = null;

        return $new;
    }