summaryrefslogtreecommitdiffstats
path: root/feeds.install
blob: 851b8df775563a9193f1f5f0206950a4c9a18ee4 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
<?php
// $Id$

/**
 * @file
 * Schema definitions install/update/uninstall hooks.
 */

/**
 * Implements hook_schema().
 */
function feeds_schema() {
  $schema = array();

  $schema['feeds_importer'] = array(
    'description' => 'Configuration of feeds objects.',
    'export' => array(
      'key' => 'id',
      'identifier' => 'feeds_importer',
      'default hook' => 'feeds_importer_default',  // Function hook name.
      'api' => array(
        'owner' => 'feeds',
        'api' => 'feeds_importer_default',  // Base name for api include files.
        'minimum_version' => 1,
        'current_version' => 1,
      ),
    ),
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Id of the fields object.',
      ),
      'config' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Configuration of the feeds object.',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array('id'),
  );
  $schema['feeds_source'] = array(
    'description' => 'Source definitions for feeds.',
    'fields' => array(
      'id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Id of the feed configuration.',
      ),
      'feed_nid' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
        'description' => 'Node nid if this particular source is attached to a feed node.',
      ),
      'config' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Configuration of the source.',
        'serialize' => TRUE,
      ),
      'source' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'Main source resource identifier. E. g. a path or a URL.',
      ),
      'state' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'Cache for batching.',
        'description' => 'State of import or clearing batches.',
        'serialize' => TRUE,
      ),
      'fetcher_result' => array(
        'type' => 'text',
        'size' => 'big',
        'not null' => FALSE,
        'description' => 'Cache for fetcher result.',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array('id', 'feed_nid'),
    'indexes' => array(
      'id' => array('id'),
      'feed_nid' => array('feed_nid'),
      'id_source' => array('id', array('source', 128)),
    ),
  );
  $schema['feeds_node_item'] = array(
    'description' => 'Stores additional information about feed item nodes. Used by FeedsNodeProcessor.',
    'fields' => array(
      'nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Primary Key: The feed item node\'s nid.',
      ),
      'id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The id of the fields object that is the producer of this item.',
      ),
      'feed_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Node id of the owner feed, if available.',
      ),
      'imported' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Import date of the feed item, as a Unix timestamp.',
      ),
      'url' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'Link to the feed item.',
      ),
      'guid' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'Unique identifier for the feed item.'
      ),
      'hash' => array(
        'type' => 'varchar',
        'length' => 32, // The length of an MD5 hash.
        'not null' => TRUE,
        'default' => '',
        'description' => 'The hash of the item.',
      ),
    ),
    'primary key' => array('nid'),
    'indexes' => array(
      'id' => array('id'),
      'feed_nid' => array('feed_nid'),
      'imported' => array('imported'),
      'url' => array(array('url', 255)),
      'guid' => array(array('guid', 255)),
    ),
  );
  $schema['feeds_term_item'] = array(
    'description' => 'Tracks imported terms.',
    'fields' => array(
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Imported term id.',
      ),
      'id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The id of the fields object that is the creator of this item.',
      ),
      'feed_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => 'Node id of the owner feed, if available.',
      ),
    ),
    'primary key' => array('tid'),
    'indexes' => array(
      'id_feed_nid' => array('id', 'feed_nid'),
      'feed_nid' => array('feed_nid'),
    ),
  );
  $schema['feeds_push_subscriptions'] = array(
    'description' => 'PubSubHubbub subscriptions.',
    'fields' => array(
      'domain' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Domain of the subscriber. Corresponds to an importer id.',
      ),
      'subscriber_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
        'description' => 'ID of the subscriber. Corresponds to a feed nid.',
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'default' => 0,
        'not null' => TRUE,
        'description' => 'Created timestamp.',
      ),
      'hub' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The URL of the hub endpoint of this subscription.',
      ),
      'topic' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The topic URL (feed URL) of this subscription.',
      ),
      'secret' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Shared secret for message authentication.',
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Status of subscription.',
      ),
      'post_fields' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Fields posted.',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array('domain', 'subscriber_id'),
    'indexes' => array(
      'timestamp' => array('timestamp'),
    ),
  );
  return $schema;
}

/**
 * Remove class field on feeds_config.
 */
