newId() public static method

See wiki docs for discussion about the chosen ID algorightm and format.
public static newId ( ) : string
return string
Example #1
0
 public function identifyEntity($entityName, $data, $id)
 {
     if ($this->schemaInfo->getEntityInfo($entityName)->usesGeneratedVpids) {
         $data['vp_id'] = IdUtil::newId();
         $this->saveId($entityName, $id, $data['vp_id']);
     }
     $data[$this->schemaInfo->getEntityInfo($entityName)->idColumnName] = $id;
     $data = $this->fillId($entityName, $data, $id);
     return $data;
 }
 public static function prepareTermMeta($vpId = null, $termVpId = null, $key = null, $value = null)
 {
     if ($vpId === null) {
         $vpId = IdUtil::newId();
     }
     $termmeta = ['vp_id' => $vpId];
     if ($termVpId !== null) {
         $termmeta['vp_term_id'] = $termVpId;
     }
     if ($key !== null) {
         $termmeta['meta_key'] = $key;
     }
     if ($value !== null) {
         $termmeta['meta_value'] = $value;
     }
     return $termmeta;
 }
 /**
  * If entity type identified by $entityName defines an ID column, creates a mapping between WordPress ID and VPID
  * for all entities (db rows) of such type.
  *
  * @param string $entityName E.g., "post"
  */
 private function createVpidsForEntitiesOfType($entityName)
 {
     if (!$this->dbSchema->getEntityInfo($entityName)->usesGeneratedVpids) {
         return;
     }
     $idColumnName = $this->dbSchema->getEntityInfo($entityName)->idColumnName;
     $tableName = $this->dbSchema->getTableName($entityName);
     $prefixedTableName = $this->dbSchema->getPrefixedTableName($entityName);
     $entities = $this->database->get_results("SELECT * FROM {$prefixedTableName}", ARRAY_A);
     $entities = $this->replaceForeignKeysWithReferencesInAllEntities($entityName, $entities);
     $storage = $this->storageFactory->getStorage($entityName);
     $entities = array_filter($entities, function ($entity) use($storage) {
         return $storage->shouldBeSaved($entity);
     });
     $chunks = array_chunk($entities, 1000);
     foreach ($chunks as $entitiesInChunk) {
         $wordpressIds = array_column($entitiesInChunk, $idColumnName);
         $idPairs = [];
         foreach ($wordpressIds as $id) {
             $id = intval($id);
             if (!isset($this->idCache[$entityName], $this->idCache[$entityName][$id])) {
                 $this->idCache[$entityName][$id] = IdUtil::newId();
             }
             $idPairs[$id] = $this->idCache[$entityName][$id];
         }
         $sqlValues = join(', ', ArrayUtils::map(function ($vpId, $id) use($tableName) {
             return "('{$tableName}', {$id}, UNHEX('{$vpId}'))";
         }, $idPairs));
         $query = "INSERT INTO {$this->database->vp_id} (`table`, id, vp_id) VALUES {$sqlValues}";
         $this->database->query($query);
         $this->checkTimeout();
     }
 }