fields(array( 'weight' => 20, )) ->condition('name', 'cdm_dataportal') ->execute(); } /** * Implements hook_uninstall(). */ function cdm_dataportal_uninstall() { // Delete all nodes with a cdm content type from the node table. // Comment @WA: you also may want to delete these content types from the // node_type table. db_delete('node') ->condition('type', 'cdm_%') ->execute(); } /* * update functions: * * - 1 digit for Drupal core compatibility. * - 1 digit for your module's major release version (e.g., is this the 7.x-1.* (1) or 7.x-2.* (2) series of your module?). This digit should be 0 for initial porting of your module to a new Drupal core API. * - 2 digits for sequential counting, starting with 00. * * @see http://api.drupal.org/api/drupal/modules!system!system.api.php/function/hook_update_N/7 */ /** * update for RELEASE 3.1.3: * - reset edit_map_server variable to default */ function cdm_dataportal_update_7301() { // reset edit_map_server variable to default return _remove_variable('edit_map_server'); } /** * update for RELEASE 3.1.4: * - reset edit_map_server variable to default */ function cdm_dataportal_update_7302() { return _remove_variable('edit_map_server') . // once again reset edit_map_server variable to default _rename_variable('cdm_dataportal_show_media', 'cdm_images_include_children'); } /** * update for RELEASE 3.2.1: * - adding missing permissions for role CDM Admin */ function cdm_dataportal_update_7303() { $role = user_role_load_by_name('CDM admin'); if(!$role){ return "Role CDM admin not found, so the update is skipped."; } $tasks_performed = array(); // permissions for node types $node_type_names = node_type_get_names(); $types_to_update = array('page', 'story', 'article'); foreach ($types_to_update as $name){ if(in_array($name, $node_type_names)) { $node_type_permissions = array( 'create ' . $name . ' content', 'edit any ' . $name . ' content', 'edit own ' . $name . ' content', 'delete any ' . $name . ' content', 'delete own ' . $name . ' content', ); user_role_grant_permissions($role->rid, $node_type_permissions); $tasks_performed[] = "node type " . $name; } } foreach (filter_formats() as $key=>$format){ if($key == 'full_html' || $format->format == "Full HTML"){ $formats_permissions = array( 'use text format full_html' ); user_role_grant_permissions($role->rid, $formats_permissions); $tasks_performed[] = 'use text format full_html'; } } // assure 'create url aliases' can be set if(!module_exists('path')){ module_enable(array('path'), TRUE); $tasks_performed[] = 'module path enabled'; } $other_permissions = array( 'create url aliases', 'delete revisions', 'revert revisions', 'view own unpublished content', 'flush caches' ); user_role_grant_permissions($role->rid, $other_permissions); $tasks_performed[] = 'and other permissions'; return "adding missing permissions for role CDM Admin: " . join(', ', $tasks_performed); } /** * update for RELEASE 3.2.2: * - migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image['show'] * - enabling required module file * - enable new debug block for all dataportals * - migrating variables for map settings */ function cdm_dataportal_update_7304() { module_enable(array('file'), TRUE); $tasks_performed[] = 'module file enabled'; if(!variable_get(CDM_TAXON_PROFILE_IMAGE, FALSE)){ $cdm_taxon_profile_image_settings = unserialize(CDM_TAXON_PROFILE_IMAGE_DEFAULT); $cdm_taxon_profile_image_settings['show'] = variable_get('cdm_dataportal_show_default_image', 0); variable_set(CDM_TAXON_PROFILE_IMAGE, $cdm_taxon_profile_image_settings); variable_del('cdm_dataportal_show_default_image'); $tasks_performed[] = 'migrating variable cdm_dataportal_show_default_image to cdm_taxon_profile_image[\'show\']'; } // CDM web service debug block $cdm_ws_debug_block = array( 'block' => array( 'module' => 'cdm_api', 'delta' => 'cdm_ws_debug', 'theme' => NULL, 'status' => 1, 'weight' => -50, 'region' => 'sidebar_first', 'pages' => '', 'cache' => -1, ), 'block_role' => array( ) ); $admin_user = user_load(1); // harmonize cdm admin role names if needed $cdm_admin_role = user_role_load_by_name('CDM Admin'); if(is_object($cdm_admin_role) && $cdm_admin_role->name !== 'CDM admin'){ $cdm_admin_role->name = 'CDM admin'; user_role_save($cdm_admin_role); $tasks_performed[] = $cdm_admin_role->name . ' role name harmonized'; } $cdm_admin_role = user_role_load_by_name('CDM admin'); if(is_object($cdm_admin_role)) { // make sure admin is member of role CDM admin if (!isset($admin_user->roles[$cdm_admin_role->rid])) { user_multiple_role_edit(array(1), 'add_role', $cdm_admin_role->rid); $tasks_performed[] = 'admin user (uid=1) added to role ' . $cdm_admin_role->name; } $cdm_ws_debug_block['block_role'][] = array( 'module' => 'cdm_api', 'delta' => 'cdm_ws_debug', 'rid' => $cdm_admin_role->rid ); } $admin_role = user_role_load_by_name("admin"); // Drupal 5 if(is_object($admin_role)){ $admin_role->name = 'administrator'; user_role_save($admin_role); $tasks_performed[] = 'administrator role name harmonized'; } else { $admin_role = user_role_load_by_name("administrator"); // Drupal 7 } if(is_object($admin_role)){ // make sure admin is member of role admin if (!isset($admin_user->roles[$admin_role->rid])) { user_multiple_role_edit(array(1), 'add_role', $admin_role->rid); $tasks_performed[] = 'admin user (uid=1) added to role ' . $admin_role->name; } $cdm_ws_debug_block['block_role'][] = array( 'module' => 'cdm_api', 'delta' => 'cdm_ws_debug', 'rid' => $admin_role->rid ); } // clean up existing block configuration which might be set by drupal automatically, we need to override this db_delete('block')->condition('module', 'cdm_api')->execute(); db_delete('block_role')->condition('module', 'cdm_api')->execute(); // insert $block_insert = db_insert('block')->fields(array('module', 'delta', 'theme', 'status', 'weight', 'region', 'pages', 'cache')); $block_role_insert = db_insert('block_role')->fields(array('module', 'delta', 'rid')); $themes = system_list('theme'); foreach ($themes as $theme) { if($theme->status == "1"){ // only for enabled themes $cdm_ws_debug_block['block']['theme'] = $theme->name; $block_insert->values($cdm_ws_debug_block['block']); } } foreach($cdm_ws_debug_block['block_role'] as $block_role){ $block_role_insert->values($block_role); } $block_insert->execute(); $block_role_insert->execute(); $tasks_performed[] = 'CDM web service debug block enabled for \'CDM admin\' users in all themes'; $tasks_performed[] = _remove_variable('cdm_webservice_debug'); $tasks_performed[] = _remove_variable('cdm_webservice_isStub'); /* * migrating variables for map settings */ $cdm_map_distribution = array(); $cdm_map_distribution['width'] = variable_get('cdm_dataportal_geoservice_display_width', 390); $cdm_map_distribution['height'] = $cdm_map_distribution['width'] / 2; _remove_variable('cdm_dataportal_geoservice_display_width'); $cdm_map_distribution['bbox'] = variable_get('cdm_dataportal_geoservice_bounding_box', '-180,-90,180,90'); _remove_variable('cdm_dataportal_geoservice_bounding_box'); $cdm_map_distribution['show_labels'] = variable_get('cdm_dataportal_geoservice_labels_on', FALSE); _remove_variable('cdm_dataportal_geoservice_labels_on'); $cdm_map_distribution['caption'] = variable_get('cdm_dataportal_geoservice_map_caption', ''); _remove_variable('cdm_dataportal_geoservice_map_caption'); $cdm_map_distribution['distribution_opacity'] = variable_get('cdm_dataportal_geoservice_distributionOpacity', '0.5'); _remove_variable('cdm_dataportal_geoservice_distributionOpacity'); $cdm_map_distribution['mapType'] = variable_get('cdm_dataportal_map_openlayers', 1); _remove_variable('cdm_dataportal_map_openlayers'); // imageMap $cdm_map_distribution['image_map'] = array(); $cdm_map_distribution['image_map']['base_layer']= variable_get('map_base_layer', 'cyprusdivs'); _remove_variable('map_base_layer'); $cdm_map_distribution['image_map']['bg_color'] = variable_get('map_bg_color', '1874CD'); _remove_variable('map_bg_color'); $cdm_map_distribution['image_map']['layer_style'] = variable_get('map_base_layer_style', 'ffffff,606060,,'); _remove_variable('map_base_layer_style'); // OpenLayers $cdm_map_distribution['openlayers'] = array(); $cdm_map_distribution['openlayers']['base_layers'] = variable_get('baselayers', array('mapproxy_vmap0' => 'mapproxy_vmap0', 'PREFERRED' => 'mapproxy_vmap0')); _remove_variable('baselayers'); $cdm_map_distribution['openlayers']['show_layer_switcher'] = variable_get('cdm_dataportal_geoservice_showLayerSwitcher', TRUE); _remove_variable('cdm_dataportal_geoservice_showLayerSwitcher'); $cdm_map_distribution['legend'] = array(); $cdm_map_distribution['legend']['show'] = variable_get('cdm_dataportal_geoservice_legend_on', TRUE); _remove_variable('cdm_dataportal_geoservice_legend_on'); $cdm_map_distribution['legend']['opacity'] = variable_get('cdm_dataportal_geoservice_legendOpacity', '0.5'); _remove_variable('cdm_dataportal_geoservice_legendOpacity'); $cdm_map_distribution['legend']['font_size'] = variable_get('cdm_dataportal_geoservice_legend_font_size', 10); _remove_variable('cdm_dataportal_geoservice_legend_font_size'); $cdm_map_distribution['legend']['font_style'] = variable_get('cdm_dataportal_geoservice_legend_font_style', FALSE); _remove_variable('cdm_dataportal_geoservice_legend_font_style'); $cdm_map_distribution['legend']['icon_width'] = variable_get('cdm_dataportal_geoservice_legend_icon_width', 35); _remove_variable('cdm_dataportal_geoservice_legend_icon_width'); $cdm_map_distribution['legend']['icon_height'] = variable_get('cdm_dataportal_geoservice_legend_icon_height', 15); _remove_variable('cdm_dataportal_geoservice_legend_icon_height'); variable_set('cdm_map_distribution', $cdm_map_distribution); $tasks_performed[] = 'variables for map settings migrated to new variable "cdm_map_distribution"'; return join(', ',$tasks_performed); } /** * update for RELEASE 3.2.3: * - remove variable 'cdm_search_use_default_values' */ function cdm_dataportal_update_7305() { $tasks_performed = array(); $tasks_performed[] = _remove_variable('cdm_search_use_default_values'); return join(', ',$tasks_performed); } /** * update for RELEASE 3.7.0: * - add 'custom_placeholder_enabled' to 'cdm_taxon_profile_image' */ function cdm_dataportal_update_7306() { $tasks_performed = array(); $cdm_taxon_profile_image = variable_get('cdm_taxon_profile_image'); if(!isset($cdm_taxon_profile_image['custom_placeholder_enabled'])){ $cdm_taxon_profile_image['custom_placeholder_enabled'] = 1; } $tasks_performed[] = _create_variable('cdm_taxon_profile_image', $cdm_taxon_profile_image); return join(', ',$tasks_performed); } /** * update for RELEASE 3.8.0: * - replace variable 'distribution_sort' with new 'distribution_order_mode' * - add variable distribution_tree_omit_levels and set TDWG2 if required */ function cdm_dataportal_update_7307() { $tasks_performed = array(); // replace distribution_sort with new variable $distribution_sort = variable_get('distribution_sort'); $distribution_order_mode = 'FLAT_ALPHA'; $distribution_tree_omit_levels = array(); if($distribution_sort == 'HIDE_TDWG2'){ $distribution_order_mode = 'TREE'; $distribution_tree_omit_levels[UUID_NAMEDAREALEVEL_TDWGLEVEL_2] = UUID_NAMEDAREALEVEL_TDWGLEVEL_2; } $tasks_performed[] = _remove_variable('distribution_sort'); $tasks_performed[] = _create_variable(DISTRIBUTION_ORDER_MODE, $distribution_order_mode); // add variable distribution_tree_omit_levels and set TDWG2 if required $tasks_performed[] = _create_variable(DISTRIBUTION_TREE_OMIT_LEVELS, $distribution_tree_omit_levels); return join(', ',$tasks_performed); } /** * update for RELEASE 3.12: * - move values for map width and height into 'image_map' settings * - set map aspect ratio based on the old width and height values */ function cdm_dataportal_update_7308() { $tasks_performed = array(); // move values for map width and height into 'image_map' settings // and // set map aspect ratio based on the old width and height values $map_distribution = get_array_variable_merged(CDM_MAP_DISTRIBUTION, CDM_MAP_DISTRIBUTION_DEFAULT); $w = 512 * 2; $h = 512; if(isset($map_distribution['width'])) { $w = $map_distribution['width']; unset($map_distribution['width']); } if(isset($map_distribution['height'])) { $h = $map_distribution['height']; unset($map_distribution['height']); } $map_distribution['image_map']['height'] = $w; $map_distribution['image_map']['width'] = $h; $map_distribution['aspect_ratio'] = $w / $h; $tasks_performed[] = _modify_variable(CDM_MAP_DISTRIBUTION, $map_distribution); return join(', ',$tasks_performed); } /** * update for RELEASE 4.2: * - rename variable taxontree_ranklimit to cdm_taxontree_ranklimit */ function cdm_dataportal_update_7309() { $tasks_performed = array(); $tasks_performed[] = _rename_variable('taxontree_ranklimit', 'cdm_taxontree_ranklimit'); return join(', ',$tasks_performed); } /** * update for RELEASE 4.4: * - grant new permission 'access cdm content' to default roles * - enable back_to_search_results block if show_back_to_search_results was enabled * - remove the variable 'cdm_dataportal_show_back_to_search_results' */ function cdm_dataportal_update_7400() { $tasks_performed = array(); // additional permission for the anonymous user authenticated user roles $additional_default_permissions = array( 'access cdm content' ); user_role_grant_permissions(1, $additional_default_permissions); // anonymous user user_role_grant_permissions(2, $additional_default_permissions); // authenticated user $tasks_performed[] = "grant new permission 'access cdm content' to default roles"; // enable the back_to_search_results block $show_button = variable_get('cdm_dataportal_show_back_to_search_results', 1); if($show_button == 1 || $show_button == "1" ) { $default_theme = variable_get('theme_default', 'zen_dataportal'); _block_rehash($default_theme); // ensure the block table is up to date db_update('block') ->fields(array( 'weight' => 20, 'region' => 'navigation', 'status' => 1, )) ->condition('delta', 'back_to_search_results') ->condition('theme', 'zen_dataportal') ->execute(); db_update('block') ->fields(array( 'weight' => -20, 'region' => 'content', 'status' => 1, )) ->condition('delta', 'back_to_search_results') ->condition('theme', 'zen_dataportal', '<>') ->execute(); $tasks_performed[] = "back_to_search_results block enabled"; } $tasks_performed[] = _remove_variable('cdm_dataportal_show_back_to_search_results'); return join(', ', $tasks_performed); } /* ======================================================================== */ /** * Renames a persistent variable. * * @return * A message string of the performed operation. */ function _rename_variable($old_name, $new_name) { $success = FALSE; $value = variable_get($old_name, FALSE); variable_del($old_name); if ($value !== FALSE) { variable_set($new_name, $value); $success = variable_get($new_name, FALSE) === $value; } else { $success = TRUE; } if($success){ return "Variable '$old_name' to '$new_name' renamed. "; } else { return "ERROR: Renaming variable '$old_name' to '$new_name'. "; } } /** * Unsets a persistent variable. * * Calls variable_del() and returns a message string. * * @return * A message string of the performed operation. */ function _remove_variable($name) { variable_del($name); return "Variable '$name' removed. "; } /** * Sets a persistent variable. * * Calls variable_set() and returns a message string. * * @return * A message string of the performed operation. */ function _create_variable($name, $value) { variable_set($name, $value); return "Variable '$name' created with value: '$value'. "; } /** * Overwrites a persistent variable. * * Calls _create_variable() and returns a message string. * * @return * A message string of the performed operation. */ function _modify_variable($name, $value_override) { /* * FIXME take care for correct handling of tree variables * for example description_gallery contains the array: * Array ( [cdm_dataportal_show_thumbnail_captions] => 1 [cdm_dataportal_media_maxextend] => 120 [cdm_dataportal_media_cols] => 4 ) * -----> solutions merge arrays !!! */ _create_variable($name, $value_override); return "Variable '$name' updated with value: '$value_override'. "; }