hierarchical_select.install in Hierarchical Select 7.3
Same filename and directory in other branches
Install, update and uninstall functions for the Hierarchical Select module.
File
hierarchical_select.installView source
<?php
/**
* @file
* Install, update and uninstall functions for the Hierarchical Select module.
*/
/**
* Implements hook_uninstall().
*/
function hierarchical_select_uninstall() {
db_delete('variable')
->condition('name', 'hs_config_%', 'LIKE')
->execute();
db_delete('variable')
->condition('name', 'hierarchical_select_%', 'LIKE')
->execute();
}
//----------------------------------------------------------------------------
// Updates.
/**
* Update Hierarchical Select to Drupal 7. Basically remove a lot of cruft.
*/
function hierarchical_select_update_7001() {
// Drop Hierarchical Select's cache table, which is now obsolete.
db_drop_table('cache_hierarchical_select');
// Undo Hierarchical Select module weight changes, because they're no longer
// necessary.
db_update('system')
->fields(array(
'weight' => 0,
))
->condition('name', 'hierarchical_select')
->execute();
}
/**
* Update Hierarchical Select config to support improved "entity count".
*/
function hierarchical_select_update_7002() {
module_load_include('inc', 'hierarchical_select', 'includes/common');
// Retrieve all information items.
$info_items = array();
foreach (module_implements('hierarchical_select_config_info') as $module) {
$info_items = array_merge_recursive($info_items, module_invoke($module, 'hierarchical_select_config_info'));
}
foreach ($info_items as $info_item) {
// Load config.
$config = hierarchical_select_common_config_get($info_item['config_id']);
// Move old settings to new location.
$config['entity_count'] = array(
'enabled' => $config['entity_count'],
'require_entity' => $config['require_entity'],
);
// Remove old setting.
unset($config['require_entity']);
// Add entity types settings.
$entity_info = entity_get_info();
foreach ($entity_info as $entity => $entity_info) {
if (!empty($entity_info['bundles']) && $entity_info['fieldable'] === TRUE) {
foreach ($entity_info['bundles'] as $bundle => $bundle_info) {
if ($entity == 'node') {
$config['entity_count']['settings']['entity_types'][$entity]['count_' . $entity][$bundle] = $bundle;
}
else {
$config['entity_count']['settings']['entity_types'][$entity]['count_' . $entity][$bundle] = 0;
}
}
}
}
// Save new config.
hierarchical_select_common_config_set($info_item['config_id'], $config);
}
}
/**
* Update system variable keys. Issue #1368916.
*/
function hierarchical_select_update_7003() {
module_load_include('inc', 'hierarchical_select', 'includes/common');
// Retrieve our keys.
$result = db_select('variable', 'v')
->fields('v', array(
'name',
))
->condition('v.name', 'hs_config%', 'LIKE')
->execute()
->fetchAll();
foreach ($result as $id => $var) {
$key = $var->name;
// Get our current value for the key.
$val = variable_get($key, array());
// Sanitize our key.
$new_key = hierarchical_select_common_sanitize_var($key);
// Write the value to the new key.
variable_set($new_key, $val);
// Delete the previous variable.
variable_del($key);
}
}
Functions
Name | Description |
---|---|
hierarchical_select_uninstall | Implements hook_uninstall(). |
hierarchical_select_update_7001 | Update Hierarchical Select to Drupal 7. Basically remove a lot of cruft. |
hierarchical_select_update_7002 | Update Hierarchical Select config to support improved "entity count". |
hierarchical_select_update_7003 | Update system variable keys. Issue #1368916. |