You are here

function ultimate_cron_prepare_job in Ultimate Cron 7.2

Prepare a UltimateCronJob object with hook data, etc.

Parameters

string $name: Name of the job.

array $hook: The cron hook data from hook_cronapi(), etc.

UltimateCronJob $job: (optional) The job to prepare with the hook data. If no job is given, a new blank UltimateCronJob object will be used.

Return value

UltimateCronJob The prepared UltimateCronJob object.

2 calls to ultimate_cron_prepare_job()
UltimateCronQueueSettings::cron_alter in plugins/ultimate_cron/settings/queue.class.php
Implements hook_cron_alter().
_ultimate_cron_job_load_all in ./ultimate_cron.module
CTools Export load all callback.

File

./ultimate_cron.module, line 434

Code

function ultimate_cron_prepare_job($name, $hook, $job = NULL) {
  $schema = ctools_export_get_schema('ultimate_cron_job');
  $export = $schema['export'];
  if (!$job) {
    $job = ctools_export_crud_new('ultimate_cron_job');
    $job->name = $name;
    $job->title = $hook['title'];
    $job->description = $hook['description'];
    $job->table = 'ultimate_cron_job';
    $job->export_type = EXPORT_IN_CODE;
    $job->{$export['export type string']} = t('Default');
    $job->disabled = ultimate_cron_job_get_status($name);
    if (!isset($job->disabled)) {
      $job->disabled = !$hook['enabled'];
    }
  }
  else {

    // If object lives in database, then it is overridden, since we do not
    // have objects living only in the database.
    if ($job->export_type & EXPORT_IN_DATABASE) {
      $job->{$export['export type string']} = t('Overridden');
      $job->export_type |= EXPORT_IN_CODE;
    }
  }

  // We do alot of += on arrays. Let's make sure we have an array to begin with.
  ctools_include('plugins');
  $plugin_types = ctools_plugin_get_plugin_type_info();
  foreach ($plugin_types['ultimate_cron'] as $plugin_type => $info) {
    $class = $info['defaults']['static']['class'];
    if ($class::$multiple) {
      $plugins = _ultimate_cron_plugin_load_all($plugin_type);
      foreach ($plugins as $plugin) {
        if (!isset($job->settings[$plugin_type][$plugin->name])) {
          $job->settings[$plugin_type][$plugin->name] = array();
        }
      }
    }
    else {
      if (!isset($job->settings[$plugin_type])) {
        $job->settings[$plugin_type] = array();
      }
    }
  }
  $job->hook = $hook;
  return $job;
}