You are here

smart_ip.install in Smart IP 8.3

Install, update and uninstall functions for the image module.

File

smart_ip.install
View source
<?php

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

/**
 * Implements hook_uninstall().
 */
function smart_ip_uninstall() {

  /** @var \Drupal\user\UserData $userData */
  $userData = \Drupal::service('user.data');

  // Delete all the Smart IP location in users' user_data
  $userData
    ->delete('smart_ip');

  // Remove all stored states
  \Drupal::state()
    ->deleteMultiple([
    'smart_ip.request_db_error_source_id',
    'smart_ip.request_db_error_message',
  ]);
}

/**
 * Update the admin debug mode to role based debug mode.
 */
function smart_ip_update_8301() {
  $config = \Drupal::configFactory()
    ->getEditable('smart_ip.settings');
  if ($config
    ->get('debug_mode')) {
    $debugIp = $config
      ->get('debug_mode_ip');
    $roles = \Drupal\user\Entity\Role::loadMultiple();
    $rolesDebug = [];
    $rolesDebugIp = [];

    /** @var \Drupal\user\Entity\Role $role */
    foreach ($roles as $roleId => $role) {
      if ($role
        ->hasPermission('administer smart_ip')) {
        $rolesDebug[$roleId] = $roleId;
      }
      $rolesDebugIp[$roleId] = $debugIp;
    }
    $config
      ->set('roles_in_debug_mode', $rolesDebug)
      ->set('roles_in_debug_mode_ip', $rolesDebugIp);
  }
  $config
    ->clear('debug_mode')
    ->clear('debug_mode_ip')
    ->save();
}

Functions

Namesort descending Description
smart_ip_uninstall Implements hook_uninstall().
smart_ip_update_8301 Update the admin debug mode to role based debug mode.