function computing_create_record in Drupal Computing 7
Creates a command record and save to {computing_record} queue. Duplicate command would not get saved twice. To force saving a duplicate command, set the 'updated' field or any input field with different value in $options.
Callers should make sure 'input' and 'output' fields are already decoded as byte strings.
Parameters
$app:
$command:
$description:
$fields:
Return value
The ID of the newly created command record.
2 calls to computing_create_record()
File
- ./
computing.module, line 183
Code
function computing_create_record($app, $command, $description = NULL, $fields = array()) {
$created = isset($fields['created']) ? $fields['created'] : FALSE;
// array_merge(): 2nd array overrides first one.
$fields = array_merge($fields, compact('app', 'command', 'description'));
$fields = array_merge(array(
'control' => 'REDY',
'weight' => 0,
), $fields);
$fields = computing_validate_fields($fields, TRUE);
unset($fields['created']);
// to avoid search duplicate record with 'created' field.
// since db_merge() doesn't return auto increment id, we simply query to check duplicate and then insert.
$result = _computing_query_records($fields, 1);
if (($dup = $result
->fetchObject()) != FALSE) {
watchdog('computing', "Request to create duplicate command record {$dup->id}");
return $dup->id;
}
// set "created" after checking for duplicate.
$fields['created'] = $created == FALSE ? time() : $created;
$insert = db_insert('computing_record');
$insert
->fields($fields);
$id = $insert
->execute();
return $id;
}