mobile_switch.install in Mobile Switch 7.2
Same filename and directory in other branches
Install, update and uninstall functions for the Mobile Switch module.
File
mobile_switch.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Mobile Switch module.
*/
/**
* Implements hook_requirements().
*/
function mobile_switch_requirements($phase) {
$requirements = array();
$t = get_t();
$requirements['mobile_detect']['value'] = '';
switch ($phase) {
case 'install':
case 'update':
// Ensure Mobile Detect class installed as library.
require_once drupal_get_path('module', 'mobile_switch') . '/mobile_switch.module';
$library['version'] = FALSE;
$library_path = libraries_get_path(MOBILE_SWITCH_LIBRARY_NAME, $base_path = FALSE);
$library_uri = $library_path . '/' . MOBILE_SWITCH_LIBRARY_FILE_NAME;
if ($library_path && file_exists($library_uri)) {
$library['version'] = mobile_switch_mobile_detect_get_version($library_uri);
}
if (!$library_path || !file_exists($library_uri) || !$library['version']) {
$requirements['mobile_detect'] = array(
'severity' => REQUIREMENT_ERROR,
'description' => $t('<em>Mobile Detect PHP class</em> module: The Mobile Detect class could not be found. See README.txt for installation instructions.'),
);
}
else {
$requirements['mobile_detect'] = array(
'severity' => REQUIREMENT_OK,
'value' => $t('@version', array(
'@version' => $library['version'],
)),
);
variable_set('mobile_detect_import_library_uri', $library_uri);
}
break;
case 'runtime':
// Reports installed Mobile Detect class version.
// Reports the availability of a new class version.
$library = libraries_detect(MOBILE_SWITCH_LIBRARY_NAME);
$library_import_version = variable_get('mobile_detect_import_version', 0);
$value = $t('@version', array(
'@version' => $library['version'],
));
if ($library_import_version > 0) {
if ($library_import_version > $library['version']) {
$requirements['mobile_detect']['severity'] = REQUIREMENT_WARNING;
$value .= '<br />' . $t('New Mobile Detect PHP class, version %new_version, available. See README.txt for installation instructions.', array(
'%new_version' => $library_import_version,
));
}
}
$requirements['mobile_detect']['value'] = $value;
$requirements['mobile_detect']['title'] = $t('Mobile Detect PHP class');
break;
}
return $requirements;
}
/**
* Implements hook_uninstall().
*/
function mobile_switch_uninstall() {
$results = db_select('variable', 'v')
->fields('v', array(
'name',
))
->condition('name', '%mobile_switch_%', 'LIKE')
->execute()
->fetchAll();
foreach ($results as $result) {
variable_del($result->name);
}
}
/**
* Deleting unneeded system variables
*/
function mobile_switch_update_7200() {
variable_del('mobile_switch_display_useragent');
}
Functions
Name![]() |
Description |
---|---|
mobile_switch_requirements | Implements hook_requirements(). |
mobile_switch_uninstall | Implements hook_uninstall(). |
mobile_switch_update_7200 | Deleting unneeded system variables |