similar.install in Similar Entries 7.2
Same filename and directory in other branches
Installation functions for Similar entries module.
File
similar.installView source
<?php
/**
* @file
* Installation functions for Similar entries module.
*/
/**
* Implements hook_install().
*
* Add FULLTEXT index to MySQL MyISAM tables.
* Module does not support InnoDB or PostgreSQL, so no changes for it.
* Individual field tables are indexed in hook_cron() if they exist.
* It is called here at install to perform the initial creation of indices.
* require_once is used because module_load_include() is not accessible
* during hook_install(). See #1257940 for more information.
*/
function similar_install() {
include_once dirname(__FILE__) . '/similar.module';
db_query('ALTER TABLE {node} ENGINE = MYISAM');
db_query('ALTER TABLE {node} ADD FULLTEXT `similar` (`title`)');
if (db_table_exists('field_data_body')) {
db_query('ALTER TABLE {field_data_body} ENGINE = MYISAM');
db_query('ALTER TABLE {field_data_body} ADD FULLTEXT `similar` (`body_value`)');
}
similar_index_fields();
}
/**
* Implements hook_uninstall().
*/
function similar_uninstall() {
db_drop_index('node', 'similar');
if (db_table_exists('field_data_body') && db_index_exists('field_data_body', 'similar')) {
db_drop_index('field_data_body', 'similar');
}
foreach (variable_get('similar_indices', array()) as $field => $info) {
if (db_table_exists($info['table']) && db_index_exists($info['table'], $info['index'])) {
db_drop_index($info['table'], $info['index']);
}
}
}
/**
* Update indexes on node tables.
*/
function similar_update_7200() {
if (db_table_exists('field_data_body') && !db_index_exists('field_data_body', 'similar')) {
db_query('ALTER TABLE {field_data_body} ENGINE = MYISAM');
db_query('ALTER TABLE {field_data_body} ADD FULLTEXT `similar` (`body_value`)');
}
}
/**
* Add index to node title field.
*/
function similar_update_7201() {
if (!db_index_exists('node', 'similar')) {
db_query('ALTER TABLE {node} ENGINE = MYISAM');
db_query('ALTER TABLE {node} ADD FULLTEXT `similar` (`title`)');
}
}
/**
* Run similar_cron() on update to reset table indexes.
*/
function similar_update_7202() {
// Delete old indices.
foreach (variable_get('similar_indices', array()) as $table => $fields) {
if (db_table_exists($table) && db_index_exists($table, 'similar')) {
db_drop_index($table, 'similar');
}
}
// Create new indices.
include_once dirname(__FILE__) . '/similar.module';
similar_index_fields();
}
Functions
Name | Description |
---|---|
similar_install | Implements hook_install(). |
similar_uninstall | Implements hook_uninstall(). |
similar_update_7200 | Update indexes on node tables. |
similar_update_7201 | Add index to node title field. |
similar_update_7202 | Run similar_cron() on update to reset table indexes. |