<?php

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

/**
 * Implements hook_enable().
 */
function security_review_enable() {
  drupal_set_message(t('Security Review module enabled. You should first set the module access permissions at !link. Be sure to grant permissions to trusted users only as this module can show senstive site information.', array('!link' => l('admin/people/permissions', 'admin/people/permissions'))));
}

/**
 * Implements hook_schema().
 */
function security_review_schema() {
  $schema['security_review'] = array(
    'fields' => array(
      'namespace' => array(
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => '',
      ),
      'reviewcheck' => array(
        'type' => 'varchar',
        'length' => 160,
        'not null' => TRUE,
        'default' => '',
      ),
      'result' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'lastrun' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'skip' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'skiptime' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ),
      'skipuid' => array(
        'type' => 'int',
        'default' => NULL
      ),
    ),
    'primary key' => array('namespace', 'reviewcheck'),
  );

  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function security_review_uninstall() {
  variable_del('security_review_untrusted_roles');
  variable_del('security_review_log');
}

/**
 * Empty Security Review check result table for a fresh start on Drupal 7.
 */
function security_review_update_7000(&$sandbox) {
  db_truncate('security_review')->execute();
  return t('Security Review table truncated.');
}