You are here

cleantalk.install in Anti Spam by CleanTalk 9.1.x

Install and uninstall functions, schema definition for the CleanTalk module.

File

cleantalk.install
View source
<?php

/**
 * @file
 * Install and uninstall functions, schema definition for the CleanTalk module.
 */

/**
 * Implements hook_schema().
 */
function cleantalk_schema() {
  $schema['cleantalk_timelabels'] = array(
    'description' => 'Timelabels for admin notification sending.',
    'fields' => array(
      'ct_key' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Notification ID.',
      ),
      'ct_value' => array(
        'type' => 'int',
        'length' => 12,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Time of last notification.',
      ),
    ),
    'primary key' => array(
      'ct_key',
    ),
  );
  $schema['cleantalk_sfw'] = array(
    'description' => 'SpamFireWall data.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'description' => "ID",
        'length' => 11,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'network' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam network.',
      ),
      'mask' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam mask.',
      ),
      'status' => array(
        'type' => 'int',
        'length' => 1,
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam status.',
      ),
      'source' => array(
        'type' => 'int',
        'length' => 1,
        'unsigned' => FALSE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'Source.',
      ),
    ),
    'indexes' => array(
      'network' => array(
        'network',
        'mask',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['cleantalk_sfw_logs'] = array(
    'description' => 'SpamFireWall logs.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ip' => array(
        'type' => 'varchar',
        'length' => 15,
        'not null' => TRUE,
        'description' => 'IP.',
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 50,
        'description' => 'status',
        'not null' => false,
        'default' => NULL,
      ),
      'all_entries' => array(
        'type' => 'int',
        'description' => 'All entries.',
      ),
      'blocked_entries' => array(
        'type' => 'int',
        'description' => 'Blocked entries.',
      ),
      'entries_timestamp' => array(
        'type' => 'int',
        'description' => 'time().',
      ),
      'ua_id' => array(
        'type' => 'int',
        'description' => 'ua_id',
        'length' => 11,
        'not null' => FALSE,
        'default' => NULL,
        'unsigned' => true,
      ),
      'ua_name' => array(
        'type' => 'varchar',
        'description' => 'ua_name',
        'length' => 1024,
        'not null' => TRUE,
      ),
      'source' => array(
        'type' => 'int',
        'length' => 1,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'network' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'first_url' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'last_url' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => FALSE,
        'default' => NULL,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['cleantalk_ac_logs'] = array(
    'description' => 'AntiCrawler logs.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ip' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'description' => 'IP.',
      ),
      'ua' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'description' => 'UA.',
      ),
      'entries' => array(
        'type' => 'int',
        'length' => 11,
        'description' => 'Entries.',
        'not null' => TRUE,
        'default' => 0,
      ),
      'interval_start' => array(
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'description' => 'interval_start.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['cleantalk_ac_ua_bl'] = array(
    'description' => 'AntiCrawler User-Agent Blacklist.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'length' => 11,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ua_template' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'ua_status' => array(
        'type' => 'int',
        'length' => 1,
        'not null' => FALSE,
      ),
    ),
    'indexes' => array(
      'network' => array(
        'ua_template',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $schema['cleantalk_sessions'] = array(
    'description' => 'Alternative cookies table',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'description' => 'id.',
      ),
      'name' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'default' => '',
        'description' => 'name.',
      ),
      'value' => array(
        'type' => 'text',
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'value.',
      ),
      'last_update' => array(
        'type' => 'datetime',
        'mysql_type' => 'datetime',
        'pgsql_type' => 'timestamp',
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'time().',
      ),
    ),
    'primary key' => array(
      'id',
      'name',
    ),
  );
  return $schema;
}

/**
 * Implements hook_uninstall().
 */
function cleantalk_uninstall() {
  \Drupal::state()
    ->delete('cleantalk_sfw_last_send_log');
  \Drupal::state()
    ->delete('cleantalk_sfw_last_check');
  \Drupal::state()
    ->delete('cleantalk_work_url');
  \Drupal::state()
    ->delete('cleantalk_server_ttl');
  \Drupal::state()
    ->delete('cleantalk_server_changed');
  \Drupal::state()
    ->delete('cleantalk_api_show_notice');
  \Drupal::state()
    ->delete('cleantalk_api_renew');
  \Drupal::state()
    ->delete('cleantalk_api_trial');
  \Drupal::state()
    ->delete('cleantalk_api_user_token');
  \Drupal::state()
    ->delete('cleantalk_api_spam_count');
  \Drupal::state()
    ->delete('cleantalk_api_moderate_ip');
  \Drupal::state()
    ->delete('cleantalk_api_show_review');
  \Drupal::state()
    ->delete('cleantalk_api_service_id');
  \Drupal::state()
    ->delete('cleantalk_api_license_trial');
  \Drupal::state()
    ->delete('cleantalk_api_account_name_ob');
  \Drupal::state()
    ->delete('cleantalk_api_ip_license');
  \Drupal::state()
    ->delete('cleantalk_show_renew_banner');
  \Drupal::state()
    ->delete('cleantalk_remote_calls');
}
function cleantalk_update_9118(&$sandbox) {
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_sfw');
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_sfw_logs');
  $cleantalk_sfw_table = array(
    'description' => 'SpamFireWall data.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'description' => "ID",
        'length' => 11,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'network' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam network.',
      ),
      'mask' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam mask.',
      ),
      'status' => array(
        'type' => 'int',
        'length' => 1,
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam status.',
      ),
    ),
    'indexes' => array(
      'network' => array(
        'network',
        'mask',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $cleantalk_sfw_logs_table = array(
    'description' => 'SpamFireWall logs.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ip' => array(
        'type' => 'varchar',
        'length' => 15,
        'not null' => TRUE,
        'description' => 'IP.',
      ),
      'all_entries' => array(
        'type' => 'int',
        'description' => 'All entries.',
      ),
      'blocked_entries' => array(
        'type' => 'int',
        'description' => 'Blocked entries.',
      ),
      'entries_timestamp' => array(
        'type' => 'int',
        'description' => 'time().',
      ),
      'ua_id' => array(
        'type' => 'int',
        'description' => 'ua_id',
        'length' => 11,
        'not null' => FALSE,
        'default' => NULL,
        'unsigned' => true,
      ),
      'ua_name' => array(
        'type' => 'varchar',
        'description' => 'ua_name',
        'length' => 1024,
        'not null' => TRUE,
      ),
      'status' => array(
        'type' => 'varchar',
        'description' => 'status',
        'length' => 50,
        'not null' => false,
        'default' => NULL,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_sfw', $cleantalk_sfw_table);
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_sfw_logs', $cleantalk_sfw_logs_table);
}
function cleantalk_update_91115(&$sandbox) {
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_sfw');
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_sfw_logs');
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_ac_logs');
  \Drupal::service('database')
    ->schema()
    ->dropTable('cleantalk_ac_ua_bl');
  $cleantalk_sfw_table_schema = array(
    'description' => 'SpamFireWall data.',
    'fields' => array(
      'id' => array(
        'type' => 'serial',
        'description' => "ID",
        'length' => 11,
        'not null' => TRUE,
        'unsigned' => TRUE,
      ),
      'network' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam network.',
      ),
      'mask' => array(
        'type' => 'int',
        'length' => 11,
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam mask.',
      ),
      'status' => array(
        'type' => 'int',
        'length' => 1,
        'unsigned' => FALSE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Spam status.',
      ),
      'source' => array(
        'type' => 'int',
        'length' => 1,
        'unsigned' => FALSE,
        'not null' => FALSE,
        'default' => NULL,
        'description' => 'Source.',
      ),
    ),
    'indexes' => array(
      'network' => array(
        'network',
        'mask',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $cleantalk_sfw_logs_table_schema = array(
    'description' => 'SpamFireWall logs.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ip' => array(
        'type' => 'varchar',
        'length' => 15,
        'not null' => TRUE,
        'description' => 'IP.',
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 50,
        'description' => 'status',
        'not null' => false,
        'default' => NULL,
      ),
      'all_entries' => array(
        'type' => 'int',
        'description' => 'All entries.',
      ),
      'blocked_entries' => array(
        'type' => 'int',
        'description' => 'Blocked entries.',
      ),
      'entries_timestamp' => array(
        'type' => 'int',
        'description' => 'time().',
      ),
      'ua_id' => array(
        'type' => 'int',
        'description' => 'ua_id',
        'length' => 11,
        'not null' => FALSE,
        'default' => NULL,
        'unsigned' => true,
      ),
      'ua_name' => array(
        'type' => 'varchar',
        'description' => 'ua_name',
        'length' => 1024,
        'not null' => TRUE,
      ),
      'source' => array(
        'type' => 'int',
        'length' => 1,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'network' => array(
        'type' => 'varchar',
        'length' => 20,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'first_url' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => FALSE,
        'default' => NULL,
      ),
      'last_url' => array(
        'type' => 'varchar',
        'length' => 100,
        'not null' => FALSE,
        'default' => NULL,
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $cleantalk_ac_logs_table_schema = array(
    'description' => 'AntiCrawler logs.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ip' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'description' => 'IP.',
      ),
      'ua' => array(
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'description' => 'UA.',
      ),
      'entries' => array(
        'type' => 'int',
        'length' => 11,
        'description' => 'Entries.',
        'not null' => TRUE,
        'default' => 0,
      ),
      'interval_start' => array(
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
        'description' => 'interval_start.',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  $cleantalk_ac_ua_bl_table_schema = array(
    'description' => 'AntiCrawler User-Agent Blacklist.',
    'fields' => array(
      'id' => array(
        'type' => 'int',
        'length' => 11,
        'not null' => true,
        'description' => 'ID.',
      ),
      'ua_template' => array(
        'type' => 'varchar',
        'length' => 255,
        'not null' => FALSE,
      ),
      'ua_status' => array(
        'type' => 'int',
        'length' => 1,
        'not null' => FALSE,
      ),
    ),
    'indexes' => array(
      'network' => array(
        'ua_template',
      ),
    ),
    'primary key' => array(
      'id',
    ),
  );
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_sfw', $cleantalk_sfw_table_schema);
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_sfw_logs', $cleantalk_sfw_logs_table_schema);
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_ac_logs', $cleantalk_ac_logs_table_schema);
  \Drupal::service('database')
    ->schema()
    ->createTable('cleantalk_ac_ua_bl', $cleantalk_ac_ua_bl_table_schema);
}