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