public function EntityAPIController::save

cis7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)
cle7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)
elmsmedia7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)
icor7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)
meedjum_blog7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)
mooc7 entity.controller.inc public EntityAPIController::save($entity, DatabaseTransaction $transaction = NULL)

Implements EntityAPIControllerInterface.

Parameters

$transaction: Optionally a DatabaseTransaction object to use. Allows overrides to pass in their transaction object.

Overrides EntityAPIControllerInterface::save

1 method overrides EntityAPIController::save()
EntityAPIControllerExportable::save in sites/all/modules/ulmus/entity/includes/entity.controller.inc
Overridden to care exportables that are overridden.

File

sites/all/modules/ulmus/entity/includes/entity.controller.inc, line 433
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

public function save($entity, DatabaseTransaction $transaction = NULL) {
  $transaction = isset($transaction) ? $transaction : db_transaction();
  try {
    // Load the stored entity, if any.
    if (!empty($entity->{$this->idKey}) && !isset($entity->original)) {
      // In order to properly work in case of name changes, load the original
      // entity using the id key if it is available.
      $entity->original = entity_load_unchanged($this->entityType, $entity->{$this->idKey});
    }
    $entity->is_new = !empty($entity->is_new) || empty($entity->{$this->idKey});
    $this->invoke('presave', $entity);

    if ($entity->is_new) {
      $return = drupal_write_record($this->entityInfo['base table'], $entity);
      if ($this->revisionKey) {
        $this->saveRevision($entity);
      }
      $this->invoke('insert', $entity);
    }
    else {
      // Update the base table if the entity doesn't have revisions or
      // we are updating the default revision.
      if (!$this->revisionKey || !empty($entity->{$this->defaultRevisionKey})) {
        $return = drupal_write_record($this->entityInfo['base table'], $entity, $this->idKey);
      }
      if ($this->revisionKey) {
        $return = $this->saveRevision($entity);
      }
      $this->resetCache(array($entity->{$this->idKey}));
      $this->invoke('update', $entity);

      // Field API always saves as default revision, so if the revision saved
      // is not default we have to restore the field values of the default
      // revision now by invoking field_attach_update() once again.
      if ($this->revisionKey && !$entity->{$this->defaultRevisionKey} && !empty($this->entityInfo['fieldable'])) {
        field_attach_update($this->entityType, $entity->original);
      }
    }

    // Ignore slave server temporarily.
    db_ignore_slave();
    unset($entity->is_new);
    unset($entity->is_new_revision);
    unset($entity->original);

    return $return;
  }
  catch (Exception $e) {
    $transaction->rollback();
    watchdog_exception($this->entityType, $e);
    throw $e;
  }
}
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.