You are here

function drush_ultimate_cron_cron_job_set in Ultimate Cron 7.2

Set a cron jobs configuration.

File

./ultimate_cron.drush.inc, line 371
Drush commands for Ultimate Cron!

Code

function drush_ultimate_cron_cron_job_set($name = NULL, $settings = NULL) {
  if (!$name) {
    return drush_set_error(dt('No job specified?'));
  }
  if (!$settings) {
    return drush_set_error(dt('No settings specified?'));
  }
  $settings = drupal_json_decode($settings);
  if ($settings === FALSE) {
    return drush_set_error(dt('Invalid JSON'));
  }
  $job = _ultimate_cron_job_load($name);
  $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) {
      if (isset($settings[$plugin_type])) {
        $job->settings[$plugin_type] = $settings[$plugin_type] + $job->settings[$plugin_type];
      }
    }
    else {
      $plugins = _ultimate_cron_plugin_load_all($plugin_type);
      foreach ($plugins as $plugin) {
        if (isset($settings[$plugin_type][$plugin->name])) {
          $job->settings[$plugin_type][$plugin->name] = $settings[$plugin_type][$plugin->name] + $job->settings[$plugin_type][$plugin->name];
        }
      }
    }
  }
  require_once drupal_get_path('module', 'ultimate_cron') . '/includes/nicejson.php';
  $nicejson = json_format(drupal_json_encode($job->settings));
  drush_print($nicejson);
  if (drush_confirm(dt('Do you want to update the job with the above settings?'))) {
    ctools_include('export');
    ctools_export_crud_save('ultimate_cron_job', $job);
    drush_print(dt('Job has been updated'));
  }
}