Index: xmlsitemap.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap.module,v
retrieving revision 1.16
diff -u -r1.16 xmlsitemap.module
--- xmlsitemap.module	18 Dec 2007 22:54:51 -0000	1.16
+++ xmlsitemap.module	18 Feb 2008 21:23:31 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap.module,v 1.16 2007/12/18 22:54:51 darrenoh Exp $
+// $Id: xmlsitemap.module,v 1.1.2.14 2007/12/18 22:54:51 darrenoh Exp $
 
 /**
  * @file Creates a site map compatible with the sitemaps.org schema.
@@ -597,6 +597,7 @@
     global $base_url;
     $links[] = array('#loc' => "$base_url/", '#changefreq' => 'always', '#priority' => variable_get('xmlsitemap_front_page_priority', 1));
     $links = array_merge($links, _xmlsitemap_additional_links());
+    $links = array_merge($links, module_invoke_all('gsitemap'));
     $links = array_merge($links, _xmlsitemap_xml_links());
     if (!empty($links)) {
       foreach ($links as $key => $link) {
@@ -644,6 +645,7 @@
 function _xmlsitemap_xml_links() {
   $links = array();
   $xml = module_invoke_all('xmlsitemap_links', 'xml');
+  $xml = array_merge($xml, module_invoke_all('gsitemap', 'xml'));
   foreach ($xml as $entries) {
     $start = strpos($entries, '<url>');
     if ($start !== FALSE) {
Index: xmlsitemap_node/xmlsitemap_node.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap_node/xmlsitemap_node.install,v
retrieving revision 1.7
diff -u -r1.7 xmlsitemap_node.install
--- xmlsitemap_node/xmlsitemap_node.install	8 Jan 2008 05:13:35 -0000	1.7
+++ xmlsitemap_node/xmlsitemap_node.install	18 Feb 2008 21:28:14 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap_node.install,v 1.7 2008/01/08 05:13:35 darrenoh Exp $
+// $Id: xmlsitemap_node.install,v 1.1.2.12 2008/01/08 05:13:27 darrenoh Exp $
 
 /**
  * Implementation of hook_install().
@@ -32,6 +32,53 @@
       );");
       break;
   }
+  _xmlsitemap_node_gsitemap_replace();
+}
+
+/**
+ * Transfer data from Google Sitemap if it is installed.
+ */
+function _xmlsitemap_node_gsitemap_replace() {
+  if (db_result(db_query("
+    SELECT 1 FROM {system}
+    WHERE type = 'module' AND name = 'gsitemap' AND (status = 1 OR schema_version >= 0)
+  "))) {
+    switch ($GLOBALS['db_type']) {
+      case 'mysql':
+      case 'mysqli':
+        db_query("
+          UPDATE {xmlsitemap_node} xn, {url_alias} ua SET xn.pid = ua.pid
+          WHERE xn.pid IS NULL AND ua.src = CONCAT('node/', xn.nid)
+        ");
+        break;
+      case 'pgsql':
+        db_query("
+          UPDATE {xmlsitemap_node} SET pid = {url_alias}.pid FROM {url_alias}
+          WHERE {xmlsitemap_node}.pid IS NULL AND {url_alias}.src = 'node/' || {xmlsitemap_node}.nid
+        ");
+        break;
+    }
+    db_query("
+      INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, previously_changed, last_comment, previous_comment, priority_override)
+      SELECT nid, pid, last_changed, previously_changed, last_comment, previous_comment, priority_override FROM {gsitemap}
+    ");
+    $settings = db_query("SELECT * FROM {variable} WHERE name LIKE 'gsitemap\_%wt'");
+    while ($variable = db_fetch_object($settings)) {
+      $ts = strlen('gsitemap_');
+      $tl = strlen('wt');
+      $type = substr($variable->name, $ts, -$tl);
+      if (node_get_types('type', $type) === FALSE) {
+        variable_set("xmlsitemap_node_${type}_priority", (float) unserialize($variable->value));
+      }
+      else {
+        variable_set("xmlsitemap_node_type_priority_$type", (float) unserialize($variable->value));
+      }
+      variable_del($variable->name);
+    }
+    $variable = db_fetch_object(db_query("SELECT * FROM {variable} WHERE name = 'gsitemap_countcom'"));
+    variable_set('xmlsitemap_node_count_comments', unserialize($variable->value));
+    variable_del($variable->name);
+  }
 }
 
 /**
@@ -60,6 +107,7 @@
       break;
   }
   db_query(_xmlsitemap_node_insert_query());
+  db_query(_xmlsitemap_node_updatepid_query());
   xmlsitemap_update_sitemap();
 }
 
@@ -68,30 +116,44 @@
  * @return Query string
  */
 function _xmlsitemap_node_insert_query() {
-  $query = "
+  return "
     INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, last_comment, previous_comment)
-    SELECT n.nid, MAX(ua.pid), n.changed, s.last_comment_timestamp, MAX(c.timestamp) FROM {node} n
+    SELECT n.nid, 0, n.changed, s.last_comment_timestamp, MAX(c.timestamp) FROM {node} n
     LEFT JOIN {node_comment_statistics} s ON s.nid = n.nid
     LEFT OUTER JOIN {comments} c ON c.nid = n.nid AND c.timestamp < s.last_comment_timestamp
-    LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid";
+    LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
+    WHERE xn.nid IS NULL
+    GROUP BY n.nid, n.changed, s.last_comment_timestamp
+  ";
+}
+/**
+ * Build SQL query for updating pids in xmlsitemap_node table.
+ * @return Query string
+ */
+function _xmlsitemap_node_updatepid_query() {
   switch ($GLOBALS['db_type']) {
     case 'mysql':
     case 'mysqli':
-      $query .= "
-        LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', n.nid)";
+      $query = "
+        UPDATE {xmlsitemap_node} xn INNER JOIN {url_alias} ua ON
+        ua.src = CONCAT('node/', xn.nid)
+        SET xn.pid = ua.pid
+        WHERE xn.pid = 0
+      ";
       break;
     case 'pgsql':
-      $query .= "
-        LEFT JOIN {url_alias} ua ON ua.src = 'node/' || n.nid";
+      $query = "
+        UPDATE {xmlsitemap_node} xn
+        SET pid = {url_alias}.pid
+        FROM {url_alias} ua
+        WHERE ua.src = 'node/' || xn.nid AND xn.pid = 0
+      ";
       break;
   }
-  $query .= "
-    WHERE xn.nid IS NULL
-    GROUP BY n.nid, n.changed, s.last_comment_timestamp
-  ";
   return $query;
 }
 
+
 /**
  * Implementation of hook_disable().
  */
@@ -110,3 +172,62 @@
   }
 }
 
+/**
+ * Implementation of hook_update_N().
+ * Fix scrambled values.
+ */
+function xmlsitemap_node_update_1() {
+  $ret = array();
+  $result = db_query("SELECT xn.nid FROM {xmlsitemap_node} xn LEFT JOIN {node} n ON n.nid = xn.nid WHERE n.nid IS NULL");
+  $bad_nids = array();
+  while ($node = db_fetch_object($result)) {
+    $bad_nids[] = $node->nid;
+  }
+  if (!empty($bad_nids)) {
+    $ret[] = update_sql("DELETE FROM {xmlsitemap_node} WHERE nid IN (". db_escape_string(implode(', ', $bad_nids)) .")");
+    $ret[] = update_sql(_xmlsitemap_node_insert_query());
+    xmlsitemap_update_sitemap();
+  }
+  return $ret;
+}
+
+/**
+ * Implementation of hook_update_N().
+ * Add missing nodes.
+ */
+function xmlsitemap_node_update_2() {
+  $ret = array(update_sql(_xmlsitemap_node_insert_query()));
+  xmlsitemap_update_sitemap();
+  return $ret;
+}
+
+/**
+ * Implementation of hook_update_N().
+ * Add missing URL aliases.
+ * Update last-changed times.
+ */
+function xmlsitemap_node_update_3() {
+  $ret = array(update_sql("UPDATE {xmlsitemap_node} SET pid = NULL WHERE pid = 0"));
+  switch ($GLOBALS['db_type']) {
+    case 'mysql':
+    case 'mysqli':
+      $ret[] = update_sql("
+        UPDATE {xmlsitemap_node} xn
+        INNER JOIN {node} n ON n.nid = xn.nid
+        LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', xn.nid) AND xn.pid IS NULL
+        SET xn.last_changed = n.changed, xn.pid = ua.pid
+      ");
+      break;
+    case 'pgsql':
+      $ret[] = update_sql("
+        UPDATE {xmlsitemap_node}
+        SET pid = {url_alias}.pid, last_changed = {node}.changed
+        FROM {node} LEFT JOIN {url_alias} ON {url_alias}.src = 'node/' || nid AND pid IS NULL
+        WHERE {node}.nid = nid
+      ");
+      break;
+  }
+  $ret = array_merge($ret, xmlsitemap_node_update_2());
+  return $ret;
+}
+
Index: xmlsitemap_node/xmlsitemap_node.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/xmlsitemap/xmlsitemap_node/xmlsitemap_node.module,v
retrieving revision 1.17
diff -u -r1.17 xmlsitemap_node.module
--- xmlsitemap_node/xmlsitemap_node.module	8 Jan 2008 05:13:35 -0000	1.17
+++ xmlsitemap_node/xmlsitemap_node.module	19 Feb 2008 04:52:30 -0000
@@ -1,5 +1,5 @@
 <?php
-// $Id: xmlsitemap_node.module,v 1.17 2008/01/08 05:13:35 darrenoh Exp $
+// $Id: xmlsitemap_node.module,v 1.1.2.15 2008/01/08 05:13:28 darrenoh Exp $
 
 /**
  * @file Adds nodes to the site map.
@@ -13,6 +13,7 @@
   if (!isset($type)) {
     $links = _xmlsitemap_node_links(_xmlsitemap_node_excludes());
     $links = array_merge($links, module_invoke_all('xmlsitemap_links', 'node', _xmlsitemap_node_excludes()));
+    $links = array_merge($links, module_invoke_all('gsitemap', 'node', _xmlsitemap_node_excludes()));
     if (!empty($links)) {
       foreach ($links as $key => $link) {
         $nid[$key] = $link['nid'];
@@ -255,25 +256,11 @@
       break;
     case 'insert':
       $node->priority_override = isset($node->priority_override) ? $node->priority_override : 'NULL';
-      $query = "
-        INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, priority_override)
-        SELECT %d, ua.pid, %d, %s
+      $query = "INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, priority_override)
+        SELECT %d, 0, %d, %s
         FROM {node} n";
-      switch ($GLOBALS['db_type']) {
-        case 'mysql':
-        case 'mysqli':
-          $query .= "
-            LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', %d)";
-          break;
-        case 'pgsql':
-          $query .= "
-            LEFT JOIN {url_alias} ua ON ua.src = 'node/' || %d";
-          break;
-      }
-      $query .= "
-        LIMIT 1
-      ";
       db_query($query, $node->nid, $node->changed, $node->priority_override, $node->nid);
+      _xmlsitemap_node_updatepid($node->nid);
       if ($node->status) {
         xmlsitemap_update_sitemap();
       }
@@ -283,23 +270,12 @@
         $priority = db_result(db_query("SELECT priority_override FROM {xmlsitemap_node} WHERE nid = %d", $node->nid));
         $node->priority_override = isset($priority) && $priority !== FALSE ? $priority : 'NULL';
       }
-      switch ($GLOBALS['db_type']) {
-        case 'mysql':
-        case 'mysqli':
-          db_query("
-            UPDATE {xmlsitemap_node} xn LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', xn.nid)
-            SET xn.pid = ua.pid, xn.previously_changed = xn.last_changed, xn.last_changed = %d, xn.priority_override = %s
-            WHERE xn.nid = %d
-          ", $node->changed, $node->priority_override, $node->nid);
-          break;
-        case 'pgsql':
-          db_query("
-            UPDATE {xmlsitemap_node}
-            SET pid = {url_alias}.pid, previously_changed = last_changed, last_changed = %d, priority_override = %s
-            FROM {url_alias} WHERE nid = %d AND ({url_alias}.src = 'node/' || nid OR {url_alias}.src IS NULL)
-          ", $node->changed, $node->priority_override, $node->nid);
-          break;
-      }
+      db_query("
+        UPDATE {xmlsitemap_node} xn 
+        SET xn.pid = 0, xn.previously_changed = xn.last_changed, xn.last_changed = %d, xn.priority_override = %s
+        WHERE xn.nid = %d
+      ", $node->changed, $node->priority_override, $node->nid);
+      _xmlsitemap_node_updatepid($node->nid);
       if ($node->status || $node->xmlsitemap_node_status) {
         xmlsitemap_update_sitemap();
       }
@@ -365,27 +341,46 @@
   if (db_result(db_query_range("SELECT COUNT(*) FROM {node} n LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid WHERE xn.nid IS NULL", 0, 1))) {
     $query = "
       INSERT INTO {xmlsitemap_node} (nid, pid, last_changed, last_comment, previous_comment)
-      SELECT n.nid, MAX(ua.pid), n.changed, s.last_comment_timestamp, MAX(c.timestamp) FROM {node} n
+      SELECT n.nid, 0, n.changed, s.last_comment_timestamp, MAX(c.timestamp) FROM {node} n
       LEFT JOIN {node_comment_statistics} s ON s.nid = n.nid
       LEFT OUTER JOIN {comments} c ON c.nid = n.nid AND c.timestamp < s.last_comment_timestamp
-      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid";
-    switch ($GLOBALS['db_type']) {
-      case 'mysql':
-      case 'mysqli':
-        $query .= "
-          LEFT JOIN {url_alias} ua ON ua.src = CONCAT('node/', n.nid)";
-        break;
-      case 'pgsql':
-        $query .= "
-          LEFT JOIN {url_alias} ua ON ua.src = 'node/' || n.nid";
-        break;
-    }
-    $query .= "
+      LEFT JOIN {xmlsitemap_node} xn ON xn.nid = n.nid
       WHERE xn.nid IS NULL
       GROUP BY n.nid, n.changed, s.last_comment_timestamp
     ";
     db_query($query);
+    // Update the pids
+    _xmlsitemap_node_updatepids();
+    // Update sitemap
     xmlsitemap_update_sitemap();
   }
 }
 
+/**
+ * @author Earnest Berry III <earnest dot berry at gmail dot com>
+ * Build SQL query for updating pids in xmlsitemap_node table.
+ * @return Query string
+ * Doing a join on a function is bad practice and very inefficient.
+ * There are 2 options:
+ * 1. Create a Temporary table
+ * 2. Run the query, and update each row individually.
+ */
+function _xmlsitemap_node_updatepids() {
+  $update_rs = db_query("SELECT nid FROM {xmlsitemap_node} WHERE pid = 0");
+  while($row = db_fetch_object($update_rs)) {
+    db_query("UPDATE {xmlsitemap_node} SET xn.pid = (
+                SELECT ua.pid FROM {url_alias} ua WHERE ua.src = '%s'
+              )", 'node/' . $row->nid);
+  }
+  return;
+}
+/**
+ * @author Earnest Berry III <earnest dot berry at gmail dot com>
+ * Updates the pid for one node.
+ */
+function _xmlsitemap_node_updatepid($nid) {
+  db_query("UPDATE {xmlsitemap_node} SET xn.pid = (
+              SELECT ua.pid FROM {url_alias} ua WHERE ua.src = '%s'
+            )", 'node/' . $nid);
+  return;
+}
\ No newline at end of file

