You are here

captcha_questions_dblog.install in Captcha Questions 8

Same filename and directory in other branches
  1. 7 captcha_questions_dblog/captcha_questions_dblog.install

Install and uninstall functions for the Captcha questions dblog module.

File

captcha_questions_dblog/captcha_questions_dblog.install
View source
<?php

/**
 * @file
 * Install and uninstall functions for the Captcha questions dblog module.
 */
use Drupal\Core\Url;
use Drupal\Core\Link;

/**
 * Implements hook_schema().
 */
function captcha_questions_dblog_schema() {
  $schema['captcha_questions_dblog'] = [
    'description' => 'Stores failed form submissions.',
    'fields' => [
      'dblogid' => [
        'description' => 'Primary Key: unique ID for failed form submissions.',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'timestamp' => [
        'description' => 'A Unix timestamp indicating when the submit failed.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
      'ip' => [
        'description' => 'IP address',
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'default' => '',
      ],
      'form_id' => [
        'description' => 'The form_id of the form',
        'type' => 'varchar',
        'length' => 40,
        'not null' => TRUE,
        'default' => '',
      ],
      'question_asked' => [
        'description' => 'The question the form submit failed on',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'answer_given' => [
        'description' => 'The answer that was wrong',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
      'answer_correct' => [
        'description' => 'The correct answer',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE,
        'default' => '',
      ],
    ],
    'indexes' => [
      'dblogid' => [
        'dblogid',
      ],
      'timestamp' => [
        'timestamp',
      ],
    ],
  ];
  return $schema;
}

/**
 * Implements hook_install().
 */
function captcha_questions_dblog_install() {
  $pass_link = Link::fromTextAndUrl(t('Configure'), Url::fromRoute('captcha_questions_settings'));
  \Drupal::messenger()
    ->addMessage(t("Captcha questions database logging installed successfully. @link what forms to protect.", [
    '@link' => $pass_link,
  ]));
}