922cf7d94d08c786c3284bb75d9d3025b113670b
[project/feeds.git] / feeds.install
1 <?php
2 // $Id$
3
4 /**
5 * @file
6 * Schema definitions install/update/uninstall hooks.
7 */
8
9 /**
10 * Implements hook_schema().
11 */
12 function feeds_schema() {
13 $schema = array();
14
15 $schema['feeds_importer'] = array(
16 'description' => 'Configuration of feeds objects.',
17 'export' => array(
18 'key' => 'id',
19 'identifier' => 'feeds_importer',
20 'default hook' => 'feeds_importer_default', // Function hook name.
21 'api' => array(
22 'owner' => 'feeds',
23 'api' => 'feeds_importer_default', // Base name for api include files.
24 'minimum_version' => 1,
25 'current_version' => 1,
26 ),
27 ),
28 'fields' => array(
29 'id' => array(
30 'type' => 'varchar',
31 'length' => 128,
32 'not null' => TRUE,
33 'default' => '',
34 'description' => 'Id of the fields object.',
35 ),
36 'config' => array(
37 'type' => 'text',
38 'not null' => FALSE,
39 'description' => 'Configuration of the feeds object.',
40 'serialize' => TRUE,
41 ),
42 ),
43 'primary key' => array('id'),
44 );
45 $schema['feeds_source'] = array(
46 'description' => 'Source definitions for feeds.',
47 'fields' => array(
48 'id' => array(
49 'type' => 'varchar',
50 'length' => 128,
51 'not null' => TRUE,
52 'default' => '',
53 'description' => 'Id of the feed configuration.',
54 ),
55 'feed_nid' => array(
56 'type' => 'int',
57 'not null' => TRUE,
58 'default' => 0,
59 'unsigned' => TRUE,
60 'description' => 'Node nid if this particular source is attached to a feed node.',
61 ),
62 'config' => array(
63 'type' => 'text',
64 'not null' => FALSE,
65 'description' => 'Configuration of the source.',
66 'serialize' => TRUE,
67 ),
68 'source' => array(
69 'type' => 'text',
70 'not null' => TRUE,
71 'description' => 'Main source resource identifier. E. g. a path or a URL.',
72 ),
73 'batch' => array(
74 'type' => 'text',
75 'size' => 'big',
76 'not null' => FALSE,
77 'description' => 'Cache for batching.',
78 'serialize' => TRUE,
79 ),
80 ),
81 'primary key' => array('id', 'feed_nid'),
82 'indexes' => array(
83 'id' => array('id'),
84 'feed_nid' => array('feed_nid'),
85 'id_source' => array('id', array('source', 128)),
86 ),
87 );
88 $schema['feeds_node_item'] = array(
89 'description' => 'Stores additional information about feed item nodes. Used by FeedsNodeProcessor.',
90 'fields' => array(
91 'nid' => array(
92 'type' => 'int',
93 'unsigned' => TRUE,
94 'not null' => TRUE,
95 'description' => 'Primary Key: The feed item node\'s nid.',
96 ),
97 'id' => array(
98 'type' => 'varchar',
99 'length' => 128,
100 'not null' => TRUE,
101 'default' => '',
102 'description' => 'The id of the fields object that is the producer of this item.',
103 ),
104 'feed_nid' => array(
105 'type' => 'int',
106 'unsigned' => TRUE,
107 'not null' => TRUE,
108 'description' => 'Node id of the owner feed, if available.',
109 ),
110 'imported' => array(
111 'type' => 'int',
112 'not null' => TRUE,
113 'default' => 0,
114 'description' => 'Import date of the feed item, as a Unix timestamp.',
115 ),
116 'url' => array(
117 'type' => 'text',
118 'not null' => TRUE,
119 'description' => 'Link to the feed item.',
120 ),
121 'guid' => array(
122 'type' => 'text',
123 'not null' => TRUE,
124 'description' => 'Unique identifier for the feed item.'
125 ),
126 'hash' => array(
127 'type' => 'varchar',
128 'length' => 32, // The length of an MD5 hash.
129 'not null' => TRUE,
130 'default' => '',
131 'description' => 'The hash of the item.',
132 ),
133 ),
134 'primary key' => array('nid'),
135 'indexes' => array(
136 'id' => array('id'),
137 'feed_nid' => array('feed_nid'),
138 'imported' => array('imported'),
139 'url' => array(array('url', 255)),
140 'guid' => array(array('guid', 255)),
141 ),
142 );
143 $schema['feeds_term_item'] = array(
144 'description' => 'Tracks imported terms.',
145 'fields' => array(
146 'tid' => array(
147 'type' => 'int',
148 'unsigned' => TRUE,
149 'not null' => TRUE,
150 'default' => 0,
151 'description' => 'Imported term id.',
152 ),
153 'id' => array(
154 'type' => 'varchar',
155 'length' => 128,
156 'not null' => TRUE,
157 'default' => '',
158 'description' => 'The id of the fields object that is the creator of this item.',
159 ),
160 'feed_nid' => array(
161 'type' => 'int',
162 'unsigned' => TRUE,
163 'not null' => TRUE,
164 'description' => 'Node id of the owner feed, if available.',
165 ),
166 ),
167 'primary key' => array('tid'),
168 'indexes' => array(
169 'id_feed_nid' => array('id', 'feed_nid'),
170 'feed_nid' => array('feed_nid'),
171 ),
172 );
173 $schema['feeds_push_subscriptions'] = array(
174 'description' => 'PubSubHubbub subscriptions.',
175 'fields' => array(
176 'domain' => array(
177 'type' => 'varchar',
178 'length' => 128,
179 'not null' => TRUE,
180 'default' => '',
181 'description' => 'Domain of the subscriber. Corresponds to an importer id.',
182 ),
183 'subscriber_id' => array(
184 'type' => 'int',
185 'not null' => TRUE,
186 'default' => 0,
187 'unsigned' => TRUE,
188 'description' => 'ID of the subscriber. Corresponds to a feed nid.',
189 ),
190 'timestamp' => array(
191 'type' => 'int',
192 'unsigned' => FALSE,
193 'default' => 0,
194 'not null' => TRUE,
195 'description' => 'Created timestamp.',
196 ),
197 'hub' => array(
198 'type' => 'text',
199 'not null' => TRUE,
200 'description' => 'The URL of the hub endpoint of this subscription.',
201 ),
202 'topic' => array(
203 'type' => 'text',
204 'not null' => TRUE,
205 'description' => 'The topic URL (feed URL) of this subscription.',
206 ),
207 'secret' => array(
208 'type' => 'varchar',
209 'length' => 128,
210 'not null' => TRUE,
211 'default' => '',
212 'description' => 'Shared secret for message authentication.',
213 ),
214 'status' => array(
215 'type' => 'varchar',
216 'length' => 64,
217 'not null' => TRUE,
218 'default' => '',
219 'description' => 'Status of subscription.',
220 ),
221 'post_fields' => array(
222 'type' => 'text',
223 'not null' => FALSE,
224 'description' => 'Fields posted.',
225 'serialize' => TRUE,
226 ),
227 ),
228 'primary key' => array('domain', 'subscriber_id'),
229 'indexes' => array(
230 'timestamp' => array('timestamp'),
231 ),
232 );
233 return $schema;
234 }
235
236 /**
237 * Remove class field on feeds_config.
238 */
239 function feeds_update_6001() {
240 $ret = array();
241 db_drop_field($ret, 'feeds_config', 'class');
242 return $ret;
243 }
244
245 /**
246 * Rename table.
247 */
248 function feeds_update_6002() {
249 $ret = array();
250 db_rename_table($ret, 'feeds_config', 'feeds_importer');
251 return $ret;
252 }
253
254 /**
255 * Add primary keys to feeds_importer and feeds_source.
256 */
257 function feeds_update_6003() {
258 $ret = array();
259 db_drop_index($ret, 'feeds_importer', 'id');
260 db_add_primary_key($ret, 'feeds_importer', array('id'));
261 db_add_primary_key($ret, 'feeds_source', array('id', 'feed_nid'));
262 return $ret;
263 }
264
265 /**
266 * Add source field to feeds_source, make fields part of PKs not null.
267 */
268 function feeds_update_6004() {
269 $ret = array();
270
271 $spec = array(
272 'type' => 'text',
273 'not null' => TRUE,
274 'description' => 'Main source resource identifier. E. g. a path or a URL.',
275 );
276 db_add_field($ret, 'feeds_source', 'source', $spec);
277 db_add_index($ret, 'feeds_source', 'id_source', array('id', array('source', 255)));
278
279 // Make feed_nid not null, default 0. It is part of the primary key.
280 $spec = array(
281 'type' => 'int',
282 'not null' => TRUE,
283 'default' => 0,
284 'unsigned' => TRUE,
285 'description' => 'Node nid if this particular source is attached to a feed node.',
286 );
287 db_change_field($ret, 'feeds_schedule', 'feed_nid', 'feed_nid', $spec);
288
289
290 // Same thing for feeds_source table.
291 $spec = array(
292 'type' => 'int',
293 'not null' => TRUE,
294 'default' => 0,
295 'unsigned' => TRUE,
296 'description' => 'Node nid if this particular source is attached to a feed node.',
297 );
298 db_change_field($ret, 'feeds_source', 'feed_nid', 'feed_nid', $spec);
299
300 return $ret;
301 }
302
303 /**
304 * Add callback column to feeds_schedule.
305 */
306 function feeds_update_6005() {
307 $ret = array();
308
309 // Add a callback column and an index.
310 $spec = array(
311 'type' => 'varchar',
312 'length' => 128,
313 'not null' => TRUE,
314 'default' => '',
315 'description' => 'Callback to be invoked.',
316 );
317 db_add_field($ret, 'feeds_schedule', 'callback', $spec);
318
319 db_add_index($ret, 'feeds_schedule', 'id_callback', array('id', 'callback'));
320
321 return $ret;
322 }
323
324 /**
325 * Remove primary key from feeds_schedule and replace it by an index.
326 */
327 function feeds_update_6006() {
328 $ret = array();
329
330 db_drop_primary_key($ret, 'feeds_schedule');
331 db_add_index($ret, 'feeds_schedule', 'feed_nid', array('feed_nid'));
332
333 return $ret;
334 }
335
336 /**
337 * Add hash column to feeds_node_item.
338 */
339 function feeds_update_6007() {
340 $ret = array();
341
342 $spec = array(
343 'type' => 'varchar',
344 'length' => 32,
345 'not null' => TRUE,
346 'default' => '',
347 'description' => 'The hash of the item.',
348 );
349 db_add_field($ret, 'feeds_node_item', 'hash', $spec);
350
351 return $ret;
352 }
353
354 /**
355 * Add batch field to feeds_source table, adjust feeds_schedule table.
356 */
357 function feeds_update_6008() {
358 $ret = array();
359
360 $spec = array(
361 'type' => 'text',
362 'size' => 'big',
363 'not null' => FALSE,
364 'description' => 'Cache for batching.',
365 'serialize' => TRUE,
366 );
367 db_add_field($ret, 'feeds_source', 'batch', $spec);
368
369 // Make scheduled flag a timestamp.
370 $spec = array(
371 'type' => 'int',
372 'size' => 'normal',
373 'unsigned' => TRUE,
374 'default' => 0,
375 'not null' => TRUE,
376 'description' => 'Timestamp when a job was scheduled. 0 if a job is currently not scheduled.',
377 );
378 db_change_field($ret, 'feeds_schedule', 'scheduled', 'scheduled', $spec);
379
380 // Rename last_scheduled_time to last_executed_time, fix unsigned property.
381 $spec = array(
382 'type' => 'int',
383 'size' => 'normal',
384 'unsigned' => TRUE,
385 'default' => 0,
386 'not null' => TRUE,
387 'description' => 'Timestamp when a job was last executed.',
388 );
389 db_change_field($ret, 'feeds_schedule', 'last_scheduled_time', 'last_executed_time', $spec);
390
391 return $ret;
392 }
393
394 /**
395 * Add feeds_push_subscriptions tables.
396 */
397 function feeds_update_6009() {
398 $ret = array();
399 $table = array(
400 'description' => 'PubSubHubbub subscriptions.',
401 'fields' => array(
402 'domain' => array(
403 'type' => 'varchar',
404 'length' => 128,
405 'not null' => TRUE,
406 'default' => '',
407 'description' => 'Domain of the subscriber. Corresponds to an importer id.',
408 ),
409 'subscriber_id' => array(
410 'type' => 'int',
411 'not null' => TRUE,
412 'default' => 0,
413 'unsigned' => TRUE,
414 'description' => 'ID of the subscriber. Corresponds to a feed nid.',
415 ),
416 'timestamp' => array(
417 'type' => 'int',
418 'unsigned' => FALSE,
419 'default' => 0,
420 'not null' => TRUE,
421 'description' => 'Created timestamp.',
422 ),
423 'hub' => array(
424 'type' => 'text',
425 'not null' => TRUE,
426 'description' => 'The URL of the hub endpoint of this subscription.',
427 ),
428 'topic' => array(
429 'type' => 'text',
430 'not null' => TRUE,
431 'description' => 'The topic URL (feed URL) of this subscription.',
432 ),
433 'secret' => array(
434 'type' => 'varchar',
435 'length' => 128,
436 'not null' => TRUE,
437 'default' => '',
438 'description' => 'Shared secret for message authentication.',
439 ),
440 'status' => array(
441 'type' => 'varchar',
442 'length' => 64,
443 'not null' => TRUE,
444 'default' => '',
445 'description' => 'Status of subscription.',
446 ),
447 'post_fields' => array(
448 'type' => 'text',
449 'not null' => FALSE,
450 'description' => 'Fields posted.',
451 'serialize' => TRUE,
452 ),
453 ),
454 'primary key' => array('domain', 'subscriber_id'),
455 'indexes' => array(
456 'timestamp' => array('timestamp'),
457 ),
458 );
459 db_create_table($ret, 'feeds_push_subscriptions', $table);
460 return $ret;
461 }
462
463 /**
464 * Enable all Feeds News, Feeds Import and Feeds fast news features.
465 */
466 function feeds_update_6010() {
467 drupal_install_modules(array('feeds_news', 'feeds_import'));
468 if (module_exists('data')) {
469 drupal_install_modules(array('feeds_fast_news'));
470 drupal_set_message(t('Installed Feeds News, Feeds Fast News and Feeds Import as replacement for Feeds Defaults module. If you were not using Feeds Defaults then you can safely disable Feeds News and Feeds Import.'));
471 }
472 else {
473 drupal_set_message(t('Installed Feeds News and Feeds Import as replacement for Feeds Defaults module. If you were not using Feeds Defaults then you can safely disable Feeds News and Feeds Import.'));
474 }
475 if (module_exists('features')) {
476 drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/structure/feeds and features on admin/build/features.</strong>'));
477 }
478 else {
479 drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/structure/feeds and Feeds modules on admin/build/modules.</strong>'));
480 }
481 return array();
482 }
483
484 /**
485 * Add imported flag for terms.
486 */
487 function feeds_update_6011() {
488 $ret = array();
489 $schema = array(
490 'description' => 'Tracks imported terms.',
491 'fields' => array(
492 'tid' => array(
493 'type' => 'int',
494 'unsigned' => TRUE,
495 'not null' => TRUE,
496 'default' => 0,
497 'description' => 'Imported term id.',
498 ),
499 'id' => array(
500 'type' => 'varchar',
501 'length' => 128,
502 'not null' => TRUE,
503 'default' => '',
504 'description' => 'The id of the fields object that is the creator of this item.',
505 ),
506 'feed_nid' => array(
507 'type' => 'int',
508 'unsigned' => TRUE,
509 'not null' => TRUE,
510 'description' => "Node id of the owner feed, if available.",
511 ),
512 ),
513 'primary key' => array('tid'),
514 'indexes' => array(
515 'id_feed_nid' => array('id', 'feed_nid'),
516 'feed_nid' => array('feed_nid'),
517 ),
518 );
519 db_create_table($ret, 'feeds_term_item', $schema);
520 return $ret;
521 }
522
523 /**
524 * Drop schedule table and reschedule all tasks, install Job Scheduler module.
525 */
526 function feeds_update_6012() {
527 $ret = array();
528 // Only attempt installation if module is present, otherwise we would leave
529 // the system table in a limbo.
530 $modules = module_rebuild_cache();
531 if (isset($modules['job_scheduler'])) {
532 if (!$modules['job_scheduler']->status) {
533 drupal_install_modules(array('job_scheduler'));
534 drupal_set_message(t('Installed Job Scheduler module.'));
535 }
536 }
537 else {
538 drupal_set_message(t('NOTE: Please install new dependency of Feeds: !job_scheduler module.', array('!job_scheduler' => l(t('Job Scheduler'), 'http://drupal.org/project/job_scheduler'))), 'warning');
539 }
540 db_drop_table($ret, 'feeds_schedule');
541 feeds_reschedule(TRUE);
542 return $ret;
543 }