name] = $var->value; } // Remove old variables db_query("DELETE FROM {variable} WHERE name LIKE 'gallery_%'"); // Array containing 'old name' => 'new name' map $variable_map = 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' ); // Migrate old variables foreach ($variable_map 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 $obsolete = array('gallery_search_max_items', 'gallery_autodetect_dir', 'gallery_uri', 'gallery_dir'); foreach ($obsolete as $var) { if (isset($variables[$var])) { unset($variables[$var]); $ret[] = array('success' => TRUE, 'query' => 'Removing variable ['. $var .']'); } } // 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. $variables['gallery_valid'] = FALSE; $variables['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 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'); // 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); } cache_clear_all('variables', 'cache'); menu_rebuild(); 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'); }