You are here

class CommerceLicenseEntityController in Commerce License 7

@file Controller for the commerce_license entity type.

Hierarchy

Expanded class hierarchy of CommerceLicenseEntityController

1 string reference to 'CommerceLicenseEntityController'
commerce_license_entity_info in ./commerce_license.module
Implements hook_entity_info().

File

includes/commerce_license.controller.inc, line 8
Controller for the commerce_license entity type.

View source
class CommerceLicenseEntityController extends EntityBundlePluginEntityController {

  /**
   * Overrides EntityBundlePluginEntityController::save().
   */
  public function save($entity, DatabaseTransaction $transaction = NULL) {
    $entity->is_new_revision = !empty($entity->is_new_revision) || !empty($entity->revision) || !empty($entity->is_new);

    // New revisions are always set as default.
    if ($entity->is_new_revision) {
      $entity->default_revision = TRUE;
    }
    parent::save($entity, $transaction);

    // Guard against #2291623.
    unset($entity->revision);
  }

  /**
   * Overrides EntityBundlePluginEntityController::saveRevision().
   *
   * Maintains the revision_created and revision_ended timestamps and the
   * revision_uid column.
   */
  protected function saveRevision($entity) {
    if ($entity->is_new_revision) {
      $current_time = commerce_license_get_time();
      $entity->revision_created = $current_time;
      $entity->revision_ended = 0;
      $entity->revision_uid = $GLOBALS['user']->uid;

      // Clear the log if it's unset, or the same as the previous revision's.
      if (empty($entity->log) || $entity->log == $entity->original->log) {
        $entity->log = '';
      }

      // A previous revision exists, close it.
      if (!empty($entity->revision_id)) {
        db_update($this->revisionTable)
          ->fields(array(
          'revision_ended' => $current_time - 1,
        ))
          ->condition('revision_id', $entity->revision_id)
          ->execute();
      }
    }
    parent::saveRevision($entity);
  }

  /**
   * Overrides EntityBundlePluginEntityController::delete().
   */
  public function delete($ids, DatabaseTransaction $transaction = NULL) {
    $entities = $ids ? $this
      ->load($ids) : FALSE;
    if (!$entities) {

      // Do nothing, in case invalid or no ids have been passed.
      return;
    }
    try {
      parent::delete($ids, $transaction);

      // Try to delete references to the given licenses.
      // Do this after deleting the entities in question in order to give
      // hook_entity_delete() implementations a chance to do their own thing
      // (for example, deleting both the reference AND the referencing entity).
      foreach ($entities as $entity) {
        commerce_license_delete_references($entity);
      }
    } catch (Exception $e) {
      if (isset($transaction)) {
        $transaction
          ->rollback();
      }
      throw $e;
    }
  }

}

Members

Namesort descending Modifiers Type Description Overrides
CommerceLicenseEntityController::delete public function Overrides EntityBundlePluginEntityController::delete(). Overrides EntityAPIController::delete
CommerceLicenseEntityController::save public function Overrides EntityBundlePluginEntityController::save(). Overrides EntityAPIController::save
CommerceLicenseEntityController::saveRevision protected function Overrides EntityBundlePluginEntityController::saveRevision(). Overrides EntityAPIController::saveRevision
DrupalDefaultEntityController::$cache protected property Whether this entity type should use the static cache.
DrupalDefaultEntityController::$entityCache protected property Static cache of entities, keyed by entity ID.
DrupalDefaultEntityController::$entityInfo protected property Array of information about the entity.
DrupalDefaultEntityController::$entityType protected property Entity type for this controller instance.
DrupalDefaultEntityController::$hookLoadArguments protected property Additional arguments to pass to hook_TYPE_load().
DrupalDefaultEntityController::$idKey protected property Name of the entity's ID field in the entity database table.
DrupalDefaultEntityController::$revisionKey protected property Name of entity's revision database table field, if it supports revisions.
DrupalDefaultEntityController::$revisionTable protected property The table that stores revisions, if the entity supports revisions.
DrupalDefaultEntityController::attachLoad protected function Attaches data to entities upon loading. 4
DrupalDefaultEntityController::cacheGet protected function Gets entities from the static cache. 1
DrupalDefaultEntityController::cacheSet protected function Stores entities in the static entity cache.
DrupalDefaultEntityController::cleanIds protected function Ensures integer entity IDs are valid.
DrupalDefaultEntityController::filterId protected function Callback for array_filter that removes non-integer IDs.
EntityAPIController::$bundleKey protected property
EntityAPIController::$cacheComplete protected property
EntityAPIController::$defaultRevisionKey protected property
EntityAPIController::buildContent public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::buildContent
EntityAPIController::buildQuery protected function Overrides DrupalDefaultEntityController::buildQuery(). Overrides DrupalDefaultEntityController::buildQuery 1
EntityAPIController::deleteRevision public function Implements EntityAPIControllerRevisionableInterface::deleteRevision(). Overrides EntityAPIControllerRevisionableInterface::deleteRevision
EntityAPIController::export public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::export 1
EntityAPIController::import public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::import
EntityAPIController::invoke public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::invoke 1
EntityAPIController::load public function Overridden. Overrides DrupalDefaultEntityController::load 1
EntityAPIController::renderEntityProperty protected function Renders a single entity property.
EntityAPIController::resetCache public function Overrides DrupalDefaultEntityController::resetCache(). Overrides DrupalDefaultEntityController::resetCache 1
EntityAPIController::view public function Implements EntityAPIControllerInterface. Overrides EntityAPIControllerInterface::view 1
EntityAPIController::__construct public function Overridden. Overrides DrupalDefaultEntityController::__construct 1
EntityBundlePluginEntityController::create public function Overrides EntityAPIController::create(). Overrides EntityAPIController::create
EntityBundlePluginEntityController::query public function Overrides EntityAPIController::query(). Overrides EntityAPIController::query