trigger.install

  1. drupal
    1. 6 modules/trigger/trigger.install
    2. 7 modules/trigger/trigger.install

Install, update and uninstall functions for the trigger module.

Functions & methods

NameDescription
trigger_installImplements hook_install().
trigger_schemaImplements hook_schema().
trigger_update_7000Alter the "hook" field and drop the "op field" of {trigger_assignments}.
trigger_update_7001Increase the length of the "hook" field to 78 characters.
trigger_update_7002Renames nodeapi to node.

File

modules/trigger/trigger.install
View source
  1. <?php
  2. /**
  3. * @file
  4. * Install, update and uninstall functions for the trigger module.
  5. */
  6. /**
  7. * Implements hook_schema().
  8. */
  9. function trigger_schema() {
  10. // The total index length (hook and aid) must be less than 333. Since the aid
  11. // field is 255 characters, the hook field can have a maximum length of 78.
  12. $schema['trigger_assignments'] = array(
  13. 'description' => 'Maps trigger to hook and operation assignments from trigger.module.',
  14. 'fields' => array(
  15. 'hook' => array(
  16. 'type' => 'varchar',
  17. 'length' => 78,
  18. 'not null' => TRUE,
  19. 'default' => '',
  20. 'description' => 'Primary Key: The name of the internal Drupal hook; for example, node_insert.',
  21. ),
  22. 'aid' => array(
  23. 'type' => 'varchar',
  24. 'length' => 255,
  25. 'not null' => TRUE,
  26. 'default' => '',
  27. 'description' => "Primary Key: Action's {actions}.aid.",
  28. ),
  29. 'weight' => array(
  30. 'type' => 'int',
  31. 'not null' => TRUE,
  32. 'default' => 0,
  33. 'description' => 'The weight of the trigger assignment in relation to other triggers.',
  34. ),
  35. ),
  36. 'primary key' => array('hook', 'aid'),
  37. 'foreign keys' => array(
  38. 'action' => array(
  39. 'table' => 'actions',
  40. 'columns' => array('aid' => 'aid'),
  41. ),
  42. ),
  43. );
  44. return $schema;
  45. }
  46. /**
  47. * Implements hook_install().
  48. */
  49. function trigger_install() {
  50. // Do initial synchronization of actions in code and the database.
  51. actions_synchronize();
  52. }
  53. /**
  54. * Alter the "hook" field and drop the "op field" of {trigger_assignments}.
  55. *
  56. * Increase the length of the "hook" field to 78 characters and adds operation
  57. * names to the hook names, and drops the "op" field.
  58. */
  59. function trigger_update_7000() {
  60. db_drop_primary_key('trigger_assignments');
  61. 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.'));
  62. $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''");
  63. foreach ($result as $record) {
  64. db_update('trigger_assignments')
  65. ->fields(array('hook' => $record->hook . '_' . $record->op))
  66. ->condition('hook', $record->hook)
  67. ->condition('op', $record->op)
  68. ->condition('aid', $record->aid)
  69. ->execute();
  70. }
  71. db_drop_field('trigger_assignments', 'op');
  72. db_add_primary_key('trigger_assignments', array('hook', 'aid'));
  73. }
  74. /**
  75. * Increase the length of the "hook" field to 78 characters.
  76. *
  77. * This is a separate function for those who ran an older version of
  78. * trigger_update_7000() that did not do this.
  79. */
  80. function trigger_update_7001() {
  81. db_drop_primary_key('trigger_assignments');
  82. 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')));
  83. }
  84. /**
  85. * Renames nodeapi to node.
  86. */
  87. function trigger_update_7002() {
  88. $result = db_query("SELECT hook, aid FROM {trigger_assignments}");
  89. foreach($result as $record) {
  90. $new_hook = str_replace('nodeapi', 'node', $record->hook);
  91. db_update('trigger_assignments')
  92. ->fields(array('hook' => $new_hook))
  93. ->condition('hook', $record->hook)
  94. ->condition('aid', $record->aid)
  95. ->execute();
  96. }
  97. }
Login or register to post comments