You are here

gplib.install in Grammar Parser Library 7.2

Same filename and directory in other branches
  1. 7 gplib.install

Install, update and uninstall functions for the Grammar Parser Library module.

@author Jim Berry ("solotandem", http://drupal.org/user/240748)

File

gplib.install
View source
<?php

/**
 * @file
 * Install, update and uninstall functions for the Grammar Parser Library module.
 *
 * @author Jim Berry ("solotandem", http://drupal.org/user/240748)
 */

/**
 * Minimum recommended value of PHP memory_limit.
 */
define('PARSER_MINIMUM_PHP_MEMORY', '128M');

/**
 * Minimum recommended value of PHP max_execution_time.
 */
define('PARSER_MINIMUM_PHP_TIME', '30');

/**
 * Implements hook_requirements().
 */
function gplib_requirements($phase) {
  $requirements = array();

  // Ensure translations don't break at install time
  $t = get_t();

  // Test PHP memory_limit. (Copied from system.install.)
  $memory_limit = ini_get('memory_limit');
  $requirements['grammar_parser_memory_limit'] = array(
    'title' => $t('Grammar Parser PHP memory limit'),
    'value' => $memory_limit == -1 ? t('-1 (Unlimited)') : $memory_limit,
  );
  if ($memory_limit && $memory_limit != -1 && parse_size($memory_limit) < parse_size(PARSER_MINIMUM_PHP_MEMORY)) {
    $description = $t('Consider increasing your PHP memory limit to %minimum_php_memory to help prevent errors when running the grammar parser.', array(
      '%minimum_php_memory' => PARSER_MINIMUM_PHP_MEMORY,
    ));
    if ($php_ini_path = get_cfg_var('cfg_file_path')) {
      $description .= ' ' . $t('Increase the memory limit by editing the memory_limit parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array(
        '%configuration-file' => $php_ini_path,
      ));
    }
    else {
      $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP memory limit.');
    }
    $requirements['grammar_parser_memory_limit']['description'] = $description;
    $requirements['grammar_parser_memory_limit']['severity'] = REQUIREMENT_WARNING;
  }

  // Test PHP max_execution_time.
  $time_limit = ini_get('max_execution_time');
  $requirements['grammar_parser_time_limit'] = array(
    'title' => $t('Grammar Parser PHP time limit'),
    'value' => $time_limit == 0 ? t('0 (Unlimited)') : $time_limit . ' seconds',
  );
  if ($time_limit && $time_limit != 0 && $time_limit < PARSER_MINIMUM_PHP_TIME) {
    $description = $t('Consider increasing your PHP maximum execution time limit to %minimum_php_time seconds to help prevent errors when running the grammar parser.', array(
      '%minimum_php_time' => PARSER_MINIMUM_PHP_TIME,
    ));
    if ($php_ini_path = get_cfg_var('cfg_file_path')) {
      $description .= ' ' . $t('Increase the execution time limit by editing the max_execution_time parameter in the file %configuration-file and then restart your web server (or contact your system administrator or hosting provider for assistance).', array(
        '%configuration-file' => $php_ini_path,
      ));
    }
    else {
      $description .= ' ' . $t('Contact your system administrator or hosting provider for assistance with increasing your PHP maximum execution time limit.');
    }
    $requirements['grammar_parser_time_limit']['description'] = $description;
    $requirements['grammar_parser_time_limit']['severity'] = REQUIREMENT_WARNING;
  }
  if ($phase != 'runtime') {

    // None of the following requirements is relevant outside of runtime.
    return $requirements;
  }
  $info = gplib_libraries_info();
  $info = $info['grammar_parser'];
  $keys = array_keys($info['versions']);
  $version = reset($keys);
  $url = l('here', $info['download url']);
  $message = $t('Install version @version of the Grammar Parser library code (from !url) in a libraries directory such as "sites/all/libraries." For easy installation, use the drush make file in the Grammar Parser Library project.', array(
    '@version' => $version,
    '!url' => $url,
  ));
  $info = libraries_load('grammar_parser');
  if (!$info['loaded']) {
    $requirements['grammar_parser_version'] = array(
      'severity' => REQUIREMENT_ERROR,
      'title' => $t('Grammar Parser version'),
      'value' => $t('Not found'),
      'description' => $message,
    );
    if (isset($info['error']) && $info['error'] == 'not detected') {
      $requirements['grammar_parser_version']['value'] = $t('The version could not be detected');
    }
    elseif (isset($info['error']) && $info['error'] == 'not supported') {
      $requirements['grammar_parser_version']['value'] = $t('The installed version @version is not supported', array(
        '@version' => $info['version'],
      ));
    }
  }
  elseif (!$info['version'] || !version_compare($info['version'], $version, '>=')) {
    $path = $info['library path'];
    $requirements['grammar_parser_version'] = array(
      'severity' => REQUIREMENT_WARNING,
      'title' => $t('Grammar Parser version'),
      'value' => $t('A version newer than the installed version @version is available', array(
        '@version' => $info['version'],
      )),
      'description' => $message,
    );
  }
  else {
    $requirements['grammar_parser_version'] = array(
      'title' => $t('Grammar Parser version'),
      'value' => $info['version'],
    );
  }
  return $requirements;
}

Functions

Namesort descending Description
gplib_requirements Implements hook_requirements().

Constants

Namesort descending Description
PARSER_MINIMUM_PHP_MEMORY Minimum recommended value of PHP memory_limit.
PARSER_MINIMUM_PHP_TIME Minimum recommended value of PHP max_execution_time.