2007-06-29 18:06:51 +00:00
<?php
2009-05-13 19:42:18 +00:00
/**
* @file
* Install, update and uninstall functions for the trigger module.
*/
2007-10-05 14:43:26 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_schema().
2007-10-05 14:43:26 +00:00
*/
function trigger_schema() {
2012-02-14 18:38:17 +00:00
// The total index length (hook and aid) must be less than 333. Since the aid
// field is 255 characters, the hook field can have a maximum length of 78.
2007-10-05 14:43:26 +00:00
$schema['trigger_assignments'] = array(
2008-11-15 13:01:11 +00:00
'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
2007-10-05 14:43:26 +00:00
'fields' => array(
2007-12-28 12:02:52 +00:00
'hook' => array(
'type' => 'varchar',
2012-02-14 18:38:17 +00:00
'length' => 78,
2007-12-28 12:02:52 +00:00
'not null' => TRUE,
'default' => '',
2009-09-19 11:07:37 +00:00
'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
2007-12-28 12:02:52 +00:00
),
'aid' => array(
'type' => 'varchar',
'length' => 255,
'not null' => TRUE,
'default' => '',
2008-11-15 13:01:11 +00:00
'description' => "Primary Key: Action's {actions}.aid.",
2007-12-28 12:02:52 +00:00
),
2007-10-10 11:39:35 +00:00
'weight' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
2008-11-15 13:01:11 +00:00
'description' => 'The weight of the trigger assignment in relation to other triggers.',
2007-10-10 11:39:35 +00:00
),
2007-10-05 14:43:26 +00:00
),
2009-09-19 11:07:37 +00:00
'primary key' => array('hook', 'aid'),
2009-06-01 22:07:10 +00:00
'foreign keys' => array(
2010-08-22 13:55:53 +00:00
'action' => array(
'table' => 'actions',
'columns' => array('aid' => 'aid'),
),
2009-06-01 22:07:10 +00:00
),
2007-10-05 14:43:26 +00:00
);
return $schema;
}
2009-11-02 02:38:53 +00:00
/**
2009-12-04 16:49:48 +00:00
* Implements hook_install().
2009-11-02 02:38:53 +00:00
*/
function trigger_install() {
// Do initial synchronization of actions in code and the database.
actions_synchronize();
}
2009-09-19 11:07:37 +00:00
/**
2012-03-27 04:56:50 +00:00
* Alter the "hook" field and drop the "op field" of {trigger_assignments}.
*
* Increase the length of the "hook" field to 78 characters and adds operation
* names to the hook names, and drops the "op" field.
2009-09-19 11:07:37 +00:00
*/
function trigger_update_7000() {
2012-03-27 04:56:50 +00:00
db_drop_primary_key('trigger_assignments');
db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.'));
2009-09-19 11:07:37 +00:00
$result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
2007-10-10 11:39:35 +00:00
2009-09-29 15:13:57 +00:00
foreach ($result as $record) {
db_update('trigger_assignments')
->fields(array('hook' => $record->hook . '_' . $record->op))
->condition('hook', $record->hook)
->condition('op', $record->op)
->condition('aid', $record->aid)
->execute();
2009-09-19 11:07:37 +00:00
}
2009-09-29 15:13:57 +00:00
db_drop_field('trigger_assignments', 'op');
2012-03-27 04:56:50 +00:00
db_add_primary_key('trigger_assignments', array('hook', 'aid'));
2009-09-19 11:07:37 +00:00
}
2012-02-14 18:38:17 +00:00
2012-07-16 16:45:43 +00:00
/**
* @addtogroup updates-7.x-extra
* @{
*/
2012-02-14 18:38:17 +00:00
/**
2012-03-27 04:56:50 +00:00
* Increase the length of the "hook" field to 78 characters.
*
* This is a separate function for those who ran an older version of
* trigger_update_7000() that did not do this.
2012-02-14 18:38:17 +00:00
*/
function trigger_update_7001() {
db_drop_primary_key('trigger_assignments');
db_change_field('trigger_assignments', 'hook', 'hook', array('type' => 'varchar', 'length' => 78, 'not null' => TRUE, 'default' => '', 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.', ), array('primary key' => array('hook', 'aid')));
}
2012-04-04 17:07:00 +00:00
/**
* Renames nodeapi to node.
*/
function trigger_update_7002() {
$result = db_query("SELECT hook, aid FROM {trigger_assignments}");
foreach($result as $record) {
$new_hook = str_replace('nodeapi', 'node', $record->hook);
db_update('trigger_assignments')
->fields(array('hook' => $new_hook))
->condition('hook', $record->hook)
->condition('aid', $record->aid)
->execute();
}
}
2012-07-16 16:45:43 +00:00
/**
* @} End of "addtogroup updates-7.x-extra".
*/