? .DS_Store ? vi_storage_00.patch ? vi_storage_01.patch ? vi_storage_02.patch Index: vocabindex.admin.inc =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.admin.inc,v retrieving revision 1.1.2.3.2.62 diff -u -p -r1.1.2.3.2.62 vocabindex.admin.inc --- vocabindex.admin.inc 17 Jun 2009 09:21:44 -0000 1.1.2.3.2.62 +++ vocabindex.admin.inc 17 Jun 2009 13:17:30 -0000 @@ -149,7 +149,7 @@ function vocabindex_path_validate($eleme * Type: string; Either a rendered form or an empty string. */ function vocabindex_admin_vi($type) { - if (count(vocabindex_vi_load($type, 0, FALSE))) { + if (count(taxonomy_get_vocabularies())) { return drupal_get_form('vocabindex_admin_vi_form', $type); } else { @@ -175,17 +175,18 @@ function vocabindex_admin_vi($type) { * Type: array; A Drupal form. */ function vocabindex_admin_vi_form($form, $type) { - $vis = vocabindex_vi_load($type, 0, FALSE); + $vocs = taxonomy_get_vocabularies(); + $vis = vocabindex_vi_load($type, 0); $form = array(); - foreach ($vis as $vi) { - $id = 'vocabindex_' . $vi->vid . '_'; + foreach ($vocs as $voc) { + $vi = isset($vis[$voc->vid]) ? $vis[$voc->vid] : FALSE; + $id = 'vocabindex_' . $voc->vid . '_'; $form[$id . 'name'] = array( - '#value' => check_plain($vi->name), + '#value' => check_plain($voc->name), ); - if ($type == VOCABINDEX_VI_PAGE) { - if ($vi->enabled) { + if ($vi) { $description = t('Currently located at !location.', array('!location' => l('/' . $vi->path, $vi->path))); } else { @@ -195,7 +196,7 @@ function vocabindex_admin_vi_form($form, $form[$id . 'path'] = array( '#type' => 'textfield', '#description' => $description, - '#default_value' => check_plain($vi->path), + '#default_value' => $vi ? check_plain($vi->path) : NULL, '#maxlength' => '255', '#size' => 30, '#element_validate' => array('vocabindex_path_validate'), @@ -204,13 +205,12 @@ function vocabindex_admin_vi_form($form, elseif ($type == VOCABINDEX_VI_BLOCK) { $form[$id . 'enabled'] = array( '#type' => 'checkbox', - '#default_value' => $vi->enabled, + '#default_value' => $vi ? TRUE : FALSE, ); } - $default_value = !is_null($vi->view) ? $vi->view : VOCABINDEX_VIEW_TREE; $options = array(VOCABINDEX_VIEW_TREE => t('Tree')); - if ($vi->type == VOCABINDEX_VI_PAGE) { + if ($type == VOCABINDEX_VI_PAGE) { $options[VOCABINDEX_VIEW_FLAT] = t('Browsable'); $options[VOCABINDEX_VIEW_ALPHABETICAL] = t('Alphabetical'); } @@ -219,13 +219,13 @@ function vocabindex_admin_vi_form($form, } $form[$id . 'view'] = array( '#type' => 'select', - '#default_value' => $default_value, + '#default_value' => $vi ? $vi->view : VOCABINDEX_VIEW_TREE, '#options' => $options, ); $form[$id . 'node_count'] = array( '#type' => 'checkbox', - '#default_value' => $vi->node_count, + '#default_value' => $vi ? $vi->node_count : FALSE, ); } @@ -250,18 +250,28 @@ function vocabindex_admin_vi_form($form, */ function vocabindex_admin_vi_form_submit($form, &$form_state) { $values = $form_state['values']; - $vis = vocabindex_vi_load($values['vocabindex_type'], 0, FALSE); - foreach ($vis as $vi) { - $id = 'vocabindex_' . $vi->vid . '_'; - - $vi->path = array_key_exists($id . 'path', $values) ? preg_replace('#^/|/$#', '', drupal_strtolower($values[$id . 'path'])) : NULL; - $vi->view = $values[$id . 'view']; - $vi->node_count = $values[$id . 'node_count']; - $vi->enabled = isset($values[$id . 'enabled']) && $values[$id . 'enabled'] == TRUE || !empty($values[$id . 'path']) ? TRUE : FALSE; + $vocs = taxonomy_get_vocabularies(); + foreach ($vocs as $voc) { + $id = 'vocabindex_' . $voc->vid . '_'; + + if (isset($values[$id . 'enabled']) && $values[$id . 'enabled'] == TRUE || !empty($values[$id . 'path'])) { + $vi = (object) array( + 'vid' => $voc->vid, + 'type' => $values['vocabindex_type'], + 'path' => array_key_exists($id . 'path', $values) ? preg_replace('#^/|/$#', '', drupal_strtolower($values[$id . 'path'])) : NULL, + 'view' => $values[$id . 'view'], + 'node_count' => $values[$id . 'node_count'], + ); - vocabindex_vi_save($vi); + vocabindex_vi_save($vi); + } + else { + vocabindex_vi_delete($voc->vid); + } } + // Reset the static VI cache to rebuild the menu. + vocabindex_vi_load(0, 0, TRUE); menu_rebuild(); drupal_set_message(t('The configuration options have been saved.')); @@ -276,8 +286,7 @@ function vocabindex_admin_vi_form_submit * Type: object; The VI to save. */ function vocabindex_vi_save($vi) { - db_query("UPDATE {vocabindex} SET path = '%s', view = %d, node_count = %d, enabled = %d WHERE vid = %d AND type = %d", $vi->path, $vi->view, $vi->node_count, $vi->enabled, $vi->vid, $vi->type); - if ($vi->type == VOCABINDEX_VI_BLOCK && $vi->enabled == FALSE) { - db_query("DELETE FROM {blocks} WHERE module = 'vocabindex' AND delta = %d", $vi->vid); - } + $vi_exists = db_result(db_query("SELECT COUNT(*) FROM {vocabindex} WHERE vid = %d AND type = %d", $vi->vid, $vi->type)); + $update = $vi_exists ? 'vid' : array(); + return drupal_write_record('vocabindex', $vi, $update); } \ No newline at end of file Index: vocabindex.install =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.install,v retrieving revision 1.1.2.3.4.30 diff -u -p -r1.1.2.3.4.30 vocabindex.install --- vocabindex.install 19 Dec 2008 00:01:07 -0000 1.1.2.3.4.30 +++ vocabindex.install 17 Jun 2009 13:17:30 -0000 @@ -22,8 +22,6 @@ 'size' => 'tiny', 'default' => 0, ), 'type' => array( 'description' => t('Index page or index block.'), 'type' => 'int', 'size' => 'tiny', - 'default' => 0, ), 'enabled' => array( 'description' => t('Indicates whether this index is enabled or not.'), 'type' => 'int', - 'size' => 'tiny', 'default' => 0, ), ), 'indexes' => array( @@ -87,8 +85,9 @@ function vocabindex_update_6200() { // Get old VI data. $result = db_query("SELECT * FROM {vocabindex}"); + $vis_old = array(); while ($vi_old = db_fetch_object($result)) { - $vi_paths[$vi_old->vid] = $vi_old->path; + $vis_old[] = $vi_old; } // Drop the old table and create the new one. @@ -104,13 +103,9 @@ function vocabindex_update_6200() { else { $view = VOCABINDEX_VIEW_TREE; } - vocabindex_create_vis(); - $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE, 0, FALSE); - foreach ($vis as $vi) { - $vi = $vis[$i]; - $vi->path = $vi_paths[$vi->vid]; - $vi->enabled = TRUE; + foreach ($vis_old as $vi) { $vi->view = $view; + $vi->type = VOCABINDEX_VI_PAGE; vocabindex_vi_save($vi); } @@ -129,16 +124,15 @@ function vocabindex_update_6200() { } /** - * Create VIs from all vocabularies. + * Implementation of hook_update_N(). * - * Used after an update or installation. + * Drop the 'enabled' column in {vocabindex}. */ -function vocabindex_create_vis() { - module_load_include('module', 'vocabindex'); - $vocs = taxonomy_get_vocabularies(); - foreach ($vocs as $voc) { - vocabindex_vi_create($voc->vid); - } +function vocabindex_update_6201() { + $ret = array(); + db_drop_field($ret, 'vocabindex', 'enabled'); + + return $ret; } /** Index: vocabindex.module =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/vocabindex.module,v retrieving revision 1.1.2.5.2.83 diff -u -p -r1.1.2.5.2.83 vocabindex.module --- vocabindex.module 14 Jun 2009 19:54:16 -0000 1.1.2.5.2.83 +++ vocabindex.module 17 Jun 2009 13:17:30 -0000 @@ -114,22 +114,23 @@ function vocabindex_menu() { ); // VI pages. - $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE); - foreach ($vis as $vi) { - $item = vocabindex_menu_base() + array( - 'title' => $vi->name, - 'description' => check_plain($vi->description), - // We need to cast out the constant to a string, because the integer will - // otherwise be replaced with the corresponding part of the menu path. - 'page arguments' => array($vi->vid, (string) VOCABINDEX_VOC), - ); - // The menu item for alphabetical VIs using the letter wildcard. - if ($vi->view == VOCABINDEX_VIEW_ALPHABETICAL) { - $arg = (int) substr_count($vi->path, '/') + 1; - $path = $vi->path . '/%vocabindex_letter'; - $item['page arguments'][2] = $arg; + if ($vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE)) { + foreach ($vis as $vi) { + $item = vocabindex_menu_base() + array( + 'title' => $vi->name, + 'description' => check_plain($vi->description), + // We need to cast out the constant to a string, because the integer will + // otherwise be replaced with the corresponding part of the menu path. + 'page arguments' => array($vi->vid, (string) VOCABINDEX_VOC), + ); + // The menu item for alphabetical VIs using the letter wildcard. + if ($vi->view == VOCABINDEX_VIEW_ALPHABETICAL) { + $arg = (int) substr_count($vi->path, '/') + 1; + $path = $vi->path . '/%vocabindex_letter'; + $item['page arguments'][2] = $arg; + } + $items[$vi->path] = $item; } - $items[$vi->path] = $item; } return $items; @@ -142,22 +143,23 @@ function vocabindex_menu() { * index pages. */ function vocabindex_menu_alter(&$items) { - $vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE); - foreach ($vis as $vi) { - if ($vi->view == VOCABINDEX_VIEW_FLAT) { - $tree = taxonomy_get_tree($vi->vid); - $children = vocabindex_get_children($tree); - foreach ($tree as $term) { - // Check if the current term is a parent. - if (isset($children[$term->tid])) { - $items['taxonomy/term/' . $term->tid] = vocabindex_menu_base() + array( - 'title' => $term->name, - 'description' => check_plain($term->description), - // We need to cast our integer constant to a string, because the - // integer will otherwise be replaced with the corresponding part - // of the menu path. - 'page arguments' => array($term->tid, (string) VOCABINDEX_TERM), - 'file path' => drupal_get_path('module', 'vocabindex'), ); + if ($vis = vocabindex_vi_load(VOCABINDEX_VI_PAGE)) { + foreach ($vis as $vi) { + if ($vi->view == VOCABINDEX_VIEW_FLAT) { + $tree = taxonomy_get_tree($vi->vid); + $children = vocabindex_get_children($tree); + foreach ($tree as $term) { + // Check if the current term is a parent. + if (isset($children[$term->tid])) { + $items['taxonomy/term/' . $term->tid] = vocabindex_menu_base() + array( + 'title' => $term->name, + 'description' => check_plain($term->description), + // We need to cast our integer constant to a string, because the + // integer will otherwise be replaced with the corresponding part + // of the menu path. + 'page arguments' => array($term->tid, (string) VOCABINDEX_TERM), + 'file path' => drupal_get_path('module', 'vocabindex'), ); + } } } } @@ -243,15 +245,8 @@ function vocabindex_theme($existing, $ty * Implementation of hook_taxonomy(). */ function vocabindex_taxonomy($op, $type, $array) { - $vid = $array['vid']; - - if ($type == 'vocabulary') { - if ($op == 'delete') { - vocabindex_vi_delete($vid); - } - elseif ($op == 'insert') { - vocabindex_vi_create($vid); - } + if ($type == 'vocabulary' && $op == 'delete') { + vocabindex_vi_delete($array['vid']); menu_rebuild(); } } @@ -419,29 +414,16 @@ function vocabindex_vi_delete($vid = 0) if ($vid == 0) { // Delete all VIs db_query("DELETE FROM {vocabindex}"); + db_query("DELETE FROM {blocks} WHERE module = 'vocabindex'"); } else { // Delete all VIs matching a VID db_query("DELETE FROM {vocabindex} WHERE vid = %d", $vid); + db_query("DELETE FROM {blocks} WHERE module = 'vocabindex' AND delta = %d", $vid); } } /** - * Create two VIs (Page and Block) for a certain vocabulary. - * - * This function must be called when the module is being installed or when a new - * vocabulary has been created. Note that created VIs are not yet enabled. - * - * @ingroup vi_management - * - * @param $vid - * Type: integer; The VID of the vocabulary to create the VIs for. - */ -function vocabindex_vi_create($vid) { - db_query("INSERT INTO {vocabindex} (vid, type) VALUES (%d, %d), (%d, %d)", $vid, VOCABINDEX_VI_PAGE, $vid, VOCABINDEX_VI_BLOCK); -} - -/** * Load the vocabindex settings for a given index. * * The first time this function is called it will get vocabularies and matching @@ -456,16 +438,20 @@ function vocabindex_vi_create($vid) { * @param $vid * Type: integer; The VID of the vocabulary index to get the settings for. * 0 (zero) to select all VIs. - * @param $enabled - * Type: boolean; Whether to return all VIs or just the enabled ones. + * @param $reset + * Type: boolean; TRUE to reset the static cache of VIs. * * @return * Type: array/object; An array containing all requested VI objects or just * one VI object. */ -function vocabindex_vi_load($type, $vid = 0, $enabled = TRUE) { +function vocabindex_vi_load($type = NULL, $vid = 0, $reset = TRUE) { static $vis = array(); + if ($reset) { + $vis = array(); + } + if (empty($vis)) { $result = db_query(db_rewrite_sql("SELECT vi.*, v.name, v.description FROM {vocabindex} vi LEFT JOIN {vocabulary} v ON vi.vid = v.vid ORDER BY v.name, v.weight ASC", 'v', 'vid')); while ($vi = db_fetch_object($result)) { @@ -482,28 +468,15 @@ function vocabindex_vi_load($type, $vid } // Check for the requested VIDs. - if ($vid != 0) { - $selection = array($vis[$type][$vid]); + if ($vid != 0 && isset($vis[$type][$vid])) { + return $vis[$type][$vid]; } - else { - $selection = $vis[$type]; - } - - // Select all VIs or just the enabled ones depending on $enabled. - if ($enabled) { - $buffer = array(); - foreach ($selection as $vi) { - if ($vi->enabled) { - $buffer[] = $vi; - } - } - $return = $buffer; + elseif (isset($vis[$type])) { + return $vis[$type]; } else { - $return = array_values($selection); + return FALSE; } - - return $vid == 0 ? $return : array_shift($return); } /** Index: theme/vocabindex_admin_vi_form.tpl.php =================================================================== RCS file: /cvs/drupal-contrib/contributions/modules/vocabindex/theme/Attic/vocabindex_admin_vi_form.tpl.php,v retrieving revision 1.1.2.8 diff -u -p -r1.1.2.8 vocabindex_admin_vi_form.tpl.php --- theme/vocabindex_admin_vi_form.tpl.php 19 Oct 2008 10:52:59 -0000 1.1.2.8 +++ theme/vocabindex_admin_vi_form.tpl.php 17 Jun 2009 13:17:30 -0000 @@ -9,10 +9,10 @@ * $form The Drupal form to render. */ $type = $form['vocabindex_type']['#value']; -$vis = vocabindex_vi_load($type, 0, FALSE); +$vocs = taxonomy_get_vocabularies(); $rows = array(); -foreach ($vis as $vi) { - $id = 'vocabindex_' . $vi->vid . '_'; +foreach ($vocs as $voc) { + $id = 'vocabindex_' . $voc->vid . '_'; // Common form fields. $name = drupal_render($form[$id . 'name']);