Newer
Older
David Snopek
committed
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/xmlsitemap_node/xmlsitemap_node.module b/xmlsitemap_node/xmlsitemap_node.module
index 4a084cc..73abdf5 100644
--- a/xmlsitemap_node/xmlsitemap_node.module
+++ b/xmlsitemap_node/xmlsitemap_node.module
@@ -81,8 +81,8 @@ function xmlsitemap_node_nodeapi(stdClass &$node, $op, $a3 = NULL, $a4 = NULL) {
switch ($op) {
case 'insert':
case 'update':
- $link = xmlsitemap_node_create_link($node);
- xmlsitemap_link_save($link);
+ // Defer creating and saving the link until the node is fully saved.
+ register_shutdown_function('xmlsitemap_node_create_and_save_link', $node, getcwd());
break;
case 'delete':
xmlsitemap_link_delete('node', $node->nid);
@@ -236,6 +236,21 @@ function xmlsitemap_node_create_link(stdClass $node) {
}
/**
+ * Create and save a sitemap link from a node.
+ */
+function xmlsitemap_node_create_and_save_link($node, $drupal_root = NULL) {
+ if (!empty($drupal_root)) {
+ // Set the CWD to DRUPAL_ROOT as it is not guaranteed to be the same as it
+ // was in the normal context of execution.
+ // @see _drupal_shutdown_function() from Drupal 7.
+ chdir($drupal_root);
+ }
+
+ $link = xmlsitemap_node_create_link($node);
+ xmlsitemap_link_save($link);
+}
+
+/**
* Determine whether a user may view the specified node.
*
* @param $node