You are here

nodejs.install in Node.js integration 7

Same filename and directory in other branches
  1. 8 nodejs.install
  2. 6 nodejs.install

Install, update and uninstall functions for the nodejs module.

File

nodejs.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the nodejs module.
 */

/**
 * Implements hook_uninstall().
 */
function nodejs_uninstall() {
  variable_del('nodejs_server_scheme');
  variable_del('nodejs_server_host');
  variable_del('nodejs_server_port');
  variable_del('nodejs_client_js_scheme');
  variable_del('nodejs_client_js_host');
  variable_del('nodejs_client_js_port');
  variable_del('nodejs_pages');
  variable_del('nodejs_config_resource');
  variable_del('nodejs_log_http_errors');
  variable_del('nodejs_config');
  variable_del('nodejs_socket_io_path');
  variable_del('nodejs_socket_io_type');
  variable_del('nodejs_enable_userchannel');
  variable_del('nodejs_auth_check_callback');
  variable_del('nodejs_auth_get_token_callback');
  variable_del('nodejs_config_backend_host');
  variable_del('nodejs_config_backend_messagePath');
  variable_del('nodejs_config_backend_port');
  variable_del('nodejs_config_cert');
  variable_del('nodejs_config_debug');
  variable_del('nodejs_config_extensions');
  variable_del('nodejs_config_host');
  variable_del('nodejs_config_js');
  variable_del('nodejs_config_js_suggestion');
  variable_del('nodejs_config_key');
  variable_del('nodejs_config_port');
  variable_del('nodejs_config_publishUrl');
  variable_del('nodejs_config_write_channels');
  variable_del('nodejs_config_write_clients');
  variable_del('nodejs_service_key');
  variable_del('nodejs_disabled_pages');
}

/**
 * Implements hook_schema().
 */
function nodejs_schema() {
  return array(
    'nodejs_presence' => array(
      'description' => 'List of currently online users on a node.js server.',
      'fields' => array(
        'uid' => array(
          'description' => 'The uid of the user.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
        'login_time' => array(
          'description' => 'The timestamp of when the user came online.',
          'type' => 'int',
          'unsigned' => TRUE,
          'not null' => TRUE,
          'default' => 0,
        ),
      ),
      'indexes' => array(
        'login_time' => array(
          'login_time',
        ),
      ),
      'unique keys' => array(
        'uid' => array(
          'uid',
        ),
      ),
    ),
  );
}

/**
 * Implements hook_requirements()
 */
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;
}

Functions