customfilter.install in Custom filter 6.2
Same filename and directory in other branches
Installation file for Custom filter.
File
customfilter.installView source
<?php
/**
* @file
* Installation file for Custom filter.
*/
/**
* Implements hook_schema().
*/
function customfilter_schema() {
$schema = array();
$schema['customfilter_filter'] = array(
'description' => 'The table for filters.',
'fields' => array(
'fid' => array(
'description' => 'The filter ID.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'id' => array(
'description' => 'The machine-readable name of this filter.',
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
),
'cache' => array(
'description' => "A boolean value that is set when the filter result is cached.",
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
),
'primary key' => array(
'fid',
),
);
$schema['customfilter_description'] = array(
'description' => 'The table for filter descriptions.',
'fields' => array(
'fdid' => array(
'description' => 'The primary key.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The filter ID.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'language' => array(
'description' => 'The language of these descriptions.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The human-readable name of this filter.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'The filter description.',
'type' => 'text',
'not null' => TRUE,
),
'longtip' => array(
'description' => 'The filter description shown in the filters description page.',
'type' => 'text',
'not null' => TRUE,
),
'shorttip' => array(
'description' => 'The short description shown in the node editing page.',
'type' => 'text',
'not null' => TRUE,
),
),
'indexes' => array(
'customfilter_description_lang' => array(
array(
'language',
6,
),
),
),
'unique keys' => array(
'customfilter_description_fid_lang' => array(
'fid',
'language',
),
),
'primary key' => array(
'fdid',
),
);
$schema['customfilter_rule'] = array(
'description' => 'The table for the filter rules.',
'fields' => array(
'rid' => array(
'description' => 'The rule ID',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'fid' => array(
'description' => 'The ID of the filter containing the replacement rule.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 0,
),
'prid' => array(
'description' => 'The parent rule.',
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'name' => array(
'description' => 'The name of the replacement rule.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'The description of the rule.',
'type' => 'text',
),
'enabled' => array(
'description' => 'A boolean value that is set when the rule is enabled.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'matches' => array(
'description' => 'The n-th matched string to replace.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 1,
),
'pattern' => array(
'description' => 'The regular expression.',
'type' => 'text',
),
'replacement' => array(
'description' => 'The replacement text.',
'type' => 'text',
),
'code' => array(
'description' => 'A boolean value that is set when the replacement text is PHP code to execute.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
),
'weight' => array(
'description' => 'The rule weight.',
'type' => 'int',
'size' => 'tiny',
'unsigned' => FALSE,
'not null' => TRUE,
'default' => 0,
),
),
'indexes' => array(
'customfilter_rule_fid' => array(
'fid',
),
'customfilter_rule_prid' => array(
'prid',
),
'customfilter_rule_weight' => array(
'weight',
),
),
'primary key' => array(
'rid',
),
);
$schema['cache_customfilter'] = drupal_get_schema_unprocessed('system', 'cache');
$schema['cache_customfilter']['description'] = 'Cache table for the Custom filter module to store information about the custom filter, and the replacement rules.';
return $schema;
}
/**
* Implements hook_install().
*/
function customfilter_install() {
drupal_install_schema('customfilter');
}
/**
* Implements hook_update_N().
*/
function customfilter_update_6200() {
$ret = array();
if (variable_get('customfilter_update', 0) < 6120) {
$ret['#abort'] = array(
'success' => FALSE,
'query' => 'The only supported update is from version 6.x-1.0-rc3 or later.',
);
}
return $ret;
}
/**
* TODO: Rewrite the update functions after this one.
*/
/**
* Implements hook_update_N().
*/
function customfilter_update_6206() {
$ret = array();
$schema = array();
$schema['customfilter_description'] = array(
'fields' => array(
'fdid' => array(
'description' => 'The primary key.',
'type' => 'serial',
'unsigned' => TRUE,
'not null' => TRUE,
),
'fid' => array(
'description' => 'The filter ID.',
'type' => 'int',
'size' => 'tiny',
'not null' => TRUE,
'default' => 1,
),
'language' => array(
'description' => 'The language of these descriptions.',
'type' => 'varchar',
'length' => 12,
'not null' => TRUE,
'default' => '',
),
'name' => array(
'description' => 'The human-readable name of this filter.',
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
),
'description' => array(
'description' => 'The filter description.',
'type' => 'text',
'not null' => TRUE,
),
'longtip' => array(
'description' => 'The filter description shown in the filters description page.',
'type' => 'text',
'not null' => TRUE,
),
'shorttip' => array(
'description' => 'The short description shown in the node editing page.',
'type' => 'text',
'not null' => TRUE,
),
),
'indexes' => array(
'customfilter_description_lang' => array(
array(
'language',
6,
),
),
),
'unique keys' => array(
'customfilter_description_fid_lang' => array(
'fid',
'language',
),
),
'primary key' => array(
'fdid',
),
);
if (!db_table_exists('customfilter_description')) {
db_create_table($ret, 'customfilter_description', $schema['customfilter_description']);
}
cache_clear_all('functions', 'cache_customfilter');
$ret[] = array(
'success' => TRUE,
'query' => 'Updated the module cache',
);
return $ret;
}
/**
* Implements hook_update_N().
*/
function customfilter_update_6207(&$sandbox) {
$ret = array();
if (!isset($sandbox['progress'])) {
$sandbox['progress'] = 0;
$sandbox['max'] = db_result(db_query("SELECT COUNT(*) FROM {customfilter_filter}"));
$sandbox['current_fid'] = 0;
}
if ($sandbox['max']) {
$result = db_query_range("SELECT * FROM {customfilter_filter} WHERE fid > %d ORDER BY fid ASC", $sandbox['current_fid'], 0, 10);
while ($row = db_fetch_object($result)) {
drupal_write_record('customfilter_description', $row, 'fdid');
$sandbox['current_fid'] = $row->fid;
$sandbox['progress']++;
}
}
$ret['#finished'] = empty($sandbox['max']) ? 1 : $sandbox['progress'] / $sandbox['max'];
if ($ret['#finished'] == 1) {
db_drop_field($ret, 'customfilter_filter', 'name');
db_drop_field($ret, 'customfilter_filter', 'description');
db_drop_field($ret, 'customfilter_filter', 'longtip');
db_drop_field($ret, 'customfilter_filter', 'shorttip');
$ret[] = array(
'success' => TRUE,
'query' => 'The filter descriptions have been moved to a different database table; the found values are used by default when there is not a description for the language enabled from Drupal',
);
}
return $ret;
}
/**
* Implements hook_uninstall().
*/
function customfilter_uninstall() {
drupal_uninstall_schema('customfilter');
}
Functions
Name | Description |
---|---|
customfilter_install | Implements hook_install(). |
customfilter_schema | Implements hook_schema(). |
customfilter_uninstall | Implements hook_uninstall(). |
customfilter_update_6200 | Implements hook_update_N(). |
customfilter_update_6206 | Implements hook_update_N(). |
customfilter_update_6207 | Implements hook_update_N(). |