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 17:22:35 -0000
@@ -171,6 +171,13 @@ function project_issue_install() {
   project_issue_add_missing_projects();
 
   db_query("UPDATE {system} SET weight = 2 WHERE name = 'project_issue'");
+
+  // Set up future followups to be read/write.
+  variable_set('comment_project_issue', COMMENT_NODE_READ_WRITE);
+  // Enable file attachments for followups.
+  variable_set('comment_upload_project_issue', '1');
+  // Enable file attachments for issues.
+  variable_set('upload_project_issue', '1');
 }
 
 /**
@@ -390,8 +397,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();
@@ -466,8 +473,8 @@ function project_issue_update_5201() {
     '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, 5201)) {
+    return $ret;
   }
 
   $fields = array(
@@ -627,8 +634,8 @@ function project_issue_update_5202() {
     '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, 5202)) {
+    return $ret;
   }
 
   $ret = array();
@@ -648,8 +655,8 @@ function project_issue_update_5203() {
   $modules = array(
     'upload' => t('Upload'),
   );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
+  if ($ret = project_issue_check_update_abort($modules, 5203)) {
+    return $ret;
   }
 
   // Multi-part update
@@ -694,8 +701,8 @@ function project_issue_update_5204() {
   $modules = array(
     'upload' => t('Upload'),
   );
-  if ($message = project_issue_check_dependencies($modules)) {
-    return array(array('success' => FALSE, 'query' => $message));
+  if ($ret = project_issue_check_update_abort($modules, 5204)) {
+    return $ret;
   }
 
   // Remove dead variables.
@@ -719,13 +726,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 +747,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 errors, a return array marked as a failed update, 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;
+}
