purge_users-8.x-2.0/purge_users.install

purge_users.install
<?php

/**
 * @file
 * Install, update and uninstall functions for the module.
 */

declare(strict_types=1);

use Drupal\Core\Database\Database;

/**
 * Implements hook_schema().
 */
function purge_users_schema() {
  $schema['purge_users_notifications'] = [
    'description' => 'Logs notification emails from purge_users, to prevent sending them more than once.',
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Auto-increment id, to distinguish different entries for the same user.',
      ],
      'uid' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => "The user id.",
      ],
      'type' => [
        'description' => "The type of email notification: Either 'notification_users' or 'purge_users'.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'timestamp' => [
        'description' => 'Timestamp when the notification was sent.',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['id'],
    'indexes' => [
      'uid' => ['uid'],
    ],
  ];
  return $schema;
}

/**
 * Create the new 'purge_users_notifications' table.
 */
function purge_users_update_8301(): void {
  // See https://www.drupal.org/docs/drupal-apis/update-api/updating-database-schema-andor-data-in-drupal-8#s-adding-a-new-table.
  $spec = [
    'description' => 'Logs notification emails from purge_users, to prevent sending them more than once.',
    'fields' => [
      'id' => [
        'type' => 'serial',
        'not null' => TRUE,
        'description' => 'Auto-increment id, to distinguish different entries for the same user.',
      ],
      'uid' => [
        'type' => 'int',
        'not null' => TRUE,
        'description' => "The user id.",
      ],
      'type' => [
        'description' => "The type of email notification: Either 'notification_users' or 'purge_users'.",
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
      ],
      'timestamp' => [
        'description' => 'Timestamp when the notification was sent.',
        'type' => 'int',
        'length' => 11,
        'not null' => TRUE,
      ],
    ],
    'primary key' => ['id'],
    'indexes' => [
      'uid' => ['uid'],
    ],
  ];
  $schema = Database::getConnection()->schema();
  $schema->createTable('purge_users_notifications', $spec);
}

/**
 * Convert purge user values to integer.
 */
function purge_users_update_9001() {
  $config = \Drupal::configFactory()->getEditable('purge_users.settings');

  $neverLastLoginIntegerValue = (integer) $config->get('user_never_lastlogin_value');
  $config->set('user_never_lastlogin_value', $neverLastLoginIntegerValue);

  $lastLoginIntegerValue = (integer) $config->get('user_lastlogin_value');
  $config->set('user_lastlogin_value', $lastLoginIntegerValue);

  $inactiveIntegerValue = (integer) $config->get('user_inactive_value');
  $config->set('user_inactive_value', $inactiveIntegerValue);

  $blockedIntegerValue = (integer) $config->get('user_blocked_value');
  $config->set('user_blocked_value', $blockedIntegerValue);
}

/**
 * Add missing langcode in purge_users.settings.
 */
function purge_users_update_9002() {
  \Drupal::configFactory()->getEditable('purge_users.settings')
    ->set('langcode', 'en')
    ->save();
}

Главная | Обратная связь

drupal hosting | друпал хостинг | it patrol .inc