protected function NodeStorageController::preSaveRevision

Overrides Drupal\Core\Entity\DatabaseStorageController::preSaveRevision().

Overrides DatabaseStorageController::preSaveRevision

File

drupal/core/modules/node/lib/Drupal/node/NodeStorageController.php, line 103
Definition of Drupal\node\NodeStorageController.

Class

NodeStorageController
Controller class for nodes.

Namespace

Drupal\node

Code

protected function preSaveRevision(\stdClass $record, EntityInterface $entity) {
  if ($entity
    ->isNewRevision()) {

    // When inserting either a new node or a new node revision, $node->log
    // must be set because {node_revision}.log is a text column and therefore
    // cannot have a default value. However, it might not be set at this
    // point (for example, if the user submitting a node form does not have
    // permission to create revisions), so we ensure that it is at least an
    // empty string in that case.
    // @todo: Make the {node_revision}.log column nullable so that we can
    // remove this check.
    if (!isset($record->log)) {
      $record->log = '';
    }
  }
  elseif (!isset($record->log) || $record->log === '') {

    // If we are updating an existing node without adding a new revision, we
    // need to make sure $node->log is unset whenever it is empty. As long as
    // $node->log is unset, drupal_write_record() will not attempt to update
    // the existing database column when re-saving the revision; therefore,
    // this code allows us to avoid clobbering an existing log entry with an
    // empty one.
    unset($record->log);
  }
  if ($entity
    ->isNewRevision()) {
    $record->timestamp = REQUEST_TIME;
    $record->uid = isset($record->revision_uid) ? $record->revision_uid : $GLOBALS['user']->uid;
  }
}