You are here

public function BrightcoveClientEntityController::save in Brightcove Video Connect 7.6

Same name and namespace in other branches
  1. 7.7 brightcove.client.inc \BrightcoveClientEntityController::save()

Overrides EntityAPIController::save()

Overrides EntityAPIControllerExportable::save

File

./brightcove.client.inc, line 95
Client related code.

Class

BrightcoveClientEntityController
Entity controller class for Brightcove client.

Code

public function save($client, DatabaseTransaction $transaction = NULL) {
  global $user;

  // Hardcode the changed time.
  $client->changed = REQUEST_TIME;
  if (empty($client->{$this->idKey}) || !empty($client->is_new)) {

    // Set the creation timestamp if not set, for new entities.
    if (empty($client->created)) {
      $client->created = REQUEST_TIME;
    }
  }
  else {

    // Otherwise if the client is not new but comes from an entity_create()
    // or similar function call that initializes the created timestamp and uid
    // value to empty strings, unset them to prevent destroying existing data
    // in those properties on update.
    if ($client->created === '') {
      unset($client->created);
    }
    if ($client->uid === '') {
      unset($client->uid);
    }
  }

  // Determine if we will be inserting a new client.
  $client->is_new = empty($client->bcid);
  $return = parent::save($client, $transaction);
  if (!(($default_client = variable_get('brightcove_client_default')) && (bool) brightcove_client_load($default_client))) {
    variable_set('brightcove_client_default', $client->bcid);
  }
  return $return;
}