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

Contents of /contributions/modules/category_aggregator/category_aggregator.install

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


Revision 1.4 - (show annotations) (download) (as text)
Sat Sep 22 12:53:41 2007 UTC (2 years, 2 months ago) by kaustubhsrikanth
Branch: MAIN
CVS Tags: DRUPAL-5--0-1, HEAD
Changes since 1.3: +16 -14 lines
File MIME type: text/x-php
Bug Fixes
1 <?php
2
3 // $Id: category_aggregator.install,v 1.4.2.11 2007/04/28 21:32:13 mistknight Exp $
4
5 function category_aggregator_install()
6 {
7 switch ($GLOBALS['db_type'])
8 {
9 case 'mysqli':
10 case 'mysql':
11
12 $query = <<<begin_create_query
13 CREATE TABLE IF NOT EXISTS {category_aggregator_feed} (
14 `nid` int(10) unsigned NOT NULL,
15 `original_author` varchar(100) NOT NULL default '',
16 `categories` varchar(50) NOT NULL default '',
17 `url` varchar(125) NOT NULL,
18 `username` varchar(50) NOT NULL default '',
19 `password` varchar(50) NOT NULL default '',
20 `refresh_interval` int(10) unsigned NOT NULL,
21 `title_as_guid_interval` int(10) unsigned NOT NULL,
22 `enabled` enum('yes', 'no') NOT NULL default 'yes',
23 `publish_new_items` enum('yes', 'no') NOT NULL default 'yes',
24 `aggregate_to_moderation_queue` enum('yes', 'no') NOT NULL default 'no',
25 `sticky_items` enum('yes', 'no') NOT NULL default 'no',
26 `enable_comments_on_articles` enum('yes','no') NOT NULL default 'no',
27 `enable_comments_on_images` enum('yes','no') NOT NULL default 'no',
28 `promote_to_frontpage` int(10) NOT NULL default 0,
29 `delete_old_items` enum('yes', 'no') NOT NULL default 'no',
30 `link_items_to_original_urls` enum('yes', 'no') NOT NULL default 'yes',
31 `item_categories` varchar(150) NOT NULL default '',
32 `etag` varchar(255) NOT NULL default '',
33 `last_modified` int(11) NOT NULL default 0,
34 `last_refreshed` int(11) NOT NULL default 0,
35 PRIMARY KEY (`nid`)
36 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
37 begin_create_query;
38
39 db_query($query);
40
41 $query = <<<begin_create_query
42 CREATE TABLE IF NOT EXISTS {category_aggregator_item} (
43 `nid` int(10) unsigned NOT NULL,
44 `url` varchar(125) NOT NULL default '',
45 `link_to_original_url` enum('yes', 'no') NOT NULL default 'yes',
46 `original_author` varchar(100) NOT NULL default '',
47 `story_guid` int unsigned NOT NULL default 0,
48 `fid` int(10) unsigned NOT NULL default 0,
49 `image_id` int(10) unsigned NOT NULL default 0,
50 `image_guid` int unsigned NOT NULL default 0,
51 PRIMARY KEY (`nid`),
52 INDEX (`story_guid`),
53 INDEX (`image_id`),
54 INDEX (`fid`),
55 INDEX (`image_guid`)
56 ) TYPE=MyISAM /*!40100 DEFAULT CHARACTER SET utf8 */;
57 begin_create_query;
58
59 db_query($query);
60
61 $vocab_count = db_query("SELECT COUNT(vid) AS vid_count FROM {vocabulary} ".
62 "WHERE name = '%s'", 'Category Aggregator Feed Types');
63
64 $vocab_count = db_fetch_object($vocab_count);
65 $vocab_count = $vocab_count->vid_count;
66
67 if ($vocab_count == 0)
68 {
69 $vocab = array();
70
71 $vocab['name'] = 'Category Aggregator Feed Types';
72 $vocab['description'] = 'All category aggregator Feed Types are to be declared as terms under this vocabulary';
73 $vocab['help'] = 'Add terms that represent the feed types. Refer to readme for details.';
74 $vocab['multiple'] = 0;
75 $vocab['required'] = 1;
76 $vocab['module'] = 'category_aggregator';
77 $vocab['nodes']['category_aggregator_feed'] = 1;
78 $vocab['tags'] = 0;
79 $vocab['weight'] = 0;
80
81 taxonomy_save_vocabulary($vocab);
82
83 variable_set('category_aggregator_current_vid', $vocab['vid']);
84
85 $term = array();
86
87 $term['name'] = 'RSS20';
88 $term['description'] = 'This is an RSS 2.0 feed handler';
89 $term['vid'] = $vocab['vid'];
90 $term['weight'] = 0;
91
92 taxonomy_save_term($term);
93
94 unset($term);
95 $term = array();
96
97 $term['name'] = 'ATOM10';
98 $term['description'] = 'This is an ATOM 1.0 feed handler';
99 $term['vid'] = $vocab['vid'];
100 $term['weight'] = 0;
101
102 taxonomy_save_term($term);
103
104 unset($term);
105 $term = array();
106
107 $term['name'] = 'RDF10';
108 $term['description'] = 'This is an RDF 1.0 feed handler';
109 $term['vid'] = $vocab['vid'];
110 $term['weight'] = 0;
111
112 taxonomy_save_term($term);
113 }
114 break;
115 }
116
117 category_aggregator_update_6();
118 }
119
120 //update function for 4.7 branch
121 function category_aggregator_update_1()
122 {
123 $ret = array();
124
125 switch ($GLOBALS['db_type'])
126 {
127 case 'mysql':
128 case 'mysqli':
129 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD aggregate_to_moderation_queue enum('yes', 'no') NOT NULL default 'no' AFTER publish_new_items");
130 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD sticky_items enum('yes', 'no') NOT NULL default 'no' AFTER aggregate_to_moderation_queue");
131 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD enable_comments_on_articles enum('yes','no') NOT NULL default 'no' AFTER sticky_items");
132 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD enable_comments_on_images enum('yes','no') NOT NULL default 'no' AFTER enable_comments_on_articles");
133 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD promote_to_frontpage int(10) NOT NULL default 0 AFTER enable_comments_on_images");
134 break;
135 }
136
137 return $ret;
138 }
139
140 // update function for drupal 5 branch
141 function category_aggregator_update_2()
142 {
143 $ret = array();
144
145 switch ($GLOBALS['db_type'])
146 {
147 case 'mysql':
148 case 'mysqli':
149 $ret[] = update_sql("ALTER TABLE {category_aggregator_feed} ADD link_items_to_original_urls enum('yes', 'no') NOT NULL default 'yes' AFTER delete_old_items");
150 $ret[] = update_sql("ALTER TABLE {category_aggregator_item} ADD link_to_original_url enum('yes', 'no') NOT NULL default 'yes' AFTER url");
151 break;
152 }
153
154 return $ret;
155 }
156
157 function category_aggregator_update_3()
158 {
159 $current_vid = variable_get('category_aggregator_current_vid', 0);
160 if ($current_vid)
161 {
162 $term_exists = taxonomy_get_term_by_name('ATOM10');
163 if (count($term_exists) > 0) return array();
164
165 $term = array();
166
167 $term['name'] = 'ATOM10';
168 $term['description'] = 'This is an ATOM 1.0 feed handler';
169 $term['vid'] = $current_vid;
170 $term['weight'] = 0;
171
172 taxonomy_save_term($term);
173 }
174 else
175 drupal_set_message("Something wrong occurred during update! Please report this to module maintainer!");
176
177 return array();
178 }
179
180 function category_aggregator_update_4()
181 {
182 db_query("ALTER TABLE {category_aggregator_item} modify `story_guid` bigint");
183 db_query("ALTER TABLE {category_aggregator_item} modify `image_guid` bigint");
184
185 $original_items = db_query("SELECT * FROM {category_aggregator_item}");
186
187 while ($row = db_fetch_object($original_items))
188 {
189 $update_statement = "";
190
191 $new_story_guid = sprintf('%u', $row->story_guid);
192 $new_image_guid = sprintf('%u', $row->image_guid);
193
194 if ($row->story_guid != $new_story_guid)
195 $update_statement .= "`story_guid` = $new_story_guid";
196
197 if ($row->image_guid != $new_image_guid)
198 if ($update_statement == '')
199 $update_statement .= "`image_guid` = $new_image_guid";
200 else
201 $update_statement .= ",`image_guid` = $new_image_guid";
202
203 if ($update_statement == '') continue;
204
205 db_query("UPDATE {category_aggregator_item} SET $update_statement WHERE nid = %d", $row->nid);
206 }
207
208 db_query("ALTER TABLE {category_aggregator_item} modify `story_guid` int unsigned");
209 db_query("ALTER TABLE {category_aggregator_item} modify `image_guid` int unsigned");
210
211 return array();
212 }
213
214 function category_aggregator_update_5()
215 {
216 $current_vid = variable_get('category_aggregator_current_vid', 0);
217 if ($current_vid)
218 {
219 $term_exists = taxonomy_get_term_by_name('RDF10');
220 if (count($term_exists) > 0) return array();
221
222 $term = array();
223
224 $term['name'] = 'RDF10';
225 $term['description'] = 'This is an RDF 1.0 feed handler';
226 $term['vid'] = $current_vid;
227 $term['weight'] = 0;
228
229 taxonomy_save_term($term);
230 }
231 else
232 drupal_set_message("Something wrong occurred during update! Please report this to module maintainer!");
233
234 return array();
235 }
236
237 function category_aggregator_update_6()
238 {
239 if (db_num_rows(db_query("SHOW TABLES LIKE '{" . db_escape_table('category_aggregator2_feed') . "}'")) == 0) return;
240 if (db_num_rows(db_query("SHOW TABLES LIKE '{" . db_escape_table('category_aggregator2_item') . "}'")) == 0) return;
241
242 if (!ini_get('safe_mode'))
243 set_time_limit(30 * 60);
244
245 db_query("UPDATE {vocabulary_node_types} SET type = '%s' WHERE type = '%s'", 'category_aggregator_feed', 'category_aggregator2_feed');
246 db_query("UPDATE {vocabulary_node_types} SET type = '%s' WHERE type = '%s'", 'category_aggregator_feed', 'category_aggregator2-feed');
247 db_query("UPDATE {vocabulary_node_types} SET type = '%s' WHERE type = '%s'", 'category_aggregator_item', 'category_aggregator2_item');
248 db_query("UPDATE {vocabulary_node_types} SET type = '%s' WHERE type = '%s'", 'category_aggregator_item', 'category_aggregator2-item');
249
250 $feeds = db_query("SELECT af.* FROM {category_aggregator2_feed} af, {node} n WHERE af.nid = n.nid");
251
252 while ($row = db_fetch_object($feeds))
253 {
254 if (db_fetch_object(db_query("SELECT COUNT(nid) AS feed_count FROM {category_aggregator_feed} WHERE url = '%s'", $row->url))->feed_count > 0) continue;
255
256 db_query("UPDATE {node} SET type = '%s' WHERE nid = %d", 'category_aggregator_feed', $row->nid);
257
258 $taxonomies_old_style = unserialize($row->item_taxonomy);
259
260 $taxonomies_new_style = array();
261
262 foreach ($taxonomies_old_style AS $key => $value)
263 {
264 $vid = db_fetch_object(db_query("SELECT vid FROM {term_data} WHERE tid = %d", $value))->vid;
265 $taxonomies_new_style[$vid][$value] = $value;
266 }
267
268 $row->item_taxonomy = serialize($taxonomies_new_style);
269
270 db_query("INSERT INTO {category_aggregator_feed} VALUES ".
271 "(%d, '%s', '%s', '%s', '%s', %d, %d, '%s', '%s', '%s', '%s', '%s', '%s', %d ,'%s', '%s', '%s', '%s', %d, %d)",
272 $row->nid, $row->author, $row->url, '', '', (int)($row->refresh/60), 0, 'no', ($row->item_status ? 'yes' : 'no'), 'no', 'no', 'no', 'no', ($row->promoted_items == 1000000000 ? 0 : $row->promoted_items), ($row->clear_items == 1000000000 ? 'no' : 'yes'), ($row->item_show_link == 1 ? 'no' : 'yes'), $row->item_taxonomy, $row->etag, $row->modified, $row->checked);
273
274 $items = db_query("SELECT ai.*, n.title FROM {category_aggregator2_item} ai, {node} n WHERE ai.fid = %d AND ai.nid = n.nid", $row->nid);
275 while ($row2 = db_fetch_object($items))
276 {
277 db_query("UPDATE {node} SET type = '%s' WHERE nid = %d", 'category_aggregator_item', $row2->nid);
278
279 $row2->guid = sprintf('%u', crc32(trim($row2->guid) == '' ? $row2->title : $row2->guid));
280
281 db_query("INSERT INTO {category_aggregator_item} (nid, url, link_to_original_url, original_author, ".
282 "story_guid, fid, image_id, image_guid) VALUES (%d, '%s', '%s', '%s', %s, %d, ".
283 "%d, %s)", $row2->nid, $row2->link, ($row->item_show_link == 1 ? 'no' : 'yes'),(trim($row2->author) == '' ? (trim($row->author) == '' ? 'unspecified' : $row->author): $row2->author), $row2->guid, $row2->fid, 0, 0);
284 }
285 }
286
287 db_query("DROP TABLE {category_aggregator2_feed}");
288 db_query("DROP TABLE {category_aggregator2_item}");
289 }
290
291 function category_aggregator_uninstall()
292 {
293 // Delete all category_aggregator items
294 $result = db_query("SELECT ai.nid FROM {category_aggregator_item} ai, {node} n WHERE ai.nid = n.nid");
295 while ($row = db_fetch_object($result))
296 node_delete($row->nid);
297
298 // Delete all category_aggregator feeds
299 $result = db_query("SELECT af.nid FROM {category_aggregator_feed} af, {node} n WHERE af.nid = n.nid");
300 while ($row = db_fetch_object($result))
301 node_delete($row->nid);
302
303 // We'll get -1 if this is not set for some reason
304 $vocabulary_to_delete = variable_get('category_aggregator_current_vid', -1);
305
306 if ($vocabulary_to_delete >= 0)
307 taxonomy_del_vocabulary($vocabulary_to_delete);
308
309 db_query("DROP TABLE {category_aggregator_item}");
310 db_query("DROP TABLE {category_aggregator_feed}");
311 variable_del('category_aggregator_current_vid');
312 variable_del('category_aggregator_item_time_to_live');
313 variable_del('category_aggregator_enable_logging');
314 variable_del('category_aggregator_image_to_display');
315 variable_del('category_aggregator_enable_cron');
316 variable_del('category_aggregator_feeds_to_refresh_per_cron');
317 variable_del('category_aggregator_feed_refresh_cooldown');
318
319 node_type_delete('category_aggregator_feed');
320 node_type_delete('category_aggregator_item');
321 }
322
323 /**
324 * Implementation of hook_requirements
325 */
326 /*function category_aggregator_requirements($phase)
327 {
328 $requirements = array();
329
330 // Ensure translations don't break at install time
331 $t = get_t();
332
333 // Test PHP version
334 $requirements['php'] = array(
335 'title' => $t('PHP'),
336 'value' => ($phase == 'runtime') ? l(phpversion(), 'admin/logs/status/php') :
337 phpversion(),
338 );
339
340 if (version_compare(phpversion(), '5.0.0') < 0)
341 {
342 $requirements['php']['description'] = $t('This module requires at least PHP %version.', array('%version' => '5.0.0'));
343 $requirements['php']['severity'] = REQUIREMENT_ERROR;
344 }
345
346 // Test for CURL support
347 if (!function_exists('curl_init'))
348 {
349 $requirements['CURL'] = array();
350 $requirements['CURL']['title'] = $t('CURL');
351 $requirements['CURL']['value'] = $t('not installed');
352 $requirements['CURL']['description'] = $t('CURL support not present.');
353 $requirements['CURL']['severity'] = REQUIREMENT_ERROR;
354 }
355
356 // Test drupal version support
357 if (strpos(VERSION, '5.') !== 0)
358 {
359 $requirements['drupal'] = array();
360 $requirements['drupal']['title'] = $t('drupal');
361 $requirements['CURL']['value'] = VERSION;
362 $requirements['CURL']['description'] = $t('Drupal version incompatible with this module.');
363 $requirements['CURL']['severity'] = REQUIREMENT_ERROR;
364 }
365
366
367 return $requirements;
368 }*/

  ViewVC Help
Powered by ViewVC 1.1.2