diff options
author | David Rothstein <drothstein@gmail.com> | 2013-12-30 18:46:34 -0500 |
---|---|---|
committer | David Rothstein <drothstein@gmail.com> | 2013-12-30 18:46:34 -0500 |
commit | a4a72dc277fc89eb36964c1509ad1b30121a013a (patch) | |
tree | b433075f02648add69b02d7c89b356ff8c61d557 | |
parent | cb7127c514aee7e66659da3f20348db4c013a40c (diff) | |
download | brdo-a4a72dc277fc89eb36964c1509ad1b30121a013a.tar.gz brdo-a4a72dc277fc89eb36964c1509ad1b30121a013a.tar.bz2 |
Issue #1146244 by Dean Reilly, klausi, fago, firebird, David_Rothstein, aaronbauman, shenzhuxi, jaanhoinatski, themoep, citlacom: Node_access integrity constraint violation on module_invoke_all('node_' . $op, $node);.
-rw-r--r-- | CHANGELOG.txt | 2 | ||||
-rw-r--r-- | modules/node/node.module | 6 | ||||
-rw-r--r-- | modules/node/node.test | 16 | ||||
-rw-r--r-- | modules/node/tests/node_test.module | 18 |
4 files changed, 38 insertions, 4 deletions
diff --git a/CHANGELOG.txt b/CHANGELOG.txt index 74377faa3..a4758eb25 100644 --- a/CHANGELOG.txt +++ b/CHANGELOG.txt @@ -1,6 +1,8 @@ Drupal 7.25, xxxx-xx-xx (development version) ----------------------- +- Fixed a bug in node_save() which prevented the saved node from being updated + in hook_node_insert() and other similar hooks. - Added a meta tag to install.php to prevent it from being indexed by search engines even when Drupal is installed in a subfolder (minor markup change). - Fixed a bug in the database API that caused frequent deadlock errors when diff --git a/modules/node/node.module b/modules/node/node.module index 268076257..876d5ca49 100644 --- a/modules/node/node.module +++ b/modules/node/node.module @@ -1179,10 +1179,8 @@ function node_save($node) { module_invoke_all('node_' . $op, $node); module_invoke_all('entity_' . $op, $node, 'node'); - // Update the node access table for this node. There's no need to delete - // existing records if the node is new. - $delete = $op == 'update'; - node_access_acquire_grants($node, $delete); + // Update the node access table for this node. + node_access_acquire_grants($node); // Clear internal properties. unset($node->is_new); diff --git a/modules/node/node.test b/modules/node/node.test index 3cafefa1d..bfe371755 100644 --- a/modules/node/node.test +++ b/modules/node/node.test @@ -1363,6 +1363,22 @@ class NodeSaveTestCase extends DrupalWebTestCase { $node = node_load($node->nid); $this->assertEqual($node->title, 'updated_presave', 'Static cache has been cleared.'); } + + /** + * Tests saving a node on node insert. + * + * This test ensures that a node has been fully saved when hook_node_insert() + * is invoked, so that the node can be saved again in a hook implementation + * without errors. + * + * @see node_test_node_insert() + */ + function testNodeSaveOnInsert() { + // node_test_node_insert() tiggers a save on insert if the title equals + // 'new'. + $node = $this->drupalCreateNode(array('title' => 'new')); + $this->assertEqual($node->title, 'Node ' . $node->nid, 'Node saved on node insert.'); + } } /** diff --git a/modules/node/tests/node_test.module b/modules/node/tests/node_test.module index fb6678521..edc175f19 100644 --- a/modules/node/tests/node_test.module +++ b/modules/node/tests/node_test.module @@ -161,3 +161,21 @@ function node_test_entity_view_mode_alter(&$view_mode, $context) { $view_mode = $change_view_mode; } } + +/** + * Implements hook_node_insert(). + * + * This tests saving a node on node insert. + * + * @see NodeSaveTest::testNodeSaveOnInsert() + */ +function node_test_node_insert($node) { + // Set the node title to the node ID and save. + if ($node->title == 'new') { + $node->title = 'Node '. $node->nid; + // Remove the is_new flag, so that the node is updated and not inserted + // again. + unset($node->is_new); + node_save($node); + } +} |