Skip to content
Snippets Groups Projects
system.install 120 KiB
Newer Older
Dries Buytaert's avatar
Dries Buytaert committed
<?php
define('DRUPAL_MINIMUM_PHP',    '4.3.3');
define('DRUPAL_MINIMUM_MYSQL',  '3.23.17'); // If using MySQL
define('DRUPAL_MINIMUM_PGSQL',  '7.3');  // If using PostgreSQL
define('DRUPAL_MINIMUM_APACHE', '1.3');  // If using Apache

/**
 * Test and report Drupal installation requirements.
 */
function system_requirements($phase) {
  $requirements = array();
  // Ensure translations don't break at install time
  $t = get_t();

  // Report Drupal version
  if ($phase == 'runtime') {
    $requirements['drupal'] = array(
      'title' => $t('Drupal'),
      'value' => VERSION,
      'severity' => REQUIREMENT_INFO
  $software = $_SERVER['SERVER_SOFTWARE'];
  $requirements['webserver'] = array(
    'title' => $t('Web server'),
    'value' => $software
  );
  // Use server info string, if present.
  if ($software && preg_match('![0-9]!', $software)) {
    list($server, $version) = split('[ /]', $software);
    switch ($server) {
      case 'Apache':
        if (version_compare($version, DRUPAL_MINIMUM_APACHE) < 0) {
          $requirements['webserver']['description'] = $t('Your Apache server is too old. Drupal requires at least Apache %version.', array('%version' => DRUPAL_MINIMUM_APACHE));
          $requirements['webserver']['severity'] = REQUIREMENT_ERROR;
        }
        break;

      default:
        $requirements['webserver']['description'] = $t('The web server you\'re using has not been tested with Drupal and might not work properly.');
        $requirements['webserver']['severity'] = REQUIREMENT_WARNING;
        break;
    }
  }
  else {
    $requirements['webserver']['value'] = $software ? $software : $t('Unknown');
    $requirements['webserver']['description'] = $t('Unable to determine your web server type and version. Drupal might not work properly.');
    $requirements['webserver']['severity'] = REQUIREMENT_WARNING;
  }

  // Test PHP version
  $requirements['php'] = array(
    'title' => $t('PHP'),
    'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/logs/status/php') : phpversion(),
  );
  if (version_compare(phpversion(), DRUPAL_MINIMUM_PHP) < 0) {
    $requirements['php']['description'] = $t('Your PHP installation is too old. Drupal requires at least PHP %version.', array('%version' => DRUPAL_MINIMUM_PHP));
    $requirements['php']['severity'] = REQUIREMENT_ERROR;
  }

  // Test DB version
  global $db_type;
  if (function_exists('db_status_report')) {
    $requirements += db_status_report($phase);
  }

  // Test settings.php file writability
  if ($phase == 'runtime') {
    if (!drupal_verify_install_file(conf_path() .'/settings.php', FILE_EXIST|FILE_READABLE|FILE_NOT_WRITABLE)) {
      $requirements['settings.php'] = array(
        'value' => $t('Not protected'),
        'severity' => REQUIREMENT_ERROR,
        'description' => $t('The file %file is not protected from modifications and poses a security risk. You must change the file\'s permissions to be non-writable.', array('%file' => conf_path() .'/settings.php')),
      );
    }
    else {
      $requirements['settings.php'] = array(
        'value' => $t('Protected'),
      );
    }
    $requirements['settings.php']['title'] = $t('Configuration file');
  }

  // Report cron status
  if ($phase == 'runtime') {
    $cron_last = variable_get('cron_last', NULL);

    if (is_numeric($cron_last)) {
      $requirements['cron']['value'] = $t('Last run !time ago', array('!time' => format_interval(time() - $cron_last)));
    }
    else {
      $requirements['cron'] = array(
        'description' => $t('Cron has not run. It appears cron jobs have not been setup on your system. Please check the help pages for <a href="@url">configuring cron jobs</a>.', array('@url' => 'http://drupal.org/cron')),
        'severity' => REQUIREMENT_ERROR,
        'value' => $t('Never run'),
      );
    }

    $requirements['cron']['description'] .= ' '. t('You can <a href="@cron">run cron manually</a>.', array('@cron' => url('admin/logs/status/run-cron')));

    $requirements['cron']['title'] = $t('Cron maintenance tasks');
  }

  // Test Unicode library
  include_once './includes/unicode.inc';
  $requirements = array_merge($requirements, unicode_requirements());

  return $requirements;
}


/**
 * Implementation of hook_install().
 */
function system_install() {
  switch ($GLOBALS['db_type']) {
    case 'mysql':
    case 'mysqli':
      db_query("CREATE TABLE {access} (
        mask varchar(255) NOT NULL default '',
        type varchar(255) NOT NULL default '',
        PRIMARY KEY (aid)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {authmap} (
        aid int unsigned NOT NULL auto_increment,
        uid int NOT NULL default '0',
        authname varchar(128) NOT NULL default '',
        module varchar(128) NOT NULL default '',
        PRIMARY KEY (aid),
        UNIQUE KEY authname (authname)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {blocks} (
        module varchar(64) DEFAULT '' NOT NULL,
        delta varchar(32) NOT NULL default '0',
        theme varchar(255) NOT NULL default '',
        status tinyint DEFAULT '0' NOT NULL,
        weight tinyint DEFAULT '0' NOT NULL,
        region varchar(64) DEFAULT 'left' NOT NULL,
        custom tinyint DEFAULT '0' NOT NULL,
        throttle tinyint DEFAULT '0' NOT NULL,
        visibility tinyint DEFAULT '0' NOT NULL,
        pages text DEFAULT '' NOT NULL,
        title varchar(64) DEFAULT '' NOT NULL
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {boxes} (
        body longtext,
        info varchar(128) NOT NULL default '',
        PRIMARY KEY (bid),
        UNIQUE KEY info (info)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");

      db_query("CREATE TABLE {cache} (
        cid varchar(255) NOT NULL default '',
        data longblob,
        expire int NOT NULL default '0',
        created int NOT NULL default '0',
        headers text,
        PRIMARY KEY (cid),
        INDEX expire (expire)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {cache_filter} (
        cid varchar(255) NOT NULL default '',
        data longblob,
        expire int NOT NULL default '0',
        created int NOT NULL default '0',
        headers text,
        PRIMARY KEY (cid),
        INDEX expire (expire)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {cache_menu} (
        cid varchar(255) NOT NULL default '',
        data longblob,
        expire int NOT NULL default '0',
        created int NOT NULL default '0',
        headers text,
        PRIMARY KEY (cid),
        INDEX expire (expire)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
      db_query("CREATE TABLE {cache_page} (
        cid varchar(255) NOT NULL default '',
        data longblob,
        expire int NOT NULL default '0',
        created int NOT NULL default '0',
        headers text,
        PRIMARY KEY (cid),
        INDEX expire (expire)
      ) /*!40100 DEFAULT CHARACTER SET UTF8 */ ");
Loading
Loading full blame...