? nodefamily_handle_updates.patch
Index: nodefamily.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodefamily/nodefamily.install,v
retrieving revision 1.4
diff -u -r1.4 nodefamily.install
--- nodefamily.install	28 Jan 2007 01:03:04 -0000	1.4
+++ nodefamily.install	29 Jan 2007 16:16:02 -0000
@@ -25,3 +25,26 @@
 function nodefamily_uninstall() {
   db_query("DROP TABLE {nodefamily}");
 }
+
+
+/**
+ * Rename variables: nodefamily_typename_max -> nodefamily_max_typename.
+ */
+function nodefamily_update_1() {
+  include_once('nodefamily.module');
+
+  foreach (node_get_types() as $type) {
+    $type_max_population = variable_get('nodefamily_'. $type->type .'_max', -1);
+    if ($type_max_population != -1) {
+      variable_del('nodefamily_'. $type->type .'_max');
+      nodefamily_content_type_set_max($type->type, $type_max_population);
+    }
+  }
+
+  return array(
+    array(
+      'success' => TRUE,
+      'query' => 'Renamed variables: nodefamily_typename_max -> nodefamily_max_typename.',
+    ),
+  );
+}
Index: nodefamily.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/nodefamily/nodefamily.module,v
retrieving revision 1.19.2.1
diff -u -r1.19.2.1 nodefamily.module
--- nodefamily.module	29 Jan 2007 13:04:55 -0000	1.19.2.1
+++ nodefamily.module	29 Jan 2007 16:16:03 -0000
@@ -33,6 +33,19 @@
 
 
 /**
+ * Return the type names as an array of strings, as opposed to node_get_types()
+ * which returns an array of type objects.
+ */
+function _nodefamily_get_typenames() {
+  $typenames = array();
+
+  foreach (node_get_types() as $type) {
+    $typenames[$type->type] = $type->name;
+  }
+  return $typenames;
+}
+
+/**
  * Menu callback; provide the means to add and remove relations between
  * content types.
  */
@@ -42,11 +55,7 @@
 }
 
 function nodefamily_admin() {
-  $typenames = array();
-
-  foreach(node_get_types() as $type) {
-    $typenames[$type->type] = $type->name;
-  }
+  $typenames = _nodefamily_get_typenames();
 
   $form['add'] = array(
     '#type' => 'fieldset',
@@ -304,6 +313,27 @@
   return $count == $max;
 }
 
+/**
+ * Implementation of hook_node_type():
+ * Rename or delete the maximum population variable if a type name changes.
+ */
+function nodefamily_node_type($op, $info) {
+  switch ($op){
+    case 'delete':
+      variable_del('nodefamily_max_'. $info->type);
+      break;
+    case 'update':
+      if (!empty($info->old_type) && $info->old_type != $info->type) {
+        $type_max_population = variable_get('nodefamily_max_'. $info->old_type, -1);
+        if ($type_max_population != -1) {
+          variable_del('nodefamily_max_'. $info->old_type);
+          variable_set('nodefamily_max_'. $info->type, $type_max_population);
+        }
+      }
+      break;
+  }
+}
+
 
 /**
  * @defgroup nodefamily_ct_relation Implementation of content type relation API
@@ -723,7 +753,7 @@
         'operator' => 'views_handler_operator_eqneq',
         'option' => array(
             '#type' => 'select',
-            '#options' => array('') + node_get_types(),
+            '#options' => _nodefamily_get_typenames(),
         ),
         'handler' => 'nodefamily_views_filter',
         'help' => t('This allows you to filter by child node ID.').t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'),
@@ -749,7 +779,7 @@
         'operator' => 'views_handler_operator_eqneq',
         'option' => array(
             '#type' => 'select',
-            '#options' => array('') + node_get_types(),
+            '#options' => _nodefamily_get_typenames(),
         ),
         'handler' => 'nodefamily_views_filter',
         'help' => t('This allows you to filter by parent node ID.').t('You can optionally restrict the filter to a certain content type, which makes sense to use in conjunctions with the NOT EQUAL operator.'),
