ip_geoloc.install in IP Geolocation Views & Maps 8
Same filename and directory in other branches
Install and uninstall hooks for IP Geolocation Views & Maps.
File
ip_geoloc.installView source
<?php
/**
* @file
* Install and uninstall hooks for IP Geolocation Views & Maps.
*/
/**
* Implements hook_requirements().
*
* $phase typically is one of 'install', 'runtime', 'update'.
*/
// TODO migrate hook_requirements function
/*
function ip_geoloc_requirements($phase) {
$config = \Drupal::config('ip_geoloc.settings');
$requirements = array();
// Avoid 'undefined function: ip_geoloc_get_css_library_path' during 'install'
// and some warnings not relevant while executing an 'update'.
if ($phase != 'runtime') {
return $requirements;
}
$t = get_t();
$geolocation_methods = array();
if ($config->get('ip_geoloc_google_to_reverse_geocode')?$config->get('ip_geoloc_google_to_reverse_geocode'): TRUE) {
$geolocation_methods[] = $t('Google Maps reverse-geocode');
}
if (\Drupal::state()->get('ip_geoloc_smart_ip_as_backup', TRUE)) {
if (\Drupal::moduleHandler()->moduleExists('smart_ip')) {
$geolocation_methods[] = 'Smart IP';
}
else {
$requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_WARNING;
$requirements['ip_geoloc_lbs']['description'] = $t('Smart IP is configured as a backup in case the Google Maps reverse-geocode fails. However the Smart IP module is not enabled.');
}
}
elseif (\Drupal::moduleHandler()->moduleExists('geoip')) {
$geolocation_methods[] = 'GeoIP API';
}
$geolocation_methods = array_merge($geolocation_methods, \Drupal::moduleHandler()->getImplementations('get_ip_geolocation_alter'));
$requirements['ip_geoloc_lbs']['title'] = $t('IP Geolocation Views & Maps data collection methods employed');
$requirements['ip_geoloc_lbs']['value'] = implode(', ', $geolocation_methods);
if (empty($geolocation_methods)) {
$warning = $t('You currently have no data collection methods enabled. Therefore no new address information can be added to the IP geolocation database.');
if (empty($requirements['ip_geoloc']['description'])) {
$requirements['ip_geoloc_lbs']['severity'] = REQUIREMENT_WARNING;
$requirements['ip_geoloc_lbs']['description'] = $warning;
}
else {
$requirements['ip_geoloc_lbs']['description'] .= ' ' . $warning;
}
}
$css_file = FALSE;
$requirements['ip_geoloc_font_awesome']['title'] = $t('IP Geolocation Views & Maps <em>Font Awesome</em> extension');
if ($css_path = ip_geoloc_get_ccs_library_path('font-awesome')) {
$css_file = "$css_path/font-awesome.min.css";
}
if (file_exists($css_file)) {
$requirements['ip_geoloc_font_awesome']['value'] = $t('Installed');
$requirements['ip_geoloc_font_awesome']['severity'] = REQUIREMENT_OK;
}
else {
$s1 = $t('%dir found, but required .css file not present: %file', array(
'%dir' => $css_path, '%file' => $css_file)
);
$s2 = $t('The optional <em>Font Awesome</em> directory was not found, so you will not be able to superimpose any Font Awesome symbols on top of your markers');
$requirements['ip_geoloc_font_awesome']['value'] = $css_path ? $s1 : $s2;
$requirements['ip_geoloc_font_awesome']['severity'] = REQUIREMENT_WARNING;
}
return $requirements;
}
*/
/**
* Implements hook_uninstall().
*/
function ip_geoloc_uninstall() {
// Delete all ip_geoloc_* variables at once.
$connection = \Drupal::database();
$connection
->delete('config')
->condition('name', 'ip_geoloc_%%', 'LIKE')
->execute();
}
/**
* Implements hook_schema().
*
* Smart IP module provides:
* IP address
* Latitude/Longitude
* Country
* Country Code
* Region
* Region Code (usually empty for Australia)
* City
* ZIP (which we store under Postal Code)
*
* GeoIP City provides:
* TBA
*
* Googlee provides:
* TBA
*
* Note: some of the varchar should be varbinary, see drupal.org/node/1793674
*/
function ip_geoloc_schema() {
$schema['ip_geoloc'] = [
'description' => 'Store visitor IP addresses and geolocation information',
'fields' => [
'id' => [
'description' => 'Unique id',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
],
'ip_address' => [
'description' => 'IP address',
'type' => 'varchar',
'length' => '64',
'not null' => TRUE,
],
'latitude' => [
'description' => 'Latitude',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
],
'longitude' => [
'description' => 'Longitude',
'type' => 'float',
'size' => 'big',
'not null' => FALSE,
],
'country' => [
'description' => 'Country',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'country_code' => [
'description' => 'ISO 3166 2-Character Country Code',
'type' => 'varchar',
'length' => 3,
'not null' => FALSE,
],
'region' => [
'description' => 'Region',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'region_code' => [
'description' => '2-Character Region Code',
'type' => 'varchar',
'length' => 3,
'not null' => FALSE,
],
'city' => [
'description' => 'City',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'postal_code' => [
'description' => 'Post code',
'type' => 'varchar',
'length' => 12,
'not null' => FALSE,
],
'locality' => [
'description' => 'Suburb',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'route' => [
'description' => 'Street',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'street_number' => [
'description' => 'Street number',
'type' => 'varchar',
'length' => 32,
'not null' => FALSE,
],
'administrative_area_level_1' => [
'description' => 'State or province',
'type' => 'varchar',
'length' => 64,
'not null' => FALSE,
],
'formatted_address' => [
'description' => 'Address',
'type' => 'varchar',
'length' => 128,
'not null' => FALSE,
],
],
'primary key' => [
'id',
],
'indexes' => [
'ip_address' => [
'ip_address',
],
],
];
return $schema;
}
Functions
Name | Description |
---|---|
ip_geoloc_schema | Implements hook_schema(). |
ip_geoloc_uninstall | Implements hook_uninstall(). |