summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--modules/simpletest/simpletest.info1
-rw-r--r--modules/simpletest/tests/upgrade/drupal-6.trigger.database.php76
-rw-r--r--modules/simpletest/tests/upgrade/upgrade.trigger.test34
-rw-r--r--modules/trigger/trigger.install15
4 files changed, 124 insertions, 2 deletions
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 @@
+<?php
+/**
+ * @file
+ * Test content for the trigger upgrade path.
+ */
+db_create_table('trigger_assignments', array(
+ 'fields' => 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 @@
+<?php
+/**
+ * @file
+ * Provides upgrade path tests for the Trigger module.
+ */
+
+/**
+ * Tests the Trigger 6 -> 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');