You are here

user_expire.install in User Expire 8

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

Install and update functions for the User expire module.

File

user_expire.install
View source
<?php

/**
 * @file
 * Install and update functions for the User expire module.
 */

/**
 * Implements hook_schema().
 */
function user_expire_schema() {
  $schema['user_expire'] = [
    'description' => 'The tracking table for user expirations.',
    'fields' => [
      'uid' => [
        'description' => 'The primary identifier for a user.',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
      ],
      'expiration' => [
        'description' => 'The Unix timestamp when the user will be disabled.',
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
      ],
    ],
    'foreign keys' => [
      'uid' => [
        'table' => 'users_field_data',
        'columns' => [
          'uid' => 'uid',
        ],
      ],
    ],
    'primary key' => [
      'uid',
    ],
  ];
  return $schema;
}

/**
 * Remove last_run from config.
 */
function user_expire_update_8001() {
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('user_expire.settings');
  $config
    ->clear('last_run');
  $config
    ->save();
}

/**
 * Convert user_expire_roles to config.
 */
function user_expire_update_8002() {
  $rules = \Drupal::database()
    ->select('user_expire_roles', 'uer')
    ->fields('uer', [
    'rid',
    'inactivity_period',
  ])
    ->execute()
    ->fetchAllAssoc('rid');

  // Convert structure.
  foreach ($rules as &$rule) {
    $rule = (int) $rule->inactivity_period;
  }
  $config_factory = \Drupal::configFactory();
  $config = $config_factory
    ->getEditable('user_expire.settings');
  $config
    ->set('user_expire_roles', $rules);
  $config
    ->save();
  \Drupal::database()
    ->schema()
    ->dropTable('user_expire_roles');
}

Functions

Namesort descending Description
user_expire_schema Implements hook_schema().
user_expire_update_8001 Remove last_run from config.
user_expire_update_8002 Convert user_expire_roles to config.