? vocabindex/.DS_Store
? vocabindex/DEVELOPERS.txt
? vocabindex/translations/.DS_Store
Index: vocabindex/vocabindex.install
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.install,v
retrieving revision 1.1.2.3.4.15
diff -u -p -r1.1.2.3.4.15 vocabindex.install
--- vocabindex/vocabindex.install	18 Aug 2008 20:30:43 -0000	1.1.2.3.4.15
+++ vocabindex/vocabindex.install	17 Sep 2008 18:18:39 -0000
@@ -30,37 +30,108 @@
  * Implementation of hook_install().
  */function vocabindex_install() {  drupal_install_schema('vocabindex');
 
-  module_load_include('module', 'vocabindex');
-
-  $vocs = taxonomy_get_vocabularies();
-  foreach ($vocs as $voc) {
-    vocabindex_index_create($voc->vid);
-  }}
+  vocabindex_create_vis();}
 
 /**
  * Implementation of hook_uninstall().
  */function vocabindex_uninstall() {
-  // Delete variables
-  db_query("DELETE FROM {variable} WHERE name LIKE 'vocabindex_%'");
-  cache_clear_all('variables', 'cache');
+  vocabindex_delete_variables();
 
-  // Delete indices and clear cache
+  // Delete indices and clear cache.
   module_load_include('inc', 'vocabindex', 'vocabindex.admin');
   vocabindex_index_delete(VOCABINDEX_VI_ALL);
   cache_clear_all('vocabindex', 'cache', TRUE);
 
-  // Delete blocks
+  // Delete blocks.
   db_query("DELETE FROM {blocks} WHERE module = 'vocabindex'");
   db_query("DELETE FROM {blocks_roles} WHERE module = 'vocabindex'");
 
   //Delete DB table.  drupal_uninstall_schema('vocabindex');}
 
 /**
- * Implementation of hook_enable()
+ * Implementation of hook_enable().
  */
 function vocabindex_enable() {
   drupal_set_message(st('Vocabulary Index has been enabled. Please proceed to <a href="!settings">the settings page</a> and <a href="!permissions">set up the permissions</a> to get started.', array('!settings' => url(_vocabindex_menu_paths('admin_settings')), '!permissions' => url('admin/user/permissions', array('fragment' => 'module-vocabindex')))));
   if (count(taxonomy_get_vocabularies()) == 0) {
     drupal_set_message(st('You have not yet got any vocabularies to create index pages for. You can create them at <a href="!link">the Taxonomy page</a>.', array('!link' => url(_vocabindex_menu_paths('taxonomy')))));
   }
+}
+
+/**
+ * Implementation of hook_update_N().
+ *
+ * Update the DB from Vocabulary Index 6.x-1.x to 6.x-2.x.
+ */
+function vocabindex_update_6200() {
+  // Get old VI data.
+  $result = db_query("SELECT * FROM {vocabindex}");
+  while ($vi_old = db_fetch_object($result)) {
+    $vi_paths[$vi_old->vid] = $vi_old->path;
+  }
+
+  $ret = array();
+
+  // Drop the old table and create the new one.
+  db_drop_table($ret, 'vocabindex');
+  $schema = vocabindex_schema();
+  db_create_table($ret, 'vocabindex', $schema['vocabindex']);
+
+  // Create new VIs and populate them with possible old data.
+  module_load_include('inc', 'vocabindex', 'vocabindex.admin');
+  if (variable_get('vocabindex_list_style', 'threaded') == 'flat') {
+    $view = VOCABINDEX_VIEW_FLAT;
+  }
+  else {
+    $view = VOCABINDEX_VIEW_TREE;
+  }
+  vocabindex_create_vis();
+  $vis = vocabindex_index_load(VOCABINDEX_VOC_PAGES);
+  for ($i = 0, $len_i = count($vis); $i < $len_i; $i++) {
+    $vi = $vis[$i];
+    $vi->path = $vi_paths[$vi->vid];
+    $vi->enabled = TRUE;
+    $vi->view = $view;
+    vocabindex_index_save($vi);
+  }
+
+  // Delete old variables and menu items.
+  $stylesheet = variable_get('vocabindex_stylesheet', TRUE);
+  vocabindex_delete_variables();
+  variable_set('vocabindex_stylesheet', $stylesheet);
+  vocabindex_delete_menu_items();
+
+  // Delete the update status flag. Only necessary for the latest hook_update_N implementation.
+  variable_del('vocabindex_schema_update', TRUE);
+
+  return $ret;
+}
+
+/**
+ * Create VIs from all vocabularies.
+ *
+ * Used after an update or installation.
+ */
+function vocabindex_create_vis() {
+  module_load_include('module', 'vocabindex');
+  $vocs = taxonomy_get_vocabularies();
+  foreach ($vocs as $voc) {
+    vocabindex_index_create($voc->vid);
+  }
+}
+
+/**
+ * Delete all Vocabulary Index variables.
+ */
+function vocabindex_delete_variables() {
+  db_query("DELETE FROM {variable} WHERE name LIKE 'vocabindex_%'");
+  cache_clear_all('variables', 'cache');
+}
+
+/**
+ * Delete all VI menu items.
+ */
+function vocabindex_delete_menu_items() {
+  // NOTE: necessary to fix menu item bug? See vocabindex issue. -Xano.
+  menu_cache_clear_all();
 }
\ No newline at end of file
Index: vocabindex/vocabindex.module
===================================================================
RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.module,v
retrieving revision 1.1.2.5.2.46
diff -u -p -r1.1.2.5.2.46 vocabindex.module
--- vocabindex/vocabindex.module	6 Sep 2008 18:22:03 -0000	1.1.2.5.2.46
+++ vocabindex/vocabindex.module	17 Sep 2008 18:18:39 -0000
@@ -91,12 +91,26 @@ function _vocabindex_menu_paths($section
  */
 function vocabindex_perm() {
   return array('view vocabulary index', 'administer vocabulary index');
+}
+
+/**
+ * Implementation of hook_init().
+ */
+function vocabindex_init() {
+  if (vocabindex_check_schema_version() == FALSE) {
+    $path = base_path() . 'update.php';
+    drupal_set_message(t("Please proceed to !update.php to update your database to Vocabulary Index 2.", array('!update.php' => '<a href="' . $path . '">update.php</a>')), 'error');
+  }
 }
 
 /**
  * Implementation of hook_menu().
  */
 function vocabindex_menu() {
+  if (vocabindex_check_schema_version() == FALSE) {
+    return;
+  }
+
   $items[_vocabindex_menu_paths('admin_main')] = array(
     'title' => 'Vocabulary Index',
     'description' => 'Create index pages for vocabularies.',
@@ -136,37 +150,34 @@ function vocabindex_menu() {
     'weight' => 2,
   );
 
-  // Prevent the DB request if the module doesn't exist anymore. Without this prevention this code would cause an error right after uninstalling the module.
-  if (module_exists('vocabindex')) {
-    // Load all VIs
-    $vis = vocabindex_index_load(VOCABINDEX_VI_PAGE);
-    for ($i = 0, $len_i = count($vis); $i < $len_i; $i++) {
-      $vi = $vis[$i];
-      // Menu callbacks for every vocabindex page
-      // We need to cast out constant to a string, because the integer will otherwise be replaced with the corresponding part of the menu path
-      $type = (string) VOCABINDEX_VOC;
-
-      $item = array(
-        'title' => $vi->name,
-        'description' => check_plain($vi->description),
-        'access arguments' => array('view vocabulary index'),
-        'page callback' => 'vocabindex_view_page',
-        'page arguments' => array($vi->vid, $type),
-        'type' => MENU_CALLBACK,
-        'file' => 'vocabindex.view.inc',
-      );
-
-      // The regular menu item
-      $items[$vi->path] = $item;
-
-      // The menu item for alphabetical indices using the letter wildcard
-      if ($vi->view == VOCABINDEX_VIEW_ALPHABETICAL) {
-        $arg = (int) substr_count($vi->path, '/') + 1;
-        $path = $vi->path . '/%vocabindex_letter';
-        $items[$path] = $item;
-        $items[$path]['page arguments'][2] = $arg;
-      }
-    }
+  // Load all VIs
+  $vis = vocabindex_index_load(VOCABINDEX_VI_PAGE);
+  for ($i = 0, $len_i = count($vis); $i < $len_i; $i++) {
+    $vi = $vis[$i];
+    // Menu callbacks for every vocabindex page
+    // We need to cast out constant to a string, because the integer will otherwise be replaced with the corresponding part of the menu path
+    $type = (string) VOCABINDEX_VOC;
+
+    $item = array(
+      'title' => $vi->name,
+      'description' => check_plain($vi->description),
+      'access arguments' => array('view vocabulary index'),
+      'page callback' => 'vocabindex_view_page',
+      'page arguments' => array($vi->vid, $type),
+      'type' => MENU_CALLBACK,
+      'file' => 'vocabindex.view.inc',
+    );
+
+    // The regular menu item
+    $items[$vi->path] = $item;
+
+    // The menu item for alphabetical indices using the letter wildcard
+    if ($vi->view == VOCABINDEX_VIEW_ALPHABETICAL) {
+      $arg = (int) substr_count($vi->path, '/') + 1;
+      $path = $vi->path . '/%vocabindex_letter';
+      $items[$path] = $item;
+      $items[$path]['page arguments'][2] = $arg;
+    }
   }
 
   return $items;
@@ -178,6 +189,10 @@ function vocabindex_menu() {
  * Used for creating the term index callbacks.
  */
 function vocabindex_menu_alter(&$items) {
+  if (vocabindex_check_schema_version() == FALSE) {
+    return;
+  }
+
   // Load all VIs
   $vis = vocabindex_index_load(VOCABINDEX_VI_PAGE);
   for ($i = 0, $len_i = count($vis); $i < $len_i; $i++) {
@@ -383,6 +398,29 @@ function vocabindex_help($path, $arg) {
   return $output;
 }
 
+
+/**
+ * Check if the latest DB updates for this module have been performed.
+ */
+function vocabindex_check_schema_version() {
+  if (!is_null(variable_get('vocabindex_schema_update', NULL))) {
+    return variable_get('vocabindex_schema_update', NULL);
+  }
+  elseif (module_exists('vocabindex')) {
+    require_once('./includes/install.inc');
+    $current = drupal_get_installed_schema_version('vocabindex');
+    // $available should have the value of the latest DB update available in this
+    // version of Vocabulary Index. Manually declaring this value improves
+    // performance, because vocabindes.install doesn't need to be called at every
+    // menu rebuild.
+    $available = 6200;
+    $uptodate = $current < $available ? FALSE : TRUE;
+    variable_set('vocabindex_schema_update', $uptodate);
+
+    return $uptodate;
+  }
+}
+
 /**
  * Template preprocessor for list items.
  *
@@ -456,8 +494,8 @@ function vocabindex_index_create($vid) {
  * @return
  *   Type: array/object; An associative array (keys are VOCABINDEX_VI_PAGE and VOCABINDEX_VI_BLOCK)
  *   possibly containing two VI objects (When selecting by VOCABINDEX_VI_VID) or an array containing
- *   multiple VI objects (When selecting by VOCABINDEX_VI_PAGE, VOCABINDEX_VI_BLOCK, VOCABINDEX_VOC_PAGE
- *   or VOCABINDEX_VOC_BLOCK).
+ *   multiple VI objects (When selecting by VOCABINDEX_VI_PAGE, VOCABINDEX_VI_BLOCK, VOCABINDEX_VOC_PAGES
+ *   or VOCABINDEX_VOC_BLOCKS).
  */
 function vocabindex_index_load($select, $vid = 0) {
   if ($select == VOCABINDEX_VOC_PAGES || $select == VOCABINDEX_VOC_BLOCKS) {
