VersionPress\Storages\Mirror::shouldBeSaved PHP Метод

shouldBeSaved() публичный Метод

Queries the associated storage whether the entity data should be saved or not
См. также: Storage::shouldBeSaved()
public shouldBeSaved ( string $entityName, array $data ) : boolean
$entityName string Determines the storage
$data array Data passed to VersionPress\Storages\Storage::shouldBeSaved()
Результат boolean
    public function shouldBeSaved($entityName, $data)
    {
        $storage = $this->storageFactory->getStorage($entityName);
        if ($storage === null) {
            return false;
        }
        return $storage->shouldBeSaved($data);
    }

Usage Example

Пример #1
0
 private function updateEntity($data, $entityName, $id)
 {
     $vpId = $this->vpidRepository->getVpidForEntity($entityName, $id);
     $data['vp_id'] = $vpId;
     if ($this->dbSchemaInfo->isChildEntity($entityName)) {
         $entityInfo = $this->dbSchemaInfo->getEntityInfo($entityName);
         $parentVpReference = "vp_" . $entityInfo->parentReference;
         if (!isset($data[$parentVpReference])) {
             $table = $this->dbSchemaInfo->getPrefixedTableName($entityName);
             $parentTable = $this->dbSchemaInfo->getTableName($entityInfo->references[$entityInfo->parentReference]);
             $vpidTable = $this->dbSchemaInfo->getPrefixedTableName('vp_id');
             $parentVpidSql = "SELECT HEX(vpid.vp_id) FROM {$table} t JOIN {$vpidTable} vpid ON t.{$entityInfo->parentReference} = vpid.id AND `table` = '{$parentTable}' WHERE {$entityInfo->idColumnName} = {$id}";
             $parentVpid = $this->database->get_var($parentVpidSql);
             $data[$parentVpReference] = $parentVpid;
         }
     }
     $shouldBeSaved = $this->mirror->shouldBeSaved($entityName, $data);
     if (!$shouldBeSaved) {
         return;
     }
     $savePostmeta = !$vpId && $entityName === 'post';
     // the post exists in DB for a while but until now it wasn't tracked, so we have to save its postmeta
     if (!$vpId) {
         $data = $this->vpidRepository->identifyEntity($entityName, $data, $id);
     }
     $this->mirror->save($entityName, $data);
     if (!$savePostmeta) {
         return;
     }
     $postmeta = $this->database->get_results("SELECT meta_id, meta_key, meta_value FROM {$this->database->postmeta} WHERE post_id = {$id}", ARRAY_A);
     foreach ($postmeta as $meta) {
         $meta['vp_post_id'] = $data['vp_id'];
         $meta = $this->vpidRepository->replaceForeignKeysWithReferences('postmeta', $meta);
         if (!$this->mirror->shouldBeSaved('postmeta', $meta)) {
             continue;
         }
         $meta = $this->vpidRepository->identifyEntity('postmeta', $meta, $meta['meta_id']);
         $this->mirror->save('postmeta', $meta);
     }
 }
All Usage Examples Of VersionPress\Storages\Mirror::shouldBeSaved