You are here

user_email_verification.install in User email verification 8

Same filename and directory in other branches
  1. 7 user_email_verification.install

The module installation functions.

File

user_email_verification.install
View source
<?php

/**
 * @file
 * The module installation functions.
 */

/**
 * Implements hook_install().
 */
function user_email_verification_install() {

  // TODO: ReDo it with batch (if many users - timeout on install).
  $database = \Drupal::database();
  $uids = $database
    ->select('users', 'u')
    ->fields('u', [
    'uid',
  ])
    ->condition('uid', 0, '>')
    ->execute()
    ->fetchAllKeyed(0, 0);
  if ($uids) {
    $verified = \Drupal::time()
      ->getRequestTime();
    $query = $database
      ->insert('user_email_verification')
      ->fields([
      'uid',
      'verified',
    ]);
    foreach ($uids as $uid) {
      $query
        ->values([
        'uid' => $uid,
        'verified' => $verified,
      ]);
    }
    $query
      ->execute();
  }
}

/**
 * Implements hook_schema().
 */
function user_email_verification_schema() {
  $schema['user_email_verification'] = [
    'description' => 'The base table for email verification for specific user.',
    'fields' => [
      'uid' => [
        'description' => 'The user id from users table.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ],
      'verified' => [
        'description' => 'Email verified timestamp & flag.',
        'type' => 'int',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ],
      'last_reminder' => [
        'type' => 'int',
        'description' => 'Last notification timestamp.',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ],
      'reminders' => [
        'type' => 'int',
        'description' => 'Number of reminders sent.',
        'not null' => TRUE,
        'unsigned' => TRUE,
        'default' => 0,
      ],
    ],
    'indexes' => [
      'inx_uid' => [
        'uid',
      ],
      'inx_verified' => [
        'verified',
      ],
      'inx_last_reminder' => [
        'last_reminder',
      ],
    ],
    'primary key' => [
      'uid',
    ],
  ];
  return $schema;
}