You are here

function computing_create in Drupal Computing 7.2

Create a computing record and save it as an entity.

Parameters

$app_name string: the name of the application to process the record, which is also the "bundle" type of the entity.:

$command string: the command to execute in the application.:

$label string: human readable explanation:

$input array: this should be an array to pass to the agent for executing. if it's a special type, override it in $options.:

$options array: extra options to save in the computing record. will override the value data.:

Return value

int: the id for the newly created computing record, or FALSE if not successful.

3 calls to computing_create()
ComputingQueue::createItem in ./computing.queue.inc
Add a queue item and store it directly to the queue.
computing_command_form_submit in ./computing.admin.inc
computing_create_services_wrapper in ./computing.services.inc

File

./computing.module, line 155

Code

function computing_create($app_name, $command, $label, $input, $options = array()) {

  //drupal_debug(func_get_args(), 'computing_create');

  // initial settings.
  $values = array(
    'application' => $app_name,
    'command' => $command,
    'label' => $label,
    'uid' => user_is_logged_in() ? $GLOBALS['user']->uid : 0,
    'status' => 'RDY',
    'weight' => 0,
  );
  if ($input != NULL) {

    // this is to take care of mixed data type to save in db as blob.
    $values['input'] = drupal_json_encode($input);

    //$values['input'] = $input;
  }

  // set additional settings. will override the other values.
  if (!empty($options)) {
    $values = $options + $values;
  }

  // create the entity in memory
  $record = computing_record_create_entity($values);

  // try to persist.
  entity_save('computing_record', $record);
  if (!empty($record->id)) {

    // only when it's successful should we invoke rules.
    // note: here input is a json encoded string.
    rules_invoke_event('computing_event_created', $record);

    // "id" seems to be a "string", which causes problem in json encoding.
    return (int) $record->id;
  }
  else {
    return FALSE;
  }
}