191 lines
5.8 KiB
Plaintext
191 lines
5.8 KiB
Plaintext
<?php
|
|
|
|
/**
|
|
* @file
|
|
* Install, update, and uninstall functions for the Synonyms module.
|
|
*/
|
|
|
|
/**
|
|
* Implements hook_schema().
|
|
*/
|
|
function synonyms_schema() {
|
|
$schema = array();
|
|
|
|
$schema['synonyms_settings'] = array(
|
|
'description' => 'Stores synonyms settings for all the entities and fields. Only enabled synonyms behaviors are included in this table.',
|
|
'fields' => array(
|
|
'instance_id' => array(
|
|
'description' => 'Reference to {field_config_instance}.id of the instance, whose synonyms settings are stored in this row.',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'unsigned' => TRUE,
|
|
),
|
|
'behavior' => array(
|
|
'description' => 'Name of the synonyms behavior (ctools plugin), whose settings are stored in this row.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
),
|
|
'settings_serialized' => array(
|
|
'description' => 'Settings of the specified synonyms behavior for the specified field instance.',
|
|
'type' => 'text',
|
|
'serialize' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'unique keys' => array(
|
|
'instance_behavior' => array('instance_id', 'behavior'),
|
|
),
|
|
'foreign keys' => array(
|
|
'field_config_instance' => array(
|
|
'table' => 'field_config_instance',
|
|
'columns' => array('instance_id' => 'id'),
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'behavior' => array('behavior'),
|
|
),
|
|
);
|
|
|
|
return $schema;
|
|
}
|
|
|
|
/**
|
|
* Implements hook_uninstall().
|
|
*/
|
|
function synonyms_uninstall() {
|
|
// Cleaning all configure variables.
|
|
$results = db_select('variable', 'var')
|
|
->fields('var', array('name'))
|
|
->condition('var.name', db_like('synonyms_') . '%', 'LIKE')
|
|
->execute();
|
|
foreach ($results as $var) {
|
|
variable_del($var->name);
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Implements hook_update_N().
|
|
*
|
|
* Update to version 7.x-1.1 of Synonyms module.
|
|
*/
|
|
function synonyms_update_7101() {
|
|
$result = db_select('variable', 'var')
|
|
->fields('var', array('name'))
|
|
->condition('var.name', db_like('synonyms_settings_') . '%', 'LIKE')
|
|
->execute();
|
|
foreach ($result as $var) {
|
|
$settings = variable_get($var->name);
|
|
// Term merging has been deprecated in favor of Term Merge module.
|
|
unset($settings['term_merge']);
|
|
// Enabled synonyms now stored as field names, since the field independency
|
|
// has been introduced. See issue http://drupal.org/node/1850748.
|
|
drupal_load('module', 'synonyms');
|
|
$settings['synonyms'] = $settings['synonyms'] ? array('synonyms_synonyms') : array();
|
|
variable_set($var->name, $settings);
|
|
}
|
|
return t('Updated settings of synonyms.');
|
|
}
|
|
|
|
/**
|
|
* Multiple adjustments in the internal structures of the module.
|
|
*
|
|
* Unlock the 'synonyms_synonyms' field, because Synonyms module no longer uses
|
|
* it.
|
|
* Create 'synonyms_settings' table.
|
|
* Enable 'synonyms_search' module if the core Search module is enabled.
|
|
* Enable all available behaviors on all "source of synonyms" fields with the
|
|
* default settings.
|
|
*/
|
|
function synonyms_update_7102() {
|
|
$field = field_info_field('synonyms_synonyms');
|
|
if ($field !== NULL) {
|
|
$field['locked'] = FALSE;
|
|
field_update_field($field);
|
|
}
|
|
|
|
db_create_table('synonyms_settings', array(
|
|
'description' => 'Stores synonyms settings for all the entities and fields. Only enabled synonyms behaviors are included in this table.',
|
|
'fields' => array(
|
|
'instance_id' => array(
|
|
'description' => 'Reference to {field_config_instance}.id of the instance, whose synonyms settings are stored in this row.',
|
|
'type' => 'int',
|
|
'not null' => TRUE,
|
|
'unsigned' => TRUE,
|
|
),
|
|
'behavior' => array(
|
|
'description' => 'Name of the synonyms behavior (ctools plugin), whose settings are stored in this row.',
|
|
'type' => 'varchar',
|
|
'length' => 255,
|
|
'not null' => TRUE,
|
|
),
|
|
'settings_serialized' => array(
|
|
'description' => 'Settings of the specified synonyms behavior for the specified field instance.',
|
|
'type' => 'text',
|
|
'serialize' => TRUE,
|
|
'not null' => TRUE,
|
|
),
|
|
),
|
|
'unique keys' => array(
|
|
'instance_behavior' => array('instance_id', 'behavior'),
|
|
),
|
|
'foreign keys' => array(
|
|
'field_config_instance' => array(
|
|
'table' => 'field_config_instance',
|
|
'columns' => array('instance_id' => 'id'),
|
|
),
|
|
),
|
|
'indexes' => array(
|
|
'behavior' => array('behavior'),
|
|
),
|
|
));
|
|
|
|
if (module_exists('search')) {
|
|
module_enable(array('synonyms_search'));
|
|
}
|
|
|
|
$vars = db_select('variable', 'v')
|
|
->fields('v', array('name'))
|
|
->condition('name', db_like('synonyms_settings_') . '%', 'LIKE')
|
|
->execute();
|
|
foreach ($vars as $row) {
|
|
$var = variable_get($row->name);
|
|
$vid = substr($row->name, drupal_strlen('synonyms_settings_'));
|
|
$vocabulary = taxonomy_vocabulary_load($vid);
|
|
if ($vocabulary) {
|
|
$bundle = $vocabulary->machine_name;
|
|
foreach ($var['synonyms'] as $field) {
|
|
$instance = field_info_instance('taxonomy_term', $field, $bundle);
|
|
foreach (synonyms_behaviors() as $behavior) {
|
|
switch ($behavior['name']) {
|
|
case 'synonyms':
|
|
case 'search':
|
|
default:
|
|
$settings = array();
|
|
break;
|
|
|
|
case 'select':
|
|
$settings = array(
|
|
'wording' => '@synonym',
|
|
);
|
|
break;
|
|
|
|
case 'autocomplete':
|
|
$settings = array(
|
|
'wording' => '@synonym, synonym of @term',
|
|
);
|
|
break;
|
|
}
|
|
$settings = array(
|
|
'instance_id' => $instance['id'],
|
|
'behavior' => $behavior['name'],
|
|
'settings' => $settings,
|
|
);
|
|
synonyms_behavior_settings_save($settings);
|
|
}
|
|
}
|
|
}
|
|
variable_del($row->name);
|
|
}
|
|
}
|