'new name' map $migrate = array( // Image block settings 'gallery_album_frame' => 'gallery_block_image_0_album_frame', 'gallery_block_block' => 'gallery_block_image_0_block_block', 'gallery_block_show' => 'gallery_block_image_0_block_show', 'gallery_item_frame' => 'gallery_block_image_0_item_frame', 'gallery_item_id' => 'gallery_block_image_0_item_id', 'gallery_link_target' => 'gallery_block_image_0_link_target', 'gallery_block_num_images' => 'gallery_block_image_0_num_images', 'gallery_maxsize' => 'gallery_block_image_0_size', // Grid block settings 'gallery_grid_album_frame' => 'gallery_block_grid_0_album_frame', 'gallery_grid_block_block' => 'gallery_block_grid_0_block_block', 'gallery_grid_block_show' => 'gallery_block_grid_0_block_show', 'gallery_grid_item_frame' => 'gallery_block_grid_0_item_frame', 'gallery_grid_item_id' => 'gallery_block_grid_0_item_id', 'gallery_grid_link_target' => 'gallery_block_grid_0_link_target', 'gallery_grid_maxsize' => 'gallery_block_grid_0_size', 'gallery_grid_num_cols' => 'gallery_block_grid_0_num_cols', 'gallery_grid_num_rows' => 'gallery_block_grid_0_num_rows', // G2 filter settings 'gallery_filter_default_size' => 'gallery_filter_default_maxsize', // Search settings 'gallery_search_max_rows_per_pager' => 'gallery_search_rows_per_pager', 'gallery_search_maxsize' => 'gallery_search_size', // Fullname support 'gallery_use_full_name' => 'gallery_use_fullname', 'gallery_profile_full_name_field' => 'gallery_profile_fullname_field' ); // Array containing obsolete variables $obsolete = array('gallery_search_max_items', 'gallery_autodetect_dir', 'gallery_uri', 'gallery_dir'); // Update variables $ret = gallery_update_variables($migrate, $obsolete); // Update the blocks $ret[] = update_sql("UPDATE {blocks} SET delta = 'image-0' WHERE module = 'gallery' AND delta = 0"); $ret[] = update_sql("UPDATE {blocks} SET delta = 'navigation' WHERE module = 'gallery' AND delta = 1"); $ret[] = update_sql("UPDATE {blocks} SET delta = 'grid-0' WHERE module = 'gallery' AND delta = 2"); // Mark gallery configuration invalid. This does NOT reset the configuration, but // forces the user to run the install wizard to (re)set and verify critical settings. variable_set('gallery_valid', FALSE); variable_set('gallery_config_reset', TRUE); drupal_set_message('You were updating from gallery module 5.x-1.x (or earlier) to the 5.x-2.x series of the module. All your settings were migrated automatically (see below), but you will need to re-configure some basic options. Please visit the Gallery settings page (admin/settings/gallery) to complete the update.', 'error'); cache_clear_all('variables', 'cache'); menu_rebuild(); return $ret; } /** * Function gallery_update_variables(). */ function gallery_update_variables($migrate, $obsolete) { $ret = array(); $variables = array(); // Fetch all gallery-related variables $result = db_query("SELECT * FROM {variable} WHERE name LIKE 'gallery_%'"); while ($var = db_fetch_object($result)) { $variables[$var->name] = $var->value; } // Remove old variables db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'"); // Migrate old variables foreach ($migrate as $old => $new) { if (isset($variables[$old])) { $variables[$new] = $variables[$old]; unset($variables[$old]); $ret[] = array('success' => TRUE, 'query' => 'Migrating variable ['. $old .' => '. $new .']'); } } // Unset obsolete variables foreach ($obsolete as $var) { if (isset($variables[$var])) { unset($variables[$var]); $ret[] = array('success' => TRUE, 'query' => 'Removing variable ['. $var .']'); } } // Save resulting variables array // (all variables not migrated or unset are taken over directly) foreach ($variables as $name => $value) { // We dont use variable_set() to reduce overhead // (i.e. unserialize => serialize and cache_clear_all() for each variable) db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $value); } return $ret; } /** * Implementation of hook_uninstall(). */ function gallery_uninstall() { // Remove all gallery related variables and blocks db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'"); db_query("DELETE FROM {blocks} WHERE module = 'gallery'"); cache_clear_all('variables', 'cache'); }