Commit f5f28ec2 authored by dsnopek's avatar dsnopek Committed by dsnopek

Issue #2986701 by dsnopek: [xmlsitemap] Add D6LTS patch for SA-CONTRIB-2018-053

parent a07b2d4a
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
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment