generateUUID() public static method

The algorithm used here, might not be completely random. If php-uuid was installed it will be used instead to speed up the process.
public static generateUUID ( ) : string
return string The universally unique id
 /**
  * @param Schema $schema
  * @return void
  */
 public function down(Schema $schema)
 {
     $this->abortIf($this->connection->getDatabasePlatform()->getName() != "postgresql");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event DROP CONSTRAINT fk_30ab3a75b684c08");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event DROP CONSTRAINT typo3_neos_eventlog_domain_model_event_pkey");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ADD persistence_object_identifier VARCHAR(40) NULL");
     $result = $this->connection->executeQuery("SELECT installed_version FROM pg_available_extensions WHERE name = 'uuid-ossp'");
     if ($result->fetchColumn() !== null) {
         $this->addSql("UPDATE typo3_neos_eventlog_domain_model_event SET persistence_object_identifier = uuid_generate_v4()");
     } else {
         $result = $this->connection->executeQuery("SELECT uid FROM typo3_neos_eventlog_domain_model_event");
         while ($uid = $result->fetchColumn()) {
             $this->addSql("UPDATE typo3_neos_eventlog_domain_model_event SET persistence_object_identifier = '" . \Neos\Flow\Utility\Algorithms::generateUUID() . "' WHERE uid = " . $uid);
         }
     }
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ALTER COLUMN persistence_object_identifier SET NOT NULL");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ALTER uid DROP NOT NULL");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ALTER parentevent TYPE VARCHAR(40) USING (parentevent::varchar)");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ALTER parentevent DROP DEFAULT");
     $this->addSql("WITH p AS (SELECT DISTINCT uid, persistence_object_identifier FROM typo3_neos_eventlog_domain_model_event) UPDATE typo3_neos_eventlog_domain_model_event SET parentevent = p.persistence_object_identifier FROM p WHERE parentevent IS NOT NULL AND p.uid = parentevent::integer");
     $this->addSql("SELECT setval('typo3_neos_eventlog_domain_model_event_uid_seq', (SELECT MAX(uid) FROM typo3_neos_eventlog_domain_model_event)+1);");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ALTER uid SET DEFAULT nextval('typo3_neos_eventlog_domain_model_event_uid_seq')");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ADD PRIMARY KEY (persistence_object_identifier)");
     $this->addSql("ALTER TABLE typo3_neos_eventlog_domain_model_event ADD CONSTRAINT fk_30ab3a75b684c08 FOREIGN KEY (parentevent) REFERENCES typo3_neos_eventlog_domain_model_event (persistence_object_identifier) NOT DEFERRABLE INITIALLY IMMEDIATE");
 }
 /**
  * Generate UUIDs in PHP if the uuid-ossp extension is not installed.
  *
  * @param Schema $schema
  * @return void
  */
 public function preDown(Schema $schema)
 {
     $result = $this->connection->executeQuery("SELECT installed_version FROM pg_available_extensions WHERE name = 'uuid-ossp'");
     if ($result->fetchColumn() === null) {
         $this->connection->executeUpdate("ALTER TABLE typo3_typo3cr_domain_model_workspace ADD persistence_object_identifier VARCHAR(40)");
         $result = $this->connection->executeQuery('SELECT name FROM typo3_typo3cr_domain_model_workspace');
         foreach ($result->fetchAll() as $workspace) {
             $this->connection->update('typo3_typo3cr_domain_model_workspace', array('persistence_object_identifier' => \Neos\Flow\Utility\Algorithms::generateUUID()), array('name' => $workspace['name']));
         }
     }
 }
Beispiel #3
0
 /**
  * @inheritdoc
  */
 public function submit($payload, array $options = [])
 {
     $this->checkClientConnection();
     $messageId = Algorithms::generateUUID();
     $idStored = $this->client->hSet("queue:{$this->name}:ids", $messageId, json_encode($payload));
     if ($idStored === 0) {
         return null;
     }
     $this->client->lPush("queue:{$this->name}:messages", $messageId);
     return $messageId;
 }
Beispiel #4
0
 /**
  * @inheritdoc
  */
 public function submit($payload, array $options = [])
 {
     $messageId = Algorithms::generateUUID();
     $message = new Message($messageId, $payload);
     $commandArguments = [$this->name, base64_encode(serialize($message))];
     if ($this->async) {
         if (!method_exists(Scripts::class, 'executeCommandAsync')) {
             throw new \RuntimeException('The "async" flag is set, but the currently used Flow version doesn\'t support this (Flow 3.3+ is required)', 1469116604);
         }
         Scripts::executeCommandAsync('flowpack.jobqueue.common:job:execute', $this->flowSettings, $commandArguments);
     } else {
         Scripts::executeCommand('flowpack.jobqueue.common:job:execute', $this->flowSettings, true, $commandArguments);
     }
     return $messageId;
 }
 /**
  * @test
  */
 public function generateUUIDGeneratesAtLeastNotTheSameUuidOnSubsequentCalls()
 {
     $this->assertNotEquals(Algorithms::generateUUID(), Algorithms::generateUUID());
 }
 /**
  * Constructs this node data container
  *
  * Creating new nodes by instantiating NodeData is not part of the public API!
  * The content repository needs to properly integrate new nodes into the node
  * tree and therefore you must use createNode() or createNodeFromTemplate()
  * in a Node object which will internally create a NodeData object.
  *
  * @param string $path Absolute path of this node
  * @param Workspace $workspace The workspace this node will be contained in
  * @param string $identifier The node identifier (not the persistence object identifier!). Specifying this only makes sense while creating corresponding nodes
  * @param array $dimensions An array of dimension name to dimension values
  */
 public function __construct($path, Workspace $workspace, $identifier = null, array $dimensions = null)
 {
     parent::__construct();
     $this->creationDateTime = new \DateTime();
     $this->lastModificationDateTime = new \DateTime();
     $this->setPath($path, false);
     $this->workspace = $workspace;
     $this->identifier = $identifier === null ? Algorithms::generateUUID() : $identifier;
     $this->dimensions = new ArrayCollection();
     if ($dimensions !== null) {
         foreach ($dimensions as $dimensionName => $dimensionValues) {
             foreach ($dimensionValues as $dimensionValue) {
                 $this->dimensions->add(new NodeDimension($this, $dimensionName, $dimensionValue));
             }
         }
     }
     $this->buildDimensionValues();
 }
 /**
  * After returning advice, making sure we have an UUID for each and every entity.
  *
  * @param JoinPointInterface $joinPoint The current join point
  * @return void
  * @Flow\Before("Neos\Flow\Persistence\Aspect\PersistenceMagicAspect->isEntity && method(.*->(__construct|__clone)()) && filter(Neos\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver)")
  */
 public function generateUuid(JoinPointInterface $joinPoint)
 {
     /** @var $proxy PersistenceMagicInterface */
     $proxy = $joinPoint->getProxy();
     ObjectAccess::setProperty($proxy, 'Persistence_Object_Identifier', Algorithms::generateUUID(), true);
     $this->persistenceManager->registerNewObject($proxy);
 }
 /**
  * Saves the given array as a node data entity without using the ORM.
  *
  * If the node data already exists (same dimensions, same identifier, same workspace)
  * it is replaced.
  *
  * @param array $nodeData node data to save as an associative array ( $column_name => $value )
  * @throws ImportException
  * @return void
  */
 protected function persistNodeData($nodeData)
 {
     if ($nodeData['workspace'] !== 'live') {
         throw new ImportException('Saving NodeData with workspace != "live" using direct SQL not supported yet. Workspace is "' . $nodeData['workspace'] . '".');
     }
     if ($nodeData['path'] === '/') {
         return;
     }
     // cleanup old data
     /** @var Connection $connection */
     $connection = $this->entityManager->getConnection();
     // prepare node dimensions
     $dimensionValues = $nodeData['dimensionValues'];
     $dimensionsHash = Utility::sortDimensionValueArrayAndReturnDimensionsHash($dimensionValues);
     $jsonPropertiesDataTypeHandler = JsonArrayType::getType(JsonArrayType::FLOW_JSON_ARRAY);
     // post-process node data
     $nodeData['dimensionsHash'] = $dimensionsHash;
     $nodeData['dimensionValues'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($dimensionValues, $connection->getDatabasePlatform());
     $nodeData['properties'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['properties'], $connection->getDatabasePlatform());
     $nodeData['accessRoles'] = $jsonPropertiesDataTypeHandler->convertToDatabaseValue($nodeData['accessRoles'], $connection->getDatabasePlatform());
     $connection->executeQuery('DELETE FROM neos_contentrepository_domain_model_nodedimension' . ' WHERE nodedata IN (' . '   SELECT persistence_object_identifier FROM neos_contentrepository_domain_model_nodedata' . '   WHERE identifier = :identifier' . '   AND workspace = :workspace' . '   AND dimensionshash = :dimensionsHash' . ' )', array('identifier' => $nodeData['identifier'], 'workspace' => $nodeData['workspace'], 'dimensionsHash' => $nodeData['dimensionsHash']));
     /** @var \Doctrine\ORM\QueryBuilder $queryBuilder */
     $queryBuilder = $this->entityManager->createQueryBuilder();
     $queryBuilder->delete()->from(NodeData::class, 'n')->where('n.identifier = :identifier')->andWhere('n.dimensionsHash = :dimensionsHash')->andWhere('n.workspace = :workspace')->setParameter('identifier', $nodeData['identifier'])->setParameter('workspace', $nodeData['workspace'])->setParameter('dimensionsHash', $nodeData['dimensionsHash']);
     $queryBuilder->getQuery()->execute();
     // insert new data
     // we need to use executeUpdate to execute the INSERT -- else the data types are not taken into account.
     // That's why we build a DQL INSERT statement which is then executed.
     $queryParts = array();
     $queryArguments = array();
     $queryTypes = array();
     foreach ($this->nodeDataPropertyNames as $propertyName => $propertyConfig) {
         if (isset($nodeData[$propertyName])) {
             $queryParts[$propertyName] = ':' . $propertyName;
             $queryArguments[$propertyName] = $nodeData[$propertyName];
             if (isset($propertyConfig['columnType'])) {
                 $queryTypes[$propertyName] = $propertyConfig['columnType'];
             }
         }
     }
     $connection->executeUpdate('INSERT INTO neos_contentrepository_domain_model_nodedata (' . implode(', ', array_keys($queryParts)) . ') VALUES (' . implode(', ', $queryParts) . ')', $queryArguments, $queryTypes);
     foreach ($dimensionValues as $dimension => $values) {
         foreach ($values as $value) {
             $nodeDimension = array('persistence_object_identifier' => Algorithms::generateUUID(), 'nodedata' => $nodeData['Persistence_Object_Identifier'], 'name' => $dimension, 'value' => $value);
             $connection->insert('neos_contentrepository_domain_model_nodedimension', $nodeDimension);
         }
     }
 }
 /**
  * @test
  */
 public function nodeWithRelatedEntitiesWillTakeCareOfAddingToPersistence()
 {
     $identifier = Algorithms::generateUUID();
     $template = new NodeTemplate();
     $template->setName('new-node');
     $template->setIdentifier($identifier);
     $newEntity = new Fixtures\RelatedEntity();
     $newEntity->setFavoritePlace('Reykjavik');
     $anotherNewEntity = new Fixtures\RelatedEntity();
     $anotherNewEntity->setFavoritePlace('Japan');
     $template->setProperty('entity', array($newEntity, $anotherNewEntity));
     $rootNode = $this->context->getRootNode();
     $newNode = $rootNode->createNodeFromTemplate($template);
     $this->persistenceManager->persistAll();
     $this->persistenceManager->clearState();
     $this->inject($this->contextFactory, 'contextInstances', array());
     $newLiveContext = $this->contextFactory->create(array('workspaceName' => 'live'));
     $newNodeAgain = $newLiveContext->getNode('/new-node');
     $entityArray = $newNodeAgain->getProperty('entity');
     $this->assertCount(2, $entityArray);
     $this->assertEquals('Japan', $entityArray[1]->getFavoritePlace());
 }
Beispiel #10
0
 /**
  * @inheritdoc
  */
 public function submit($payload, array $options = [])
 {
     $this->lastSubmitOptions = $options;
     $messageId = Algorithms::generateUUID();
     $this->readyMessages[$messageId] = $payload;
     return $messageId;
 }
 /**
  * Starts the session, if it has not been already started
  *
  * @return void
  * @api
  * @throws Exception\InvalidRequestHandlerException
  */
 public function start()
 {
     if ($this->request === null) {
         $requestHandler = $this->bootstrap->getActiveRequestHandler();
         if (!$requestHandler instanceof HttpRequestHandlerInterface) {
             throw new Exception\InvalidRequestHandlerException('Could not start a session because the currently active request handler (%s) is not an HTTP Request Handler.', 1364367520);
         }
         $this->initializeHttpAndCookie($requestHandler);
     }
     if ($this->started === false) {
         $this->sessionIdentifier = Algorithms::generateRandomString(32);
         $this->storageIdentifier = Algorithms::generateUUID();
         $this->sessionCookie = new Http\Cookie($this->sessionCookieName, $this->sessionIdentifier, 0, $this->sessionCookieLifetime, $this->sessionCookieDomain, $this->sessionCookiePath, $this->sessionCookieSecure, $this->sessionCookieHttpOnly);
         $this->response->setCookie($this->sessionCookie);
         $this->lastActivityTimestamp = $this->now;
         $this->started = true;
         $this->writeSessionMetaDataCacheEntry();
     }
 }