You are here

function nodejs_requirements in Node.js integration 7

Same name and namespace in other branches
  1. 8 nodejs.install \nodejs_requirements()

Implements hook_requirements()

File

./nodejs.install, line 81
Install, update and uninstall functions for the nodejs module.

Code

function nodejs_requirements($phase) {
  if ($phase != 'runtime') {
    return array();
  }
  $requirements['nodejs'] = array(
    'title' => t('Node.js'),
    'description' => t('Can Drupal connect to the Node.js server?'),
  );

  // Nodejs::healthCheck() does the work for us. It will return FALSE if the
  // HTTP Request failed so we just check to see if that happened or not. If
  // There's a response, we can connect to the server.
  if (Nodejs::healthCheck()) {
    $server_version = Nodejs::getServerVersion();
    if (!Nodejs::checkServerVersion()) {
      $result = array(
        'value' => t('The Drupal-Node.js server application is not compatible with this version of the module. Please ensure both the Node.js Integration module and Node.js server application are up to date.'),
        'severity' => REQUIREMENT_ERROR,
      );
    }
    else {
      if (nodejs_server_has_update()) {
        $result = array(
          'value' => t('The Drupal-Node.js server application (version @version) is out of date. Please install the latest version.', array(
            '@version' => $server_version,
          )),
          'severity' => REQUIREMENT_WARNING,
        );
      }
      else {
        $result = array(
          'value' => t('The Drupal-Node.js server (version @version) was successfully reached.', array(
            '@version' => $server_version,
          )),
          'severity' => REQUIREMENT_OK,
        );
      }
    }
  }
  else {

    // Http request to the server failed.
    $result = array(
      'value' => t('Error reaching the Node.js server. Make sure your Node.js service key matches the key set in the server application. Enable HTTP error-logging and check the dblog page for more details.'),
      'severity' => REQUIREMENT_ERROR,
    );
  }
  $requirements['nodejs'] += $result;
  return $requirements;
}