function feeds_update_6001() {
  $ret = array();
  db_drop_field($ret, 'feeds_config', 'class');
  return $ret;
}

/**
 * Rename table.
 */
function feeds_update_6002() {
  $ret = array();
  db_rename_table($ret, 'feeds_config', 'feeds_importer');
  return $ret;
}

/**
 * Add primary keys to feeds_importer and feeds_source.
 */
function feeds_update_6003() {
  $ret = array();
  db_drop_index($ret, 'feeds_importer', 'id');
  db_add_primary_key($ret, 'feeds_importer', array('id'));
  db_add_primary_key($ret, 'feeds_source', array('id', 'feed_nid'));
  return $ret;
}

/**
 * Add source field to feeds_source, make fields part of PKs not null.
 */
function feeds_update_6004() {
  $ret = array();

  $spec = array(
    'type' => 'text',
    'not null' => TRUE,
    'description' => 'Main source resource identifier. E. g. a path or a URL.',
  );
  db_add_field($ret, 'feeds_source', 'source', $spec);
  db_add_index($ret, 'feeds_source', 'id_source', array('id', array('source', 255)));

  // Make feed_nid not null, default 0. It is part of the primary key.
  $spec = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'unsigned' => TRUE,
    'description' => 'Node nid if this particular source is attached to a feed node.',
  );
  db_change_field($ret, 'feeds_schedule', 'feed_nid', 'feed_nid', $spec);


  // Same thing for feeds_source table.
  $spec = array(
    'type' => 'int',
    'not null' => TRUE,
    'default' => 0,
    'unsigned' => TRUE,
    'description' => 'Node nid if this particular source is attached to a feed node.',
  );
  db_change_field($ret, 'feeds_source', 'feed_nid', 'feed_nid', $spec);

  return $ret;
}

/**
 * Add callback column to feeds_schedule.
 */
function feeds_update_6005() {
  $ret = array();

  // Add a callback column and an index.
  $spec = array(
    'type' => 'varchar',
    'length' => 128,
    'not null' => TRUE,
    'default' => '',
    'description' => 'Callback to be invoked.',
  );
  db_add_field($ret, 'feeds_schedule', 'callback', $spec);

  db_add_index($ret, 'feeds_schedule', 'id_callback', array('id', 'callback'));

  return $ret;
}

/**
 * Remove primary key from feeds_schedule and replace it by an index.
 */
function feeds_update_6006() {
  $ret = array();

  db_drop_primary_key($ret, 'feeds_schedule');
  db_add_index($ret, 'feeds_schedule', 'feed_nid', array('feed_nid'));

  return $ret;
}

/**
 * Add hash column to feeds_node_item.
 */
function feeds_update_6007() {
  $ret = array();

  $spec = array(
    'type' => 'varchar',
    'length' => 32,
    'not null' => TRUE,
    'default' => '',
    'description' => 'The hash of the item.',
  );
  db_add_field($ret, 'feeds_node_item', 'hash', $spec);

  return $ret;
}

/**
 * Add batch field to feeds_source table, adjust feeds_schedule table.
 */
function feeds_update_6008() {
  $ret = array();

  $spec = array(
    'type' => 'text',
    'size' => 'big',
    'not null' => FALSE,
    'description' => 'Cache for batching.',
    'serialize' => TRUE,
  );
  db_add_field($ret, 'feeds_source', 'batch', $spec);

  // Make scheduled flag a timestamp.
  $spec = array(
    'type' => 'int',
    'size' => 'normal',
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
    'description' => 'Timestamp when a job was scheduled. 0 if a job is currently not scheduled.',
  );
  db_change_field($ret, 'feeds_schedule', 'scheduled', 'scheduled', $spec);

  // Rename last_scheduled_time to last_executed_time, fix unsigned property.
  $spec = array(
    'type' => 'int',
    'size' => 'normal',
    'unsigned' => TRUE,
    'default' => 0,
    'not null' => TRUE,
    'description' => 'Timestamp when a job was last executed.',
  );
  db_change_field($ret, 'feeds_schedule', 'last_scheduled_time', 'last_executed_time', $spec);

  return $ret;
}

/**
 * Add feeds_push_subscriptions tables.
 */
function feeds_update_6009() {
  $ret = array();
  $table = array(
    'description' => 'PubSubHubbub subscriptions.',
    'fields' => array(
      'domain' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Domain of the subscriber. Corresponds to an importer id.',
      ),
      'subscriber_id' => array(
        'type' => 'int',
        'not null' => TRUE,
        'default' => 0,
        'unsigned' => TRUE,
        'description' => 'ID of the subscriber. Corresponds to a feed nid.',
      ),
      'timestamp' => array(
        'type' => 'int',
        'unsigned' => FALSE,
        'default' => 0,
        'not null' => TRUE,
        'description' => 'Created timestamp.',
      ),
      'hub' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The URL of the hub endpoint of this subscription.',
      ),
      'topic' => array(
        'type' => 'text',
        'not null' => TRUE,
        'description' => 'The topic URL (feed URL) of this subscription.',
      ),
      'secret' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Shared secret for message authentication.',
      ),
      'status' => array(
        'type' => 'varchar',
        'length' => 64,
        'not null' => TRUE,
        'default' => '',
        'description' => 'Status of subscription.',
      ),
      'post_fields' => array(
        'type' => 'text',
        'not null' => FALSE,
        'description' => 'Fields posted.',
        'serialize' => TRUE,
      ),
    ),
    'primary key' => array('domain', 'subscriber_id'),
    'indexes' => array(
      'timestamp' => array('timestamp'),
    ),
  );
  db_create_table($ret, 'feeds_push_subscriptions', $table);
  return $ret;
}

/**
 * Enable all Feeds News, Feeds Import and Feeds fast news features.
 */
function feeds_update_6010() {
  drupal_install_modules(array('feeds_news', 'feeds_import'));
  if (module_exists('data')) {
    drupal_install_modules(array('feeds_fast_news'));
    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.'));
  }
  else {
    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.'));
  }
  if (module_exists('features')) {
    drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/structure/feeds and features on admin/build/features.</strong>'));
  }
  else {
    drupal_set_message(t('<strong>Review enabled state of importer configurations on admin/structure/feeds and Feeds modules on admin/build/modules.</strong>'));
  }
  return array();
}

/**
 * Add imported flag for terms.
 */
function feeds_update_6011() {
  $ret = array();
  $schema = array(
    'description' => 'Tracks imported terms.',
    'fields' => array(
      'tid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0,
        'description' => 'Imported term id.',
      ),
      'id' => array(
        'type' => 'varchar',
        'length' => 128,
        'not null' => TRUE,
        'default' => '',
        'description' => 'The id of the fields object that is the creator of this item.',
      ),
      'feed_nid' => array(
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'description' => "Node id of the owner feed, if available.",
      ),
    ),
    'primary key' => array('tid'),
    'indexes' => array(
      'id_feed_nid' => array('id', 'feed_nid'),
      'feed_nid' => array('feed_nid'),
    ),
  );
  db_create_table($ret, 'feeds_term_item', $schema);
  return $ret;
}

/**
 * Drop schedule table and reschedule all tasks, install Job Scheduler module.
 */
function feeds_update_6012() {
  $ret = array();
  // Only attempt installation if module is present, otherwise we would leave
  // the system table in a limbo.
  $modules = module_rebuild_cache();
  if (isset($modules['job_scheduler'])) {
    if (!$modules['job_scheduler']->status) {
      drupal_install_modules(array('job_scheduler'));
      drupal_set_message(t('Installed Job Scheduler module.'));
    }
  }
  else {
    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');
  }
  db_drop_table($ret, 'feeds_schedule');
  feeds_reschedule(TRUE);
  return $ret;
}

/**
 * Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
 * result.
 */
function feeds_update_7100(&$sandbox) {
  $spec = array(
    'type' => 'text',
    'size' => 'big',
    'not null' => FALSE,
    'description' => 'State of import or clearing batches.',
    'serialize' => TRUE,
  );
  db_change_field('feeds_source', 'batch', 'state', $spec);

  $spec = array(
    'type' => 'text',
    'size' => 'big',
    'not null' => FALSE,
    'description' => 'Cache for fetcher result.',
    'serialize' => TRUE,
  );
  db_add_field('feeds_source', 'fetcher_result', $spec);
}