You are here

function smart_ip_update_8301 in Smart IP 8.3

Same name and namespace in other branches
  1. 8.4 smart_ip.install \smart_ip_update_8301()

Update the admin debug mode to role based debug mode.

File

./smart_ip.install, line 27
Install, update and uninstall functions for the image module.

Code

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();
}