function elysia_cron_set in Elysia Cron 5
Same name and namespace in other branches
- 5.2 elysia_cron.module \elysia_cron_set()
- 6.2 elysia_cron.module \elysia_cron_set()
- 6 elysia_cron.module \elysia_cron_set()
- 7.2 elysia_cron.module \elysia_cron_set()
- 7 elysia_cron.module \elysia_cron_set()
24 calls to elysia_cron_set()
File
- ./
elysia_cron.module, line 350
Code
function elysia_cron_set($name, $channel = false, $values = array()) {
if ($channel) {
$name = ':' . $name;
}
if (EC_DRUPAL_VERSION >= 7) {
db_merge('elysia_cron')
->key(array(
'name' => $name,
))
->fields($values)
->execute();
}
else {
$fields = array(
"name" => "'%s'",
"disable" => "%d",
"rule" => "'%s'",
"weight" => "%d",
"context" => "'%s'",
"running" => "%d",
"last_run" => "%d",
"last_aborted" => "%d",
"abort_count" => "%d",
"last_abort_function" => "'%s'",
"last_execution_time" => "%d",
"execution_count" => "%d",
"avg_execution_time" => "%f",
"max_execution_time" => "%d",
"last_shutdown_time" => "%d",
);
$ifields = array(
'disable',
'running',
'last_run',
'last_aborted',
'abort_count',
'last_execution_time',
'execution_count',
'avg_execution_time',
'max_execution_time',
'last_shutdown_time',
);
$uquery = array();
$uvalues = array();
foreach ($values as $k => $v) {
if (is_null($v) && !in_array($k, $ifields)) {
$uquery[] = $k . ' = NULL';
}
else {
$uquery[] = $k . ' = ' . $fields[$k];
$uvalues[] = $v;
}
}
$uvalues[] = $name;
db_query("update {elysia_cron} set " . implode(', ', $uquery) . " where name = '%s'", $uvalues);
if (!db_affected_rows()) {
foreach ($ifields as $f) {
if (empty($values[$f])) {
$values[$f] = 0;
}
}
$values['name'] = $name;
$iquery1 = array();
$iquery2 = array();
$ivalues = array();
foreach ($values as $k => $v) {
if (!is_null($v)) {
$iquery1[] = $k;
$iquery2[] = $fields[$k];
$ivalues[] = $v;
}
}
db_query("insert into {elysia_cron} (" . implode(', ', $iquery1) . ") values (" . implode(', ', $iquery2) . ")", $ivalues);
}
}
global $elysia_cron_db_cache;
unset($elysia_cron_db_cache[$name]);
}