function SqlContentEntityStorage::restore

Same name in other branches
  1. 9 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::restore()
  2. 10 core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::restore()
  3. 11.x core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php \Drupal\Core\Entity\Sql\SqlContentEntityStorage::restore()

Overrides EntityStorageBase::restore

File

core/lib/Drupal/Core/Entity/Sql/SqlContentEntityStorage.php, line 853

Class

SqlContentEntityStorage
A content entity database storage implementation.

Namespace

Drupal\Core\Entity\Sql

Code

public function restore(EntityInterface $entity) {
    $transaction = $this->database
        ->startTransaction();
    try {
        // Insert the entity data in the base and data tables only for default
        // revisions.
        
        /** @var \Drupal\Core\Entity\ContentEntityInterface $entity */
        if ($entity->isDefaultRevision()) {
            $record = $this->mapToStorageRecord($entity->getUntranslated(), $this->baseTable);
            $this->database
                ->insert($this->baseTable)
                ->fields((array) $record)
                ->execute();
            if ($this->dataTable) {
                $this->saveToSharedTables($entity);
            }
        }
        // Insert the entity data in the revision and revision data tables.
        if ($this->revisionTable) {
            $record = $this->mapToStorageRecord($entity->getUntranslated(), $this->revisionTable);
            $this->database
                ->insert($this->revisionTable)
                ->fields((array) $record)
                ->execute();
            if ($this->revisionDataTable) {
                $this->saveToSharedTables($entity, $this->revisionDataTable);
            }
        }
        // Insert the entity data in the dedicated tables.
        $this->saveToDedicatedTables($entity, FALSE, []);
        // Ignore replica server temporarily.
        \Drupal::service('database.replica_kill_switch')->trigger();
    } catch (\Exception $e) {
        $transaction->rollBack();
        watchdog_exception($this->entityTypeId, $e);
        throw new EntityStorageException($e->getMessage(), $e->getCode(), $e);
    }
}

Buggy or inaccurate documentation? Please file an issue. Need support? Need help programming? Connect with the Drupal community.