? 6-validate.patch
? 6-x-conf-ignore.patch
? 624360-redirect.patch
? 63220-generate.patch
? 632438-views.patch
? generate_2.patch
? test,patch
Index: domain.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/domain/domain.module,v
retrieving revision 1.134.2.1
diff -u -p -r1.134.2.1 domain.module
--- domain.module	16 Nov 2009 21:25:49 -0000	1.134.2.1
+++ domain.module	20 Nov 2009 15:22:51 -0000
@@ -1145,7 +1145,9 @@ function domain_nodeapi(&$node, $op, $a3
       break;
     case 'insert':
     case 'update':
+      global $_domain;
       $_SESSION['domain_nid'] = $node->nid;
+      $_SESSION['domain_save_id'] = $_domain['domain_id'];
       break;
   }
 }
@@ -1921,38 +1923,34 @@ function domain_invalid_domain_requested
  * We must do this because node_form_submit() overrides the
  * form's redirect values.
  *
+ * For extra checking, we also store the source domain_id and
+ * try to redirect to that domain if we acidentally moved. However,
+ * the node must be visible on that domain.
+ *
  * @return
  *   No return value. Issue a drupal_goto() if needed.
  */
 function domain_node_save_redirect() {
+  global $_domain;
   // If no session token, nothing to do.
   if (!isset($_SESSION['domain_nid'])) {
     return;
   }
   $nid = $_SESSION['domain_nid'];
+  $domain_id = $_SESSION['domain_save_id'];
   // Unset the token now so as not to repeat this step.
   unset($_SESSION['domain_nid']);
-  // Domain Source tells us where to go.
-  if (function_exists('domain_source_lookup')) {
-    $source = domain_source_lookup($nid);
+  unset($_SESSION['domain_save_id']);
+  // Is this node assigned to all affiliates?
+  $domains = domain_get_node_domains($nid);
+  // If so, ensure we return to the calling domain, since the node is always visibe.
+  if (!empty($domains['domain_site'])) {
+    $source = domain_lookup($domain_id);
   }
-  // Otherwise, make an educated guess.
-  // TODO: Merge these lookup functions and make an alter hook.
+  // Otherwise, find the proper domain for this node.
   else {
-    $domains = domain_get_node_domains($nid);
-    // If set to all affilaites, we don't care.
-    if (!empty($domains['domain_site'])) {
-      return;
-    }
-    $domain_id = current($domains['domain_id']);
-    if ($domain_id == -1) {
-      $source = domain_default();
-    }
-    else {
-      $source = domain_lookup($domain_id);
-    }
-  }  
-  // If issuing a redirect, make sure it is valid and to a visible domain.
+    $source = domain_get_node_match($nid);
+  }
   if ($source['domain_id'] != -1 && $source['domain_id'] != $_domain['domain_id'] && ($source['valid'] || user_access('access inactive domains'))) {
     drupal_goto($source['path'] . drupal_get_path_alias("node/$nid"));
   }
