You are here

function computing_update in Drupal Computing 7.2

Update an existing computing entity and persist any changes. Input/Output should NOT be encoded as json string before calling this: this function will take care of encoding/decoding

Parameters

object $record:: should be a PHP object. however, if it's an array, we'll convert to object first.

Return value

bool TRUE if successfully updated, false if not.

3 calls to computing_update()
computing_finish in ./computing.module
When agent finishes a computational task, call this function to persist results back to Drupal.
computing_update_field in ./computing.module
Only update and persist the given field. This is supposed to save bandwidth between Drupal and Agent by only updating one field instead of the entire object. It only handles the database properties of the entity, or single value field. Use your own…
computing_update_services_wrapper in ./computing.services.inc

File

./computing.module, line 226

Code

function computing_update($record) {

  //drupal_debug($record, 'computing_update');
  if (is_array($record)) {
    $record = (object) $record;
  }
  if (!empty($record->input)) {
    $record->input = drupal_json_encode($record->input);
  }
  if (!empty($record->output)) {
    $record->output = drupal_json_encode($record->output);
  }
  $record->changed = time();

  // copy from EntityAPIController. set original record. $record->original will be unset in $entity->save()
  // note that here input/output are already encoded into json string.
  if (!isset($record->original)) {
    $record->original = entity_load_unchanged('computing_record', $record->id);
  }

  // this is pass by reference. also note that $record->original is unset in entity_save() so we want to keep it here.
  $original = $record->original;
  $return = (bool) entity_save('computing_record', $record);
  if ($return) {

    // NOTE: here input/output are json encoded strings.
    $record->original = $original;
    rules_invoke_event('computing_event_updated', $record);

    //drupal_debug($original, "computing_update_old");

    //drupal_debug($record, "computing_update_new");
  }
  return $return;
}