/** * @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 = '" . \TYPO3\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"); }
/** * After returning advice, making sure we have an UUID for each and every entity. * * @param \TYPO3\Flow\Aop\JoinPointInterface $joinPoint The current join point * @return void * @Flow\Before("TYPO3\Flow\Persistence\Aspect\PersistenceMagicAspect->isEntity && method(.*->(__construct|__clone)()) && filter(TYPO3\Flow\Persistence\Doctrine\Mapping\Driver\FlowAnnotationDriver)") */ public function generateUuid(JoinPointInterface $joinPoint) { /** @var $proxy \TYPO3\Flow\Persistence\Aspect\PersistenceMagicInterface */ $proxy = $joinPoint->getProxy(); ObjectAccess::setProperty($proxy, 'Persistence_Object_Identifier', Algorithms::generateUUID(), true); $this->persistenceManager->registerNewObject($proxy); }
/** * @param \TYPO3\Flow\Security\Account $login * @param string $name * @param string $imageId * @param string $imageId */ public function __construct($login, $name, $imageId) { $this->accountId = \TYPO3\Flow\Utility\Algorithms::generateUUID(); $this->creationDate = new \DateTime(); $this->login = $login; $this->name = trim($name); $this->imageId = trim($imageId); }
/** * Generate a number of random identifiers * * @param integer $count * @return void */ public function generateRandomIdentifiersCommand($count = 10) { $this->outputLine('Here are your random identifiers:'); $this->outputLine(''); for ($i = 0; $i < 10; $i++) { $this->outputLine(Algorithms::generateUUID()); } $this->outputLine(''); $this->outputLine('Make sure you always use an identifier once ;-)'); }
/** * @test */ public function createNodeFromTemplateUsesIdentifierFromTemplate() { $identifier = \TYPO3\Flow\Utility\Algorithms::generateUUID(); $template = new \TYPO3\TYPO3CR\Domain\Model\NodeTemplate(); $template->setName('new-node'); $template->setIdentifier($identifier); $rootNode = $this->context->getRootNode(); $newNode = $rootNode->createNodeFromTemplate($template); $this->assertSame($identifier, $newNode->getIdentifier()); }
/** * 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' => \TYPO3\Flow\Utility\Algorithms::generateUUID()), array('name' => $workspace['name'])); } } }
/** * Starts the session, if it has not been already started * * @return void * @api * @throws \TYPO3\Flow\Session\Exception\InvalidRequestHandlerException */ public function start() { if ($this->request === null) { $requestHandler = $this->bootstrap->getActiveRequestHandler(); if (!$requestHandler instanceof HttpRequestHandlerInterface) { throw new \TYPO3\Flow\Session\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 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(); } }
/** * 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 \TYPO3\TYPO3CR\Domain\Model\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(); }
/** * @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()); }
/** * 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 \Doctrine\DBAL\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 typo3_typo3cr_domain_model_nodedimension' . ' WHERE nodedata IN (' . ' SELECT persistence_object_identifier FROM typo3_typo3cr_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('TYPO3\\TYPO3CR\\Domain\\Model\\NodeData', '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 typo3_typo3cr_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('typo3_typo3cr_domain_model_nodedimension', $nodeDimension); } } }
/** * @test */ public function generateUUIDGeneratesAtLeastNotTheSameUuidOnSubsequentCalls() { $this->assertNotEquals(Algorithms::generateUUID(), Algorithms::generateUUID()); }
/** * @param BadgeClass $badgeClass The badge class where this step is needed for an assertion * @param string $identifier An identifier for this step (unique per badge class), used to reference steps client- and server-side */ public function __construct(BadgeClass $badgeClass, $identifier) { $this->badgeClass = $badgeClass; $this->identifier = $identifier; $this->token = \TYPO3\Flow\Utility\Algorithms::generateUUID(); }
public static function next() { return Algorithms::generateUUID(); }
public function __construct() { $this->uuid = 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 \TYPO3\TYPO3CR\Domain\Model\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) { $this->setPath($path, FALSE); $this->workspace = $workspace; $this->identifier = $identifier === NULL ? Algorithms::generateUUID() : $identifier; $this->dimensions = new \Doctrine\Common\Collections\ArrayCollection(); if ($dimensions !== NULL) { foreach ($dimensions as $dimensionName => $dimensionValues) { foreach ($dimensionValues as $dimensionValue) { $this->dimensions->add(new NodeDimension($this, $dimensionName, $dimensionValue)); } } } $this->calculateDimensionsHash(); $this->buildDimensionValues(); }