? 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	3 Feb 2007 09:28:08 -0000
@@ -23,5 +23,32 @@
 }
 
 function nodefamily_uninstall() {
+  include_once('nodefamily.module');
+
   db_query("DROP TABLE {nodefamily}");
+
+  foreach (node_get_types('names') as $typename) {
+    _nodefamily_content_type_del_max($typename);
+  }
+}
+
+
+/**
+ * Rename variables: nodefamily_typename_max -> nodefamily_max_typename.
+ */
+function nodefamily_update_1() {
+  foreach (node_get_types('names') as $typename) {
+    $type_max_population = variable_get('nodefamily_'. $typename .'_max', -1);
+    if ($type_max_population != -1) {
+      variable_del('nodefamily_'. $typename .'_max');
+      variable_set('nodefamily_max_'. $typename, $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	3 Feb 2007 09:28:09 -0000
@@ -42,11 +42,7 @@
 }
 
 function nodefamily_admin() {
-  $typenames = array();
-
-  foreach(node_get_types() as $type) {
-    $typenames[$type->type] = $type->name;
-  }
+  $typenames = node_get_types('names');
 
   $form['add'] = array(
     '#type' => 'fieldset',
@@ -136,21 +132,21 @@
   
   $header = array(t('Parent type'), t('Child type'), '');
   $rows = array();
-  $types = node_get_types();
+  $typenames = node_get_types('names');
   foreach($relations as $key => $value) {
-    $rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $types));
+    $rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames));
   }  
   
   return theme('table', $header, $rows, array('class' => 'nodefamily'));
 }
 
-function _nodefamily_relation_overview_dive($parent, &$array, &$types) {
+function _nodefamily_relation_overview_dive($parent, $array, $typenames) {
   $rows = array();
   foreach($array as $key => $value) {
-    $rows[] = array($types[$parent]->name, $types[$key]->name,
+    $rows[] = array($typenames[$parent], $typenames[$key],
               l(t('delete'),'admin/content/nodefamily/' . $parent .'/'. $key)); 
     if ($value && is_array($value)) {
-      $rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $types));
+      $rows = array_merge($rows, _nodefamily_relation_overview_dive($key, $value, $typenames));
     }
   }
   return $rows;
@@ -291,6 +287,10 @@
   return variable_get('nodefamily_max_'. $typename, 0);
 }
 
+function _nodefamily_content_type_del_max($typename) {
+  variable_del('nodefamily_max_'. $typename);
+}
+
 /**
  * Return, if the maximum population is already reached.
  */
@@ -304,6 +304,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':
+      _nodefamily_content_type_del_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) {
+          _nodefamily_content_type_del_max($info->old_type);
+          nodefamily_content_type_set_max($info->type, $type_max_population);
+        }
+      }
+      break;
+  }
+}
+
 
 /**
  * @defgroup nodefamily_ct_relation Implementation of content type relation API
@@ -723,7 +744,7 @@
         'operator' => 'views_handler_operator_eqneq',
         'option' => array(
             '#type' => 'select',
-            '#options' => array('') + node_get_types(),
+            '#options' => node_get_types('names'),
         ),
         '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 +770,7 @@
         'operator' => 'views_handler_operator_eqneq',
         'option' => array(
             '#type' => 'select',
-            '#options' => array('') + node_get_types(),
+            '#options' => node_get_types('names'),
         ),
         '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.'),
