You are here

function ultimate_cron_get_module_hooks in Ultimate Cron 7.2

Get cron hooks declared by a module.

Parameters

string $module: Name of module.

Return value

array Hook definitions for the specified module.

1 call to ultimate_cron_get_module_hooks()
ultimate_cron_get_hooks in ./ultimate_cron.module
Get all cron hooks defined.

File

./ultimate_cron.module, line 1306

Code

function ultimate_cron_get_module_hooks($module) {
  $items = array();
  if (module_hook($module, 'cronapi')) {
    $items = module_invoke($module, 'cronapi', NULL);
    if (!is_array($items)) {

      // API Version 1.x
      $items = array();
      $list = module_invoke($module, 'cronapi', 'list');
      if (!$list) {
        $list = array();
      }
      foreach ($list as $name => $title) {
        $items[$name] = array(
          'title' => $title,
        );
      }
      foreach ($items as $name => &$item) {
        $item['api_version'] = 'ultimate_cron-1';
        $rules = module_invoke($module, 'cronapi', 'rule', $name);
        $rules = $rules ? $rules : array();
        $settings = (array) module_invoke($module, 'cronapi', 'settings', $name);
        if (empty($settings['rules']) && $rules) {
          $settings['rules'] = is_array($rules) ? $rules : array(
            $rules,
          );
        }
        if (!empty($settings['rules'])) {
          $settings['scheduler'] = array(
            'name' => 'crontab',
            'crontab' => array(
              'rules' => $settings['rules'],
            ),
          );
          unset($settings['rules']);
        }
        $settings += array(
          'configure' => module_invoke($module, 'cronapi', 'configure', $name),
        );
        $item += $settings;
      }
    }
    else {
      foreach ($items as &$item) {
        if (!empty($item['rule'])) {

          // Elysia 2.x compatibility.
          $item['scheduler'] = array(
            'name' => 'crontab',
            'crontab' => array(
              'rules' => array(
                $item['rule'],
              ),
            ),
          );
          $item['api_version'] = 'elysia_cron-2';
          $item['title'] = $item['description'];
        }
      }
    }
  }

  // Add hook_cron() if applicable.
  if (module_hook($module, 'cron')) {
    if (empty($items["{$module}_cron"])) {
      $items["{$module}_cron"] = array();
    }
    $info = system_get_info('module', $module);
    $items["{$module}_cron"] += array(
      'module' => $module,
      'title' => 'Default cron handler',
      'configure' => empty($info['configure']) ? NULL : $info['configure'],
      'tags' => array(),
      'pass job argument' => FALSE,
    );
    $items["{$module}_cron"]['tags'][] = 'core';
  }
  foreach (ultimate_cron_get_easy_hooks() as $name => $easy_hook) {
    $hook_name = "{$module}_{$name}";
    if (module_hook($module, $name)) {
      if (empty($items[$hook_name])) {
        $items[$hook_name] = array();
      }
      $items[$hook_name] += $easy_hook;
      $info = system_get_info('module', $module);
      $items[$hook_name] += array(
        'module' => $module,
        'title' => 'Easy hook ' . $name,
      );
    }
  }

  // Make sure the module is defined.
  foreach ($items as &$item) {
    $item += array(
      'module' => $module,
    );
  }
  return $items;
}