/[drupal]/contributions/modules/calendar/calendar.install
ViewVC logotype

Contents of /contributions/modules/calendar/calendar.install

Parent Directory Parent Directory | Revision Log Revision Log | View Revision Graph Revision Graph


Revision 1.18 - (show annotations) (download) (as text)
Sat Dec 13 17:55:04 2008 UTC (11 months, 2 weeks ago) by karens
Branch: MAIN
CVS Tags: HEAD
Changes since 1.17: +0 -0 lines
File MIME type: text/x-php
Synch HEAD to latest D6.
1 <?php
2 //$Id: calendar.install,v 1.13.2.8 2008/10/15 13:33:59 karens Exp $
3 /**
4 * @file
5 * Install File
6 */
7 /**
8 * Implementation of hook_requirements().
9 * Added to be sure the Date API version matches this code so invalid
10 * functions are not called.
11 */
12 function calendar_requirements($phase) {
13 $requirements = array();
14 $t = get_t();
15
16 // This is the minimum required version for the Date API so that it will work with this module.
17 $required_version = 5.2;
18
19 // Make sure the matching version of date_api is installed.
20 // Use info instead of an error at install time since the problem may
21 // just be that they were installed in the wrong order.
22 switch ($phase) {
23 case 'runtime':
24 if (variable_get('date_api_version', 0) < $required_version) {
25 $requirements['calendar_api_version'] = array(
26 'title' => $t('Calendar requirements'),
27 'value' => $t('The Calendar module requires a more current version of the Date API. Please check for a newer version.'),
28 'severity' => REQUIREMENT_ERROR,
29 );
30 }
31 break;
32 case 'install':
33 if (variable_get('date_api_version', 0) < $required_version) {
34 $requirements['calendar_api_version'] = array(
35 'title' => $t('Calendar requirements'),
36 'value' => $t('The Calendar module requires the latest version of the Date API, be sure you are installing the latest versions of both modules.'),
37 'severity' => REQUIREMENT_INFO,
38 );
39 }
40 break;
41 }
42 return $requirements;
43 }
44
45 /**
46 * Implementation of hook_enable().
47 * Reset the calendar caches.
48 */
49 function calendar_enable() {
50 module_enable(array('date_api'));
51 if (version_compare(PHP_VERSION, '5.2', '<')) {
52 module_enable(array('date_php4'));
53 }
54 module_enable(array('date_timezone'));
55 db_query("DELETE FROM {cache_views}");
56 }
57
58 /**
59 * Implementation of hook_disable().
60 * Empty the calendar caches.
61 */
62 function calendar_disable() {
63 db_query("DELETE FROM {cache_views}");
64 }
65
66 /**
67 * Implementation of hook_uninstall().
68 * Remove all traces of calendars.
69 */
70 function calendar_uninstall() {
71 $ret = array();
72 $displays = array(
73 'calendar',
74 'calendar_attachment',
75 'calendar_year',
76 'calendar_day',
77 'calendar_month',
78 'calendar_week',
79 'calendar_block',
80 'calendar_block_view',
81 'calendar_ical',
82 );
83 $result = db_query("SELECT DISTINCT vid FROM {views_display} WHERE display_plugin IN ('". implode("','", $displays) ."')");
84 while($row = db_fetch_array($result)) {
85 db_query("DELETE FROM {views_view} WHERE vid = %d", $row['vid']);
86 db_query("DELETE FROM {views_display} WHERE vid = %d", $row['vid']);
87 }
88 db_query("DELETE FROM {cache_views}");
89 return $ret;
90 }
91
92 /**
93 * Implementation of hook_install().
94 */
95 function calendar_install() {
96 $ret = array();
97 module_enable(array('date_api'));
98 if (version_compare(PHP_VERSION, '5.2', '<')) {
99 module_enable(array('date_php4'));
100 }
101 module_enable(array('date_timezone'));
102 // Make sure this module loads after date_api.
103 db_query("UPDATE {system} SET weight = 1 WHERE name = 'calendar'");
104 db_query("DELETE FROM {cache_views}");
105 return $ret;
106 }
107
108 /**
109 * Move these caches from 'cache' to 'cache_views' so they get cleared
110 * automatically whenever views_invalidate_cache() is called.
111 */
112 function calendar_update_5000() {
113 $ret = array();
114 cache_clear_all('calendar_fields', 'cache');
115 cache_clear_all('calendar_views', 'cache');
116 return $ret;
117 }
118
119 /**
120 * Implementation of hook_update().
121 */
122 function calendar_update_5001() {
123 $ret = array();
124 $ret[] = update_sql("UPDATE {system} SET weight = 1 WHERE name = 'calendar'");
125
126 return $ret;
127 }
128
129 function calendar_update_5200() {
130 $ret = array();
131 module_enable(array('date_api'));
132 if (version_compare(PHP_VERSION, '5.2', '<')) {
133 module_enable(array('date_php4'));
134 }
135 module_enable(array('date_timezone'));
136 return $ret;
137 }
138
139 // No longer track views info in variables now that
140 // Views 2 has settings we can use.
141 function calendar_update_6000() {
142 $ret = array();
143 variable_del('calendar_empty_arg');
144
145 // Can't use variable_del because we don't have a reliable
146 // way to find the old view names.
147 db_query("DELETE FROM {variable} WHERE name LIKE 'calendar_%'");
148 cache_clear_all('variables', 'cache');
149 return $ret;
150 }
151
152 /**
153 * Make sure handlers for disabled Calendar iCal module don't get saved in the view.
154 */
155 function calendar_update_6001() {
156 $ret = array();
157 if (!module_exists('calendar_ical')) {
158 $ret[] = update_sql("DELETE FROM {views_display} WHERE display_plugin = 'ical'");
159 }
160 return $ret;
161 }
162
163 function calendar_update_6002() {
164 $ret = array();
165 $periods = array(
166 'calendar_month' => 'calendar_period_1',
167 'calendar_year' => 'calendar_period_2',
168 'calendar_day' => 'calendar_period_3',
169 'calendar_week' => 'calendar_period_4',
170 'calendar_block_view' => 'calendar_period_5',
171 );
172 $result = db_query("SELECT * FROM {views_display} d LEFT JOIN {views_view} v ON d.vid = v.vid");
173 drupal_load('module', 'views');
174 while ($row = db_fetch_array($result)) {
175 if (in_array($row['display_plugin'], array_keys($periods))) {
176 $id = $row['id'];
177 $options = unserialize($row['display_options']);
178 if ($row['display_plugin'] == 'calendar_block_view') {
179 $options['calendar_type'] = 'month';
180 $options['displays'] = array('calendar_1' => 0, 'default' => 0, 'calendar_block_1' => 'calendar_block_1');
181 }
182 else {
183 $options['calendar_type'] = str_replace('calendar_', '', $row['display_plugin']);
184 $options['displays'] = array('calendar_1' => 'calendar_1', 'default' => 0, 'calendar_block_1' => 0);
185 }
186 $row['id'] = $periods[$row['id']];
187 $row['display_plugin'] = 'calendar_period';
188 $row['display_options'] = serialize($options);
189 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);
190 }
191 elseif ($row['display_plugin'] == 'calendar' || $row['display_plugin'] == 'calendar_block') {
192 db_query("UPDATE {views_display} SET id='%s' WHERE id='%s'", $row['id'] .'_1', $row['id']);
193 }
194 db_query("DELETE FROM {views_object_cache} WHERE name = '%s'", $row['name']);
195 }
196 views_invalidate_cache();
197 $ret[] = array('success' => TRUE, 'query' => 'Updated calendar displays to use new handlers.');
198 return $ret;
199 }

  ViewVC Help
Powered by ViewVC 1.1.2