From 91e03c4ab7ef1b8d4afe634ef6943cb7719bd064 Mon Sep 17 00:00:00 2001 From: Marco Villegas Date: Wed, 22 Aug 2012 11:16:28 -0500 Subject: [PATCH] Initial upgrade from vud_node. --- vud.install | 70 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 70 insertions(+) diff --git a/vud.install b/vud.install index 9bdc1cd..9b5fd39 100644 --- a/vud.install +++ b/vud.install @@ -42,3 +42,73 @@ function vud_update_7000() { menu_rebuild(); return $result; } + +/** + * Upgrades vud_{node,comment,term} data to vud_field. + */ +function vud_update_7001() { + $messages = array(); + // Retrieve global configurations. + $vud_tag = variable_get('vud_tag', 'vote'); + // Enable vud_field and create a vud_field to use. + if (!module_enable(array('vud_field'))) { + throw new DrupalUpdateException('Cannot enable vud_field.'); + } + field_cache_clear(); + field_associate_fields('vud_field'); + $vud_field = array( + 'field_name' => 'field_vud', + 'type' => 'vud_field', + ); + field_create_field($vud_field); + + // Migrate vud_node data into vud_field. + $node_bundles = array_filter(variable_get('vud_node_types', array())); + if (empty($node_bundles)) { + $messages[] = t('There is no data to be migrated from vud_node to vud_field.'); + } + else { + $node_widget = variable_get('vud_node_widget', 'plain'); + $node_widget_visibility = variable_get('vud_node_widget_show', 3); + $display = array( + 'default' => array('label' => 'hidden'), + 'teaser' => array('label' => 'hidden'), + ); + switch ($node_widget_visibility) { + // VUD_NODE_DISPLAY_TEASER_ONLY + case 1: + $display['default']['type'] = 'hidden'; + break; + // VUD_NODE_DISPLAY_FULL_ONLY + case 2: + $display['teaser']['type'] = 'hidden'; + break; + // VUD_NODE_DISPLAY_BOTH + case 3: + default: + // Nothing to do, it's the default. + break; + } + foreach ($node_bundles as $bundle_name) { + // Create a field instance per node bundle. + $instance = array( + 'field_name' => $vud_field['field_name'], + 'entity_type' => 'node', + 'bundle' => $bundle_name, + 'settings' => array( + 'vud_widget' => $node_widget, + 'votingapi_tag' => $vud_tag, + ), + 'display' => $display, + ); + field_create_instance($instance); + } + $messages[] = t('Vote Up/Down Nodes information was migrated to Vote Up/Down field fields on node types @bundles', array('@bundles' => implode(',', $node_bundles))); + } + + $list_variables = array( + 'title' => t('Vote Up/Down migration from node/comment/term submodules to field submodule.'), + 'items' => $messages, + ); + return theme('item_list', $list_variables); +} -- 1.7.10.4