From 505974084d248ebcbb225fe328409ef59a9d4e5a Mon Sep 17 00:00:00 2001 From: webchick Date: Mon, 26 Mar 2012 21:56:50 -0700 Subject: Issue #1280792 by xjm, julien, BTMash, pingers, AntoineSolutions, tim.plunkett, Niklas Fiekas: Fixed {trigger_assignments()}.hook has only 32 characters, is too short. --- modules/simpletest/simpletest.info | 1 + .../tests/upgrade/drupal-6.trigger.database.php | 76 ++++++++++++++++++++++ .../simpletest/tests/upgrade/upgrade.trigger.test | 34 ++++++++++ modules/trigger/trigger.install | 15 ++++- 4 files changed, 124 insertions(+), 2 deletions(-) create mode 100644 modules/simpletest/tests/upgrade/drupal-6.trigger.database.php create mode 100644 modules/simpletest/tests/upgrade/upgrade.trigger.test (limited to 'modules') diff --git a/modules/simpletest/simpletest.info b/modules/simpletest/simpletest.info index 6a02cf965..0a43eb35b 100644 --- a/modules/simpletest/simpletest.info +++ b/modules/simpletest/simpletest.info @@ -46,6 +46,7 @@ files[] = tests/upgrade/upgrade.locale.test files[] = tests/upgrade/upgrade.menu.test files[] = tests/upgrade/upgrade.node.test files[] = tests/upgrade/upgrade.taxonomy.test +files[] = tests/upgrade/upgrade.trigger.test files[] = tests/upgrade/upgrade.translatable.test files[] = tests/upgrade/update.trigger.test files[] = tests/upgrade/upgrade.upload.test diff --git a/modules/simpletest/tests/upgrade/drupal-6.trigger.database.php b/modules/simpletest/tests/upgrade/drupal-6.trigger.database.php new file mode 100644 index 000000000..07160d9ec --- /dev/null +++ b/modules/simpletest/tests/upgrade/drupal-6.trigger.database.php @@ -0,0 +1,76 @@ + array( + 'hook' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'op' => array( + 'type' => 'varchar', + 'length' => 32, + 'not null' => TRUE, + 'default' => '', + ), + 'aid' => array( + 'type' => 'varchar', + 'length' => 255, + 'not null' => TRUE, + 'default' => '', + ), + 'weight' => array( + 'type' => 'int', + 'not null' => TRUE, + 'default' => 0, + ), + ), + 'primary key' => array('hook', 'op', 'aid'), + 'module' => 'trigger', + 'name' => 'trigger_assignments', +)); + + +// Add several trigger configurations. +db_insert('trigger_assignments')->fields(array( + 'hook', + 'op', + 'aid', + 'weight', +)) +->values(array( + 'hook' => 'node', + 'op' => 'presave', + 'aid' => 'node_publish_action', + 'weight' => '1', +)) +->values(array( + 'hook' => 'comment', + 'op' => 'presave', + 'aid' => 'comment_publish_action', + 'weight' => '1', +)) +->values(array( + 'hook' => 'comment_delete', + 'op' => 'presave', + 'aid' => 'node_save_action', + 'weight' => '1', +)) +->values(array( + 'hook' => 'nodeapi', + 'op' => 'somehow_nodeapi_got_a_very_long', + 'aid' => 'node_save_action', + 'weight' => '1', +)) +->execute(); + +db_update('system')->fields(array( + 'schema_version' => '6000', + 'status' => '1', +)) +->condition('filename', 'modules/trigger/trigger.module') +->execute(); diff --git a/modules/simpletest/tests/upgrade/upgrade.trigger.test b/modules/simpletest/tests/upgrade/upgrade.trigger.test new file mode 100644 index 000000000..028ea4f05 --- /dev/null +++ b/modules/simpletest/tests/upgrade/upgrade.trigger.test @@ -0,0 +1,34 @@ + 7 upgrade path. + */ +class UpgradePathTriggerTestCase extends UpgradePathTestCase { + public static function getInfo() { + return array( + 'name' => 'Trigger upgrade path', + 'description' => 'Trigger upgrade path tests.', + 'group' => 'Upgrade path', + ); + } + + public function setUp() { + // Path to the database dump. + $this->databaseDumpFiles = array( + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.filled.database.php', + drupal_get_path('module', 'simpletest') . '/tests/upgrade/drupal-6.trigger.database.php', + ); + parent::setUp(); + } + + /** + * Basic tests for the trigger upgrade. + */ + public function testTaxonomyUpgrade() { + $this->assertTrue($this->performUpgrade(), t('The upgrade was completed successfully.')); + } +} diff --git a/modules/trigger/trigger.install b/modules/trigger/trigger.install index 5ed40776b..4deecf3af 100644 --- a/modules/trigger/trigger.install +++ b/modules/trigger/trigger.install @@ -55,9 +55,15 @@ function trigger_install() { } /** - * Adds operation names to the hook names and drops the "op" field. + * 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. */ function trigger_update_7000() { + 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.')); + $result = db_query("SELECT hook, op, aid FROM {trigger_assignments} WHERE op <> ''"); foreach ($result as $record) { @@ -69,10 +75,15 @@ function trigger_update_7000() { ->execute(); } db_drop_field('trigger_assignments', 'op'); + + db_add_primary_key('trigger_assignments', array('hook', 'aid')); } /** - * Increase length of hook name field to 78 characters. + * 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. */ function trigger_update_7001() { db_drop_primary_key('trigger_assignments'); -- cgit v1.2.3