You are here

cleantalk.install in Anti Spam by CleanTalk 8.3

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(
      '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',
      ),
    ),
  );
  $schema['cleantalk_sfw_logs'] = array(
    'description' => 'SpamFireWall logs.',
    'fields' => array(
      'ip' => array(
        'type' => 'varchar',
        'length' => 15,
        'not null' => TRUE,
        'default' => '',
        '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().',
      ),
    ),
    'primary key' => array(
      'ip',
    ),
  );
  $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',
    ),
  );
  \Drupal::state()
    ->set('cleantalk_remote_calls', array(
    'close_renew_banner' => array(
      'last_call' => 0,
    ),
    'sfw_update' => array(
      'last_call' => 0,
      'cooldown' => 600,
    ),
    'sfw_update__write_base' => array(
      'last_call' => 0,
    ),
    'sfw_send_logs' => array(
      'last_call' => 0,
    ),
    'update_plugin' => array(
      'last_call' => 0,
    ),
  ));
  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_8138(&$sandbox) {
  $status_field = [
    'type' => 'int',
    'description' => "Spam status",
    'length' => 1,
    'not null' => TRUE,
    'default' => 0,
    'unsigned' => FALSE,
  ];
  \Drupal::service('database')
    ->schema()
    ->addField('cleantalk_sfw', 'status', $status_field);
}
function cleantalk_update_8140(&$sandbox) {
  \Drupal::state()
    ->set('cleantalk_remote_calls', array(
    'close_renew_banner' => array(
      'last_call' => 0,
    ),
    'sfw_update' => array(
      'last_call' => 0,
      'cooldown' => 600,
    ),
    'sfw_update__write_base' => array(
      'last_call' => 0,
    ),
    'sfw_send_logs' => array(
      'last_call' => 0,
    ),
    'update_plugin' => array(
      'last_call' => 0,
    ),
  ));
}