You are here

function services_requirements in Services 6.3

Same name and namespace in other branches
  1. 7.3 services.install \services_requirements()

Implements hook_requirements().

File

./services.install, line 94
Install, uninstall and update the Services module.

Code

function services_requirements($phase) {
  $requirements = array();
  $t = get_t();

  // Warn users of the possible threat.
  if ($phase == 'runtime') {

    // If rest_server is enabled, make sure it's from Services core.
    if (module_exists('rest_server')) {
      $rest_path = drupal_get_path('module', 'rest_server');
      $core_path = drupal_get_path('module', 'services') . '/servers/rest_server';
      if ($rest_path !== $core_path) {
        $requirements['services_rest_server_compatibility'] = array(
          'description' => $t('The enabled version of Rest Server is not from Services core. Uninstall then remove the old Rest Server module from') . ' ' . $rest_path . ' ' . t('to utilize Services core Rest Server'),
          'severity' => REQUIREMENT_ERROR,
          'title' => 'Services Rest Server Compatibility',
        );
      }
    }

    //Pull endpoints that do not have services authentication enabled
    $result = db_query("SELECT * FROM {services_endpoint} AS se WHERE se.authentication NOT LIKE '%s'", '%services%');
    $items = array();
    $has_endpoint = FALSE;
    while ($endpoint = db_fetch_object($result)) {
      $has_endpoint = TRUE;
      $items[] = l($endpoint->name, 'admin/build/services/list/' . $endpoint->name);
    }

    // theme the endpoints list
    $endpoints = '';
    if (!empty($items)) {
      $endpoints = theme('item_list', array(
        'items' => $items,
      ));
    }

    // Only display the list if we have at least one endpoint without services authentication.
    if (count($items)) {
      $requirements['services'] = array(
        'description' => $t('Services authentication mechanism has not been enabled for the following endpoints. Requests to these endpoints will always be anonymous.'),
        'severity' => REQUIREMENT_WARNING,
        'value' => $endpoints,
        'title' => 'Services Authentication Mechanism',
      );
    }
    else {
      $requirements['services'] = array(
        'severity' => REQUIREMENT_OK,
        'value' => 'Enabled for all Endpoints',
        'title' => 'Services Authentication Mechanism',
      );
    }
  }
  return $requirements;
}