Index: hosting_package.install
===================================================================
RCS file: /cvs/drupal/contributions/modules/hosting/package/hosting_package.install,v
retrieving revision 1.14
diff -u -r1.14 hosting_package.install
--- hosting_package.install	28 Sep 2009 16:24:07 -0000	1.14
+++ hosting_package.install	2 Oct 2009 09:30:56 -0000
@@ -296,3 +296,34 @@
 
   return $ret;
 }
+
+// Clean up packages duplication introduced in 0.4-alpha1 by
+// removing all of them and scheduling a re-verify for all platforms.
+function hosting_package_update_11() {
+  $ret = array();
+
+  // delete node packages
+  $result = db_query("SELECT nid FROM {node} WHERE type='package'");
+  while ($package = db_fetch_object($result)) {
+    $ret[] = array('success'=>TRUE, 'query'=>"Deleted package ".$package->nid);
+    node_delete($package->nid);
+  }
+  // catch and supress node_delete messages
+  drupal_get_messages('status');
+  
+  // clean other tables that are not triggered by node_delete
+  $ret[] = update_sql("TRUNCATE TABLE {hosting_package_instance}");
+  //$ret[] = update_sql("ALTER TABLE `hosting_package_instance` AUTO_INCREMENT=1");
+  $ret[] = update_sql("TRUNCATE TABLE {hosting_package_languages}");
+  $ret[] = update_sql("DELETE FROM {node_access} WHERE realm='hosting package'");
+
+  // Schedule re-verify of all existing platforms
+  $result = db_query("SELECT nid FROM {node} WHERE type='platform' AND status=1");
+  while ($platform = db_fetch_object($result)) {
+    $ret[] = array('success'=>TRUE, 'query'=>"Re-verify scheduled for platform ".$platform->nid);
+    hosting_add_task($platform->nid, 'verify');
+  }
+
+  return $ret;
+}
+
