You are here

smart_ip_ip2location_bin_db.install in Smart IP 8.3

File

modules/smart_ip_ip2location_bin_db/smart_ip_ip2location_bin_db.install
View source
<?php

use Drupal\Core\Link;
use Drupal\Core\Url;

/**
 * Implements hook_requirements().
 *
 * @param $phase
 * @return array
 */
function smart_ip_ip2location_bin_db_requirements($phase) {
  $requirements = [];
  if ($phase == 'install') {
    if (!class_exists('\\IP2Location\\Database')) {
      $requirements['ip2location_library'] = [
        'description' => t('Smart IP IP2Location binary database module requires the
          ip2location/ip2location-php library. To setup, follow this @guide', [
          '@guide' => Link::fromTextAndUrl(t('guide'), Url::fromUri('https://www.webfoobar.com/node/68'))
            ->toString(),
        ]),
        'severity' => REQUIREMENT_ERROR,
      ];
    }
  }
  return $requirements;
}

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

  // Remove all stored states
  \Drupal::state()
    ->deleteMultiple([
    'smart_ip_ip2location_bin_db.last_update_time',
    'smart_ip_ip2location_bin_db.current_ip_version_queue',
  ]);
}

/**
 * Merge the two separate custom paths for IPV4 and IPV6 binary files into one
 * path. Change the default value of db_auto_update to FALSE.
 */
function smart_ip_ip2location_bin_db_update_8301() {
  $configName = \Drupal\smart_ip_ip2location_bin_db\EventSubscriber\SmartIpEventSubscriber::configName();
  $config = \Drupal::configFactory()
    ->getEditable($configName);
  $filesystem = \Drupal::service('file_system');
  $path = $filesystem
    ->dirname($config
    ->get('ip2location_bin_db_ipv4_custom_path'));
  $config
    ->set('db_auto_update', '0')
    ->set('bin_file_custom_path', $path)
    ->clear('ip2location_bin_db_ipv4_custom_path')
    ->clear('ip2location_bin_db_ipv6_custom_path')
    ->save();
}

Functions

Namesort descending Description
smart_ip_ip2location_bin_db_requirements Implements hook_requirements().
smart_ip_ip2location_bin_db_uninstall Implements hook_uninstall().
smart_ip_ip2location_bin_db_update_8301 Merge the two separate custom paths for IPV4 and IPV6 binary files into one path. Change the default value of db_auto_update to FALSE.