Index: project_issue.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/project_issue/project_issue.install,v
retrieving revision 1.34
diff -u -F^f -r1.34 project_issue.install
--- project_issue.install	26 Oct 2007 13:46:13 -0000	1.34
+++ project_issue.install	27 Oct 2007 23:32:49 -0000
@@ -390,8 +390,8 @@ function project_issue_update_5200() {
     'comment_upload' => t('Comment upload'),
     'comment' => t('Comment')
   );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
+  if ($ret = project_issue_check_update_abort($modules, 5200)) {
+    return $ret;
   }
 
   $ret = array();
@@ -461,15 +461,6 @@ function project_issue_update_5201() {
   // issue followups per issue.
   $limit = 100;
 
-  // Prevent the update and warn if the new required modules aren't enabled.
-  $modules = array(
-    'comment_upload' => t('Comment upload'),
-    'comment' => t('Comment')
-  );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
-  }
-
   $fields = array(
     'pid',
     'rid',
@@ -622,15 +613,6 @@ function _project_issue_update_5201_get_
  */
 function project_issue_update_5202() {
 
-  // Prevent the update and warn if the new required modules aren't enabled.
-  $modules = array(
-    'comment_upload' => t('Comment upload'),
-    'comment' => t('Comment')
-  );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
-  }
-
   $ret = array();
   $ret[] = update_sql('DROP TABLE {project_comments}');
   return $ret;
@@ -644,14 +626,6 @@ function project_issue_update_5203() {
   // default has been chosen, but you may want to tweak depending on your setup.
   $limit = 500;
 
-  // Prevent the update and warn if the new required modules aren't enabled.
-  $modules = array(
-    'upload' => t('Upload'),
-  );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
-  }
-
   // Multi-part update
   if (!isset($_SESSION['project_issue_update_5203'])) {
     $_SESSION['project_issue_update_5203'] = 0;
@@ -690,14 +664,6 @@ function project_issue_update_5203() {
  */
 function project_issue_update_5204() {
 
-  // Prevent the update and warn if the new required modules aren't enabled.
-  $modules = array(
-    'upload' => t('Upload'),
-  );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
-  }
-
   // Remove dead variables.
   variable_del('project_issues_extensions_default');
   $variables = db_query("SELECT name FROM {variable} WHERE name LIKE 'project_issues_extensions_%%'");
@@ -719,13 +685,19 @@ function project_issue_update_5204() {
 
 /**
  * Helper function for determining new module dependencies.
+ *
+ * @param $modules
+ *   An associative array of modules to check. Key is module name,
+ *   value is human-readable name.
+ * @return
+ *   A string containing the error message, if any -- FALSE otherwise.
  */
 function project_issue_check_dependencies($modules) {
   $message = FALSE;
   $messages = array();
   foreach ($modules as $module => $name) {
     if (!module_exists($module)) {
-      $messages[] = t('The %module module is not present.', array('%module' => $name));
+      $messages[] = t('The %module module is not enabled.', array('%module' => $name));
     }
   }
   if (!empty($messages)) {
@@ -734,3 +706,38 @@ function project_issue_check_dependencie
 
   return $message;
 }
+
+/**
+ * Helper function for rolling back updates if dependency checks fail.
+ *
+ * @param $modules
+ *   An associative array of modules to check. Key is module name,
+ *   value is human-readable name.
+ * @param $current_update
+ *   The current update.
+ * @return
+ *   If a dependency check fails, a return array marked as failed (with
+ *   a user message) -- otherwise, an empty array.
+ */
+function project_issue_check_update_abort($modules, $current_update) {
+  $ret = array();
+
+  // Dependency check failed.
+  if ($message = project_issue_check_dependencies($modules)) {
+    // Remove all subsequent project issue updates.
+    foreach ($_SESSION['update_remaining'] as $key => $update) {
+      if ($update['module'] = 'project_issue' && intval($update['version']) > $current_update) {
+        unset($_SESSION['update_remaining'][$key]);
+      }
+    }
+    // Clarify the nature of the error, and what to do next.
+    // Unfortunately, there's no elegant way to properly reset the schema version
+    // programatically, so we'll have to instruct the user to redo the update
+    // manually.
+    $message .= '<p>'. t("This and all subsequent updates of Project issue were safely aborted. Correct the problems listed above, then <a href=\"!update_link\">re-run update.php</a>, click 'Select versions', select update %update for project_issue, and click 'Update'", array('!update_link' => url("update.php", "op=selection"), '%update' => $current_update)) .'</p><p><em>'. t('Note: you will most likely need to disable the Project issue module temporarily in order to resolve the issues above.') .'</em></p>';
+
+    $ret = array(array('success' => FALSE, 'query' => $message));
+  }
+
+  return $ret;
+}
