You are here

function elysia_cron_set in Elysia Cron 5.2

Same name and namespace in other branches
  1. 5 elysia_cron.module \elysia_cron_set()
  2. 6.2 elysia_cron.module \elysia_cron_set()
  3. 6 elysia_cron.module \elysia_cron_set()
  4. 7.2 elysia_cron.module \elysia_cron_set()
  5. 7 elysia_cron.module \elysia_cron_set()
24 calls to elysia_cron_set()
elysia_cron_execute in ./elysia_cron.module
elysia_cron_execute_aborted in ./elysia_cron.module
elysia_cron_reset_channel_disabled in ./elysia_cron.module
elysia_cron_reset_channel_rule in ./elysia_cron.module
elysia_cron_reset_job_channel in ./elysia_cron.module

... See full list

File

./elysia_cron.module, line 354

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]);
}