You are here

nodejs.install in Node.js integration 8

Same filename and directory in other branches
  1. 6 nodejs.install
  2. 7 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.
 */
use Drupal\nodejs\Nodejs;

/**
 * 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 [];
  }
  $nodejs = \Drupal::service('nodejs.nodejs');
  $value = t('The Node.js server was successfully reached.');
  $severity = REQUIREMENT_OK;
  if (!$nodejs
    ->healthCheck()) {
    $value = t('Error reaching the Node.js server. Enable HTTP error-logging and check the dblog page for more details');
    $severity = REQUIREMENT_ERROR;
  }
  else {
    if (!$nodejs
      ->safeNodeServerVersion()) {
      $value = t('The Drupal-Node.js application version is insecure. Please update.');
      $severity = REQUIREMENT_ERROR;
    }
  }
  return [
    'nodejs' => [
      'title' => t('Node.js'),
      'description' => t('Can Drupal connect to the Node.js server?'),
      'value' => $value,
      'severity' => $severity,
    ],
  ];
}

Functions

Namesort descending Description
nodejs_requirements Implements hook_requirements()
nodejs_schema Implements hook_schema().