protected function EntityAPIController::saveRevision

cis7 entity.controller.inc protected EntityAPIController::saveRevision($entity)
cle7 entity.controller.inc protected EntityAPIController::saveRevision($entity)
elmsmedia7 entity.controller.inc protected EntityAPIController::saveRevision($entity)
icor7 entity.controller.inc protected EntityAPIController::saveRevision($entity)
meedjum_blog7 entity.controller.inc protected EntityAPIController::saveRevision($entity)
mooc7 entity.controller.inc protected EntityAPIController::saveRevision($entity)

Saves an entity revision.

Parameters

Entity $entity: Entity revision to save.

1 call to EntityAPIController::saveRevision()
EntityAPIController::save in sites/all/modules/ulmus/entity/includes/entity.controller.inc
Implements EntityAPIControllerInterface.

File

sites/all/modules/ulmus/entity/includes/entity.controller.inc, line 493
Provides a controller building upon the core controller but providing more features like full CRUD functionality.

Class

EntityAPIController
A controller implementing EntityAPIControllerInterface for the database.

Code

protected function saveRevision($entity) {
  // Convert the entity into an array as it might not have the same properties
  // as the entity, it is just a raw structure.
  $record = (array) $entity;
  // File fields assumes we are using $entity->revision instead of
  // $entity->is_new_revision, so we also support it and make sure it's set to
  // the same value.
  $entity->is_new_revision = !empty($entity->is_new_revision) || !empty($entity->revision) || $entity->is_new;
  $entity->revision = &$entity->is_new_revision;
  $entity->{$this->defaultRevisionKey} = !empty($entity->{$this->defaultRevisionKey}) || $entity->is_new;



  // When saving a new revision, set any existing revision ID to NULL so as to
  // ensure that a new revision will actually be created.
  if ($entity->is_new_revision && isset($record[$this->revisionKey])) {
    $record[$this->revisionKey] = NULL;
  }

  if ($entity->is_new_revision) {
    drupal_write_record($this->revisionTable, $record);
    $update_default_revision = $entity->{$this->defaultRevisionKey};
  }
  else {
    drupal_write_record($this->revisionTable, $record, $this->revisionKey);
    // @todo: Fix original entity to be of the same revision and check whether
    // the default revision key has been set.
    $update_default_revision = $entity->{$this->defaultRevisionKey} && $entity->{$this->revisionKey} != $entity->original->{$this->revisionKey};
  }
  // Make sure to update the new revision key for the entity.
  $entity->{$this->revisionKey} = $record[$this->revisionKey];

  // Mark this revision as the default one.
  if ($update_default_revision) {
    db_update($this->entityInfo['base table'])->fields(array($this->revisionKey => $record[$this->revisionKey]))->condition($this->idKey, $entity->{$this->idKey})->execute();
  }
  return $entity->is_new_revision ? SAVED_NEW : SAVED_UPDATED;
}
Error | ELMSLN API

Error

×

Error message

  • Warning: Cannot modify header information - headers already sent by (output started at /var/www/html/elmsln_community/api.elmsln.org/includes/common.inc:2791) in drupal_send_headers() (line 1499 of /var/www/html/elmsln_community/api.elmsln.org/includes/bootstrap.inc).
  • Error: Call to undefined function apc_delete() in DrupalAPCCache->clear() (line 289 of /var/www/html/elmsln_community/api.elmsln.org/sites/all/modules/apc/drupal_apc_cache.inc).
The website encountered an unexpected error. Please try again later.