[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

/sites/all/modules/gallery/ -> gallery.install (source)

   1  <?php
   2  // $Id: gallery.install,v 1.3.2.6 2008/06/10 14:58:13 profix898 Exp $
   3  
   4  /**
   5   * gallery.module : gallery.install
   6   * Install/Uninstall functions
   7   */
   8  
   9  /**
  10   * Implementation of hook_install().
  11   */
  12  function gallery_install() {
  13  }
  14  
  15  /**
  16   * Implementation of hook_update_N().
  17   * (migrate settings from the 5.x-1.x to 5.x-2.x series)
  18   */
  19  function gallery_update_1() {
  20    // Array containing 'old name' => 'new name' map
  21    $migrate = array(
  22      // Image block settings
  23      'gallery_album_frame'               => 'gallery_block_image_0_album_frame',
  24      'gallery_block_block'               => 'gallery_block_image_0_block_block',
  25      'gallery_block_show'                => 'gallery_block_image_0_block_show',
  26      'gallery_item_frame'                => 'gallery_block_image_0_item_frame',
  27      'gallery_item_id'                   => 'gallery_block_image_0_item_id',
  28      'gallery_link_target'               => 'gallery_block_image_0_link_target',
  29      'gallery_block_num_images'          => 'gallery_block_image_0_num_images',
  30      'gallery_maxsize'                   => 'gallery_block_image_0_size',
  31      // Grid block settings
  32      'gallery_grid_album_frame'          => 'gallery_block_grid_0_album_frame',
  33      'gallery_grid_block_block'          => 'gallery_block_grid_0_block_block',
  34      'gallery_grid_block_show'           => 'gallery_block_grid_0_block_show',
  35      'gallery_grid_item_frame'           => 'gallery_block_grid_0_item_frame',
  36      'gallery_grid_item_id'              => 'gallery_block_grid_0_item_id',
  37      'gallery_grid_link_target'          => 'gallery_block_grid_0_link_target',
  38      'gallery_grid_maxsize'              => 'gallery_block_grid_0_size',
  39      'gallery_grid_num_cols'             => 'gallery_block_grid_0_num_cols',
  40      'gallery_grid_num_rows'             => 'gallery_block_grid_0_num_rows',
  41      // G2 filter settings
  42      'gallery_filter_default_size'       => 'gallery_filter_default_maxsize',
  43      // Search settings
  44      'gallery_search_max_rows_per_pager' => 'gallery_search_rows_per_pager',
  45      'gallery_search_maxsize'            => 'gallery_search_size',
  46      // Fullname support
  47      'gallery_use_full_name'             => 'gallery_use_fullname',
  48      'gallery_profile_full_name_field'   => 'gallery_profile_fullname_field'
  49    );
  50    // Array containing obsolete variables
  51    $obsolete = array('gallery_search_max_items', 'gallery_autodetect_dir', 'gallery_uri', 'gallery_dir');
  52    
  53    // Update variables
  54    $ret = gallery_update_variables($migrate, $obsolete);
  55    
  56    // Update the blocks
  57    db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'image-0', 'gallery', 0);
  58    $ret[] = array('success' => TRUE, 'query' => 'Updating block [image-0]');
  59    db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'navigation', 'gallery', 1);
  60    $ret[] = array('success' => TRUE, 'query' => 'Updating block [navigation]');
  61    db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%d'", 'grid-0', 'gallery', 2);
  62    $ret[] = array('success' => TRUE, 'query' => 'Updating block [grid-0]');
  63   
  64    // Mark gallery configuration invalid. This does NOT reset the configuration, but
  65    // forces the user to run the install wizard to (re)set and verify critical settings.
  66    variable_set('gallery_valid', FALSE);
  67    drupal_set_message('You were updating from gallery module 5.x-1.x (or earlier) to the 6.x-1.x
  68                        series of the module. All your settings were migrated automatically (see below),
  69                        but you will need to re-configure some basic options. Please visit the
  70                        Gallery settings page (admin/settings/gallery) to complete the update.',
  71                        'error');
  72    
  73    cache_clear_all('variables', 'cache');
  74    menu_rebuild();
  75    
  76    return $ret;
  77  }
  78  
  79  /**
  80   * Implementation of hook_update_N().
  81   * (initial update to Drupal 6)
  82   */
  83  function gallery_update_6000() {
  84    $delta = 0;
  85    $new = $migrate = array();
  86    
  87    // Image block settings
  88    $imageblock_num = variable_get('gallery_block_image_num', 1);
  89    for ($i=0; $i<$imageblock_num; $i++) {
  90      $delta++;
  91      $new += array(
  92        'gallery_block_'. $delta .'_type'                 => 'imageblock',
  93        'gallery_block_'. $delta .'_imageblock_num_cols'  => 1
  94      );
  95      $migrate += array(
  96        'gallery_block_image_'. $i .'_blockid'      => 'gallery_block_'. $delta .'_blockid',
  97        'gallery_block_image_'. $i .'_num_images'   => 'gallery_block_'. $delta .'_imageblock_num_rows',
  98        'gallery_block_image_'. $i .'_block_block'  => 'gallery_block_'. $delta .'_imageblock_block_block',
  99        'gallery_block_image_'. $i .'_item_id'      => 'gallery_block_'. $delta .'_imageblock_item_id',
 100        'gallery_block_image_'. $i .'_block_show'   => 'gallery_block_'. $delta .'_imageblock_block_show',
 101        'gallery_block_image_'. $i .'_size_method'  => 'gallery_block_'. $delta .'_imageblock_size_method',
 102        'gallery_block_image_'. $i .'_size'         => 'gallery_block_'. $delta .'_imageblock_size',
 103        'gallery_block_image_'. $i .'_album_frame'  => 'gallery_block_'. $delta .'_imageblock_album_frame',
 104        'gallery_block_image_'. $i .'_item_frame'   => 'gallery_block_'. $delta .'_imageblock_item_frame',
 105        'gallery_block_image_'. $i .'_link_target'  => 'gallery_block_'. $delta .'_imageblock_link_target',
 106        'gallery_block_image_'. $i .'_link'         => 'gallery_block_'. $delta .'_imageblock_link'
 107      );
 108      db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%s'", 'block-'. $delta, 'gallery', 'image-'. $i);
 109      $ret[] = array('success' => TRUE, 'query' => 'Updating block [image-'. $i .']');
 110    }
 111    
 112    // Grid block settings
 113    $gridblock_num = variable_get('gallery_block_grid_num', 1);
 114    for ($i=0; $i<$gridblock_num; $i++) {
 115      $delta++;
 116      $new['gallery_block_'. $delta .'_type'] = 'imageblock';
 117      $migrate += array(
 118        'gallery_block_grid_'. $i .'_blockid'       => 'gallery_block_'. $delta .'_blockid',
 119        'gallery_block_grid_'. $i .'_num_cols'      => 'gallery_block_'. $delta .'_imageblock_num_cols',
 120        'gallery_block_grid_'. $i .'_num_rows'      => 'gallery_block_'. $delta .'_imageblock_num_rows',
 121        'gallery_block_grid_'. $i .'_item_id'       => 'gallery_block_'. $delta .'_imageblock_item_id',
 122        'gallery_block_grid_'. $i .'_block_show'    => 'gallery_block_'. $delta .'_imageblock_block_show',
 123        'gallery_block_grid_'. $i .'_size_method'   => 'gallery_block_'. $delta .'_imageblock_size_method',
 124        'gallery_block_grid_'. $i .'_size'          => 'gallery_block_'. $delta .'_imageblock_size',
 125        'gallery_block_grid_'. $i .'_album_frame'   => 'gallery_block_'. $delta .'_imageblock_album_frame',
 126        'gallery_block_grid_'. $i .'_item_frame'    => 'gallery_block_'. $delta .'_imageblock_item_frame',
 127        'gallery_block_grid_'. $i .'_link_target'   => 'gallery_block_'. $delta .'_imageblock_link_target',
 128        'gallery_block_grid_'. $i .'_link'          => 'gallery_block_'. $delta .'_imageblock_link'
 129      );
 130      db_query("UPDATE {blocks} SET delta = '%s' WHERE module = '%s' AND delta = '%s'", 'block-'. $delta, 'gallery', 'grid-'. $i);
 131      $ret[] = array('success' => TRUE, 'query' => 'Updating block [grid-'. $i .']');
 132      
 133      // gallery_block_grid_X_block_block must be handled differently. In D5 this was a single value,
 134      // but in D6 it is an array of size cols*rows (to allow different values for each item).
 135      $num_images = variable_get('gallery_block_grid_'. $i .'_num_cols', 2) * variable_get('gallery_block_grid_'. $i .'_num_rows', 2);
 136      $old_block = variable_get('gallery_block_grid_'. $i .'_block_block', array('randomImage'));
 137      $new_block = array_fill(0, $num_images, $old_block);
 138      $new['gallery_block_'. $delta .'_imageblock_block_block'] = $new_block;
 139    }
 140    $new['gallery_block_num'] = $delta;
 141    
 142    // Other variables
 143    $migrate += array(
 144      'gallery_g2image_only_listed_pages'   => 'gallery_g2image_visibility',
 145      'gallery_g2image_std_pages'           => 'gallery_g2image_visibility_pages'
 146    );
 147    
 148    // Array containing obsolete variables
 149    $obsolete = array(
 150      'gallery_page_callback',
 151      'gallery_block_image_num',
 152      'gallery_block_grid_num',
 153      'gallery_menu_timestamp'
 154    );
 155    
 156    // Update variables
 157    $ret += gallery_update_variables($migrate, $obsolete);
 158    
 159    // Add new variables
 160    foreach ($new as $name => $value) {
 161      db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, serialize($value));
 162      $ret[] = array('success' => TRUE, 'query' => 'Adding variable ['. $name .']');
 163    }
 164    cache_clear_all('variables', 'cache');
 165    menu_rebuild();
 166    
 167    return $ret;
 168  }
 169  
 170  /**
 171   * Function gallery_update_variables().
 172   */
 173  function gallery_update_variables($migrate, $obsolete) {
 174    $ret = array();
 175    
 176    $variables = array();
 177    // Fetch all gallery-related variables
 178    $result = db_query("SELECT * FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
 179    while ($var = db_fetch_object($result)) {
 180      $variables[$var->name] = $var->value;
 181    }
 182    
 183    // Remove old variables
 184    db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
 185    
 186    // Migrate old variables
 187    foreach ($migrate as $old => $new) {
 188      if (isset($variables[$old])) {
 189        $variables[$new] = $variables[$old];
 190        unset($variables[$old]);
 191        $ret[] = array('success' => TRUE, 'query' => 'Migrating variable ['. $old .' => '. $new .']');
 192      }
 193    }
 194  
 195    // Unset obsolete variables
 196    foreach ($obsolete as $var) {
 197      if (isset($variables[$var])) {
 198        unset($variables[$var]);
 199        $ret[] = array('success' => TRUE, 'query' => 'Removing variable ['. $var .']');
 200      }
 201    }
 202    // Save resulting variables array
 203    // (all variables not migrated or unset are taken over directly)
 204    foreach ($variables as $name => $serialized_value) {
 205      // We dont use variable_set() to reduce overhead
 206      // (i.e. unserialize/serialize cache_clear_all() for each variable)
 207      // Cannot use update_sql with % substitution.
 208      db_query("INSERT INTO {variable} (name, value) VALUES ('%s', '%s')", $name, $serialized_value);
 209    }
 210    
 211    return $ret;
 212  }
 213  
 214  /**
 215   * Implementation of hook_uninstall().
 216   */
 217  function gallery_uninstall() {
 218    // Remove all gallery related variables and blocks
 219    db_query("DELETE FROM {variable} WHERE name LIKE '%s'", 'gallery_%');
 220    db_query("DELETE FROM {blocks} WHERE module = '%s'", 'gallery');
 221    cache_clear_all('variables', 'cache');
 222  }


Generated: Mon Jul 9 18:01:44 2012 Cross-referenced by PHPXref 0.7