[ Index ]

PHP Cross Reference of Drupal 6 (yi-drupal)

title

Body

[close]

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

   1  <?php
   2  //$Id: calendar.install,v 1.13.2.12 2010/02/28 14:23:48 karens Exp $
   3  
   4  /**
   5   * Implementation of hook_enable().
   6   * Reset the calendar caches.
   7   */
   8  function calendar_enable() {
   9    module_enable(array('date_api'));
  10    if (version_compare(PHP_VERSION, '5.2', '<')) {
  11      module_enable(array('date_php4'));
  12    }
  13    module_enable(array('date_timezone'));
  14    db_query("DELETE FROM {cache_views}");
  15  }
  16  
  17  /**
  18   * Implementation of hook_disable().
  19   * Empty the calendar caches.
  20   */
  21  function calendar_disable() {
  22    db_query("DELETE FROM {cache_views}");
  23  }
  24  
  25  /**
  26   * Implementation of hook_uninstall().
  27   * Remove all traces of calendars.
  28   */
  29  function calendar_uninstall() {
  30    $ret = array();
  31    variable_del('calendar_default_view_options');
  32    $displays = array(
  33      'calendar', 
  34      'calendar_attachment', 
  35      'calendar_year', 
  36      'calendar_day', 
  37      'calendar_month', 
  38      'calendar_week', 
  39      'calendar_block', 
  40      'calendar_block_view',
  41      'calendar_ical',
  42      );
  43    $result = db_query("SELECT DISTINCT vid FROM {views_display} WHERE display_plugin IN ('". implode("','", $displays) ."')");
  44    while($row = db_fetch_array($result)) {
  45      db_query("DELETE FROM {views_view} WHERE vid = %d", $row['vid']);
  46      db_query("DELETE FROM {views_display} WHERE vid = %d", $row['vid']);
  47    }
  48    db_query("DELETE FROM {cache_views}");
  49    return $ret;
  50  }
  51  
  52  /**
  53   * Implementation of hook_install().
  54   */
  55  function calendar_install() {
  56    $ret = array();
  57    module_enable(array('date_api'));
  58    if (version_compare(PHP_VERSION, '5.2', '<')) {
  59      module_enable(array('date_php4'));
  60    }
  61    module_enable(array('date_timezone'));
  62    // Make sure this module loads after date_api.
  63    db_query("UPDATE {system} SET weight = 1 WHERE name = 'calendar'");
  64    db_query("DELETE FROM {cache_views}");
  65    return $ret;
  66  }
  67  
  68  function calendar_update_last_removed() {
  69    return 5200;
  70  }
  71  
  72  // No longer track views info in variables now that
  73  // Views 2 has settings we can use.
  74  function calendar_update_6000() {
  75    $ret = array();
  76    // don't attempt to upgrade if views is not yet upgraded.
  77    if (drupal_get_installed_schema_version('views', TRUE) < 6000) {
  78      $ret = array();
  79      drupal_set_message(t('Calendar module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array('@update-php' => base_path() .'update.php?op=selection')), 'warning', FALSE);
  80      $ret['#abort'] = array('success' => FALSE, 'query' => t('calendar.module has updates, but cannot be updated until views.module is updated first.'));
  81      
  82      return $ret;
  83    }
  84    
  85    variable_del('calendar_empty_arg');
  86    
  87    // Can't use variable_del because we don't have a reliable
  88    // way to find the old view names.
  89    db_query("DELETE FROM {variable} WHERE name LIKE 'calendar_%'");
  90    cache_clear_all('variables', 'cache');
  91    return $ret;
  92  }
  93  
  94  /**
  95   * Make sure handlers for disabled Calendar iCal module don't get saved in the view.
  96   */
  97  function calendar_update_6001() {
  98    $ret = array();
  99    // don't attempt to upgrade if views is not yet upgraded.
 100    if (drupal_get_installed_schema_version('views', TRUE) < 6000) {
 101      $ret = array();
 102      drupal_set_message(t('Calendar module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array('@update-php' => base_path() .'update.php?op=selection')), 'warning', FALSE);
 103      $ret['#abort'] = array('success' => FALSE, 'query' => t('calendar.module has updates, but cannot be updated until views.module is updated first.'));
 104      
 105      return $ret;
 106    }
 107    if (!module_exists('calendar_ical')) {
 108      $ret[] = update_sql("DELETE FROM {views_display} WHERE display_plugin = 'ical'");
 109    }
 110    return $ret;
 111  }
 112  
 113  function calendar_update_6002() {
 114    $ret = array();
 115    // don't attempt to upgrade if views is not yet upgraded.
 116    if (drupal_get_installed_schema_version('views', TRUE) < 6000) {
 117      $ret = array();
 118      drupal_set_message(t('Calendar module cannot be updated until after Views has been updated. Please return to <a href="@update-php">update.php</a> and run the remaining updates.', array('@update-php' => base_path() .'update.php?op=selection')), 'warning', FALSE);
 119      $ret['#abort'] = array('success' => FALSE, 'query' => t('calendar.module has updates, but cannot be updated until views.module is updated first.'));
 120      
 121      return $ret;
 122    }
 123    $periods = array(
 124      'calendar_month' => 'calendar_period_1',
 125      'calendar_year' => 'calendar_period_2',
 126      'calendar_day' => 'calendar_period_3',
 127      'calendar_week' => 'calendar_period_4',
 128      'calendar_block_view' => 'calendar_period_5',
 129      );
 130    $result = db_query("SELECT * FROM {views_display} d LEFT JOIN {views_view} v ON d.vid = v.vid");
 131    drupal_load('module', 'views');
 132    while ($row = db_fetch_array($result)) {
 133      if (in_array($row['display_plugin'], array_keys($periods))) {
 134        $id = $row['id'];
 135        $options = unserialize($row['display_options']);
 136        if ($row['display_plugin'] == 'calendar_block_view') {
 137          $options['calendar_type'] = 'month';
 138          $options['displays'] = array('calendar_1' => 0, 'default' => 0, 'calendar_block_1' => 'calendar_block_1');
 139        }
 140        else {
 141          $options['calendar_type'] = str_replace('calendar_', '', $row['display_plugin']);
 142          $options['displays'] = array('calendar_1' => 'calendar_1', 'default' => 0, 'calendar_block_1' => 0);
 143        }
 144        $row['id'] = $periods[$row['id']];
 145        $row['display_plugin'] = 'calendar_period';
 146        $row['display_options'] = serialize($options);
 147        db_query("UPDATE {views_display} SET id='%s', display_plugin='%s', display_options='%s' WHERE id='%s'", $row['id'], $row['display_plugin'], $row['display_options'], $id);
 148      }
 149      elseif ($row['display_plugin'] == 'calendar' || $row['display_plugin'] == 'calendar_block') {
 150        db_query("UPDATE {views_display} SET id='%s' WHERE id='%s'", $row['id'] .'_1', $row['id']);      
 151      }
 152      db_query("DELETE FROM {views_object_cache} WHERE name = '%s'", $row['name']);
 153    }
 154    views_invalidate_cache();
 155    $ret[] = array('success' => TRUE, 'query' => 'Updated calendar displays to use new handlers.');
 156    return $ret;
 157  }


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