Projet

Général

Profil

Paste
Télécharger (20,6 ko) Statistiques
| Branche: | Révision:

root / drupal7 / sites / all / modules / feeds / feeds.install @ a192dc0b

1
<?php
2

    
3
/**
4
 * @file
5
 * Schema definitions install/update/uninstall hooks.
6
 */
7

    
8
/**
9
 * Implements hook_requirements().
10
 */
11
function feeds_requirements($phase) {
12
  $t = get_t();
13

    
14
  $requirements = array();
15

    
16
  module_load_include('module', 'feeds');
17
  // Check if we have any SimplePie importers.
18
  $needs_simplepie = FALSE;
19
  foreach (feeds_importer_load_all() as $importer) {
20
    if ($importer->config['parser']['plugin_key'] === 'FeedsSimplePieParser') {
21
      $needs_simplepie = TRUE;
22
      break;
23
    }
24
  }
25

    
26
  if (!$needs_simplepie) {
27
    return $requirements;
28
  }
29

    
30
  $requirements['simplepie'] = array(
31
    'title' => $t('SimplePie'),
32
    'value' => $t('Installed'),
33
    'description' => $t('The SimplePie library is required for Feeds SimplePie Parser.'),
34
    'severity' => REQUIREMENT_OK,
35
  );
36

    
37
  if (!feeds_simplepie_exists()) {
38
    $requirements['simplepie']['value'] = $t('Not installed');
39

    
40
    $folder = drupal_get_path('module', 'feeds') . '/libraries';
41
    if (module_exists('libraries')) {
42
      $folder = 'sites/all/libraries/simplepie';
43
    }
44

    
45
    $args = array(
46
      '!url' => 'http://simplepie.org/downloads/',
47
      '%folder' => $folder,
48
      '%file' => 'simplepie.compiled.php',
49
    );
50
    $requirements['simplepie']['description'] .= $t('<br />Download the compiled, single-file version of the library from the <a href="!url">SimplePie download page</a>, place it into %folder and rename it to %file.', $args);
51
    $requirements['simplepie']['severity'] = REQUIREMENT_ERROR;
52
  }
53

    
54
  return $requirements;
55
}
56

    
57
/**
58
  * Implement hook_uninstall()
59
  */
60
function feeds_uninstall() {
61
  variable_del('http_request_timeout');
62
  variable_del('feeds_reschedule');
63
  variable_del('feeds_use_mbstring');
64
}
65

    
66
/**
67
 * Implements hook_schema().
68
 */
69
function feeds_schema() {
70
  $schema = array();
71

    
72
  $schema['feeds_importer'] = array(
73
    'description' => 'Configuration of feeds objects.',
74
    'export' => array(
75
      'key' => 'id',
76
      'identifier' => 'feeds_importer',
77
      'default hook' => 'feeds_importer_default',  // Function hook name.
78
      'api' => array(
79
        'owner' => 'feeds',
80
        'api' => 'feeds_importer_default',  // Base name for api include files.
81
        'minimum_version' => 1,
82
        'current_version' => 1,
83
      ),
84
    ),
85
    'fields' => array(
86
      'id' => array(
87
        'type' => 'varchar',
88
        'length' => 128,
89
        'not null' => TRUE,
90
        'default' => '',
91
        'description' => 'Id of the fields object.',
92
      ),
93
      'config' => array(
94
        'type' => 'blob',
95
        'size' => 'big',
96
        'not null' => FALSE,
97
        'description' => 'Configuration of the feeds object.',
98
        'serialize' => TRUE,
99
      ),
100
    ),
101
    'primary key' => array('id'),
102
  );
103
  $schema['feeds_source'] = array(
104
    'description' => 'Source definitions for feeds.',
105
    'fields' => array(
106
      'id' => array(
107
        'type' => 'varchar',
108
        'length' => 128,
109
        'not null' => TRUE,
110
        'default' => '',
111
        'description' => 'Id of the feed configuration.',
112
      ),
113
      'feed_nid' => array(
114
        'type' => 'int',
115
        'not null' => TRUE,
116
        'default' => 0,
117
        'unsigned' => TRUE,
118
        'description' => 'Node nid if this particular source is attached to a feed node.',
119
      ),
120
      'config' => array(
121
        'type' => 'blob',
122
        'size' => 'big',
123
        'not null' => FALSE,
124
        'description' => 'Configuration of the source.',
125
        'serialize' => TRUE,
126
      ),
127
      'source' => array(
128
        'type' => 'text',
129
        'not null' => TRUE,
130
        'description' => 'Main source resource identifier. E. g. a path or a URL.',
131
      ),
132
      'state' => array(
133
        'type' => 'blob',
134
        'size' => 'big',
135
        'not null' => FALSE,
136
        'description' => 'State of import or clearing batches.',
137
        'serialize' => TRUE,
138
      ),
139
      'fetcher_result' => array(
140
        'type' => 'blob',
141
        'size' => 'big',
142
        'not null' => FALSE,
143
        'description' => 'Cache for fetcher result.',
144
        'serialize' => TRUE,
145
      ),
146
      'imported' => array(
147
        'type' => 'int',
148
        'not null' => TRUE,
149
        'default' => 0,
150
        'unsigned' => TRUE,
151
        'description' => 'Timestamp when this source was imported last.',
152
      ),
153
    ),
154
    'primary key' => array('id', 'feed_nid'),
155
    'indexes' => array(
156
      'id' => array('id'),
157
      'feed_nid' => array('feed_nid'),
158
      'id_source' => array('id', array('source', 128)),
159
    ),
160
  );
161
  $schema['feeds_item'] = array(
162
    'description' => 'Tracks items such as nodes, terms, users.',
163
    'fields' => array(
164
      'entity_type' => array(
165
        'type' => 'varchar',
166
        'length' => 32,
167
        'not null' => TRUE,
168
        'default' => '',
169
        'description' => 'The entity type.',
170
      ),
171
      'entity_id' => array(
172
        'type' => 'int',
173
        'unsigned' => TRUE,
174
        'not null' => TRUE,
175
        'description' => 'The imported entity\'s serial id.',
176
      ),
177
      'id' => array(
178
        'type' => 'varchar',
179
        'length' => 128,
180
        'not null' => TRUE,
181
        'default' => '',
182
        'description' => 'The id of the importer that created this item.',
183
      ),
184
      'feed_nid' => array(
185
        'type' => 'int',
186
        'unsigned' => TRUE,
187
        'not null' => TRUE,
188
        'description' => 'Node id of the source, if available.',
189
      ),
190
      'imported' => array(
191
        'type' => 'int',
192
        'not null' => TRUE,
193
        'default' => 0,
194
        'description' => 'Import date of the feed item, as a Unix timestamp.',
195
      ),
196
      'url' => array(
197
        'type' => 'text',
198
        'not null' => TRUE,
199
        'description' => 'Link to the feed item.',
200
      ),
201
      'guid' => array(
202
        'type' => 'text',
203
        'not null' => TRUE,
204
        'description' => 'Unique identifier for the feed item.'
205
      ),
206
      'hash' => array(
207
        'type' => 'varchar',
208
        'length' => 32, // The length of an MD5 hash.
209
        'not null' => TRUE,
210
        'default' => '',
211
        'description' => 'The hash of the source item.',
212
      ),
213
    ),
214
    'primary key' => array('entity_type', 'entity_id'),
215
    'indexes' => array(
216
      'id' => array('id'),
217
      'feed_nid' => array('feed_nid'),
218
      'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
219
      'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
220
      'global_lookup_url' => array('entity_type', array('url', 128)),
221
      'global_lookup_guid' => array('entity_type', array('guid', 128)),
222
      'imported' => array('imported'),
223
    ),
224
  );
225
  $schema['feeds_push_subscriptions'] = array(
226
    'description' => 'PubSubHubbub subscriptions.',
227
    'fields' => array(
228
      'domain' => array(
229
        'type' => 'varchar',
230
        'length' => 128,
231
        'not null' => TRUE,
232
        'default' => '',
233
        'description' => 'Domain of the subscriber. Corresponds to an importer id.',
234
      ),
235
      'subscriber_id' => array(
236
        'type' => 'int',
237
        'not null' => TRUE,
238
        'default' => 0,
239
        'unsigned' => TRUE,
240
        'description' => 'ID of the subscriber. Corresponds to a feed nid.',
241
      ),
242
      'timestamp' => array(
243
        'type' => 'int',
244
        'unsigned' => FALSE,
245
        'default' => 0,
246
        'not null' => TRUE,
247
        'description' => 'Created timestamp.',
248
      ),
249
      'hub' => array(
250
        'type' => 'text',
251
        'not null' => TRUE,
252
        'description' => 'The URL of the hub endpoint of this subscription.',
253
      ),
254
      'topic' => array(
255
        'type' => 'text',
256
        'not null' => TRUE,
257
        'description' => 'The topic URL (feed URL) of this subscription.',
258
      ),
259
      'secret' => array(
260
        'type' => 'varchar',
261
        'length' => 128,
262
        'not null' => TRUE,
263
        'default' => '',
264
        'description' => 'Shared secret for message authentication.',
265
      ),
266
      'status' => array(
267
        'type' => 'varchar',
268
        'length' => 64,
269
        'not null' => TRUE,
270
        'default' => '',
271
        'description' => 'Status of subscription.',
272
      ),
273
      'post_fields' => array(
274
        'type' => 'text',
275
        'not null' => FALSE,
276
        'description' => 'Fields posted.',
277
        'serialize' => TRUE,
278
      ),
279
    ),
280
    'primary key' => array('domain', 'subscriber_id'),
281
    'indexes' => array(
282
      'timestamp' => array('timestamp'),
283
    ),
284
  );
285
  $schema['feeds_log'] = array(
286
    'description' => 'Table that contains logs of feeds events.',
287
    'fields' => array(
288
      'flid' => array(
289
        'type' => 'serial',
290
        'not null' => TRUE,
291
        'description' => 'Primary Key: Unique feeds event ID.',
292
      ),
293
      'id' => array(
294
        'type' => 'varchar',
295
        'length' => 128,
296
        'not null' => TRUE,
297
        'default' => '',
298
        'description' => 'The id of the importer that logged the event.',
299
      ),
300
      'feed_nid' => array(
301
        'type' => 'int',
302
        'unsigned' => TRUE,
303
        'not null' => TRUE,
304
        'description' => 'Node id of the source, if available.',
305
      ),
306
      'log_time' => array(
307
        'type' => 'int',
308
        'not null' => TRUE,
309
        'default' => 0,
310
        'description' => 'Unix timestamp of when event occurred.',
311
      ),
312
      'request_time' => array(
313
        'type' => 'int',
314
        'not null' => TRUE,
315
        'default' => 0,
316
        'description' => 'Unix timestamp of the request when the event occurred.',
317
      ),
318
      'type' => array(
319
        'type' => 'varchar',
320
        'length' => 64,
321
        'not null' => TRUE,
322
        'default' => '',
323
        'description' => 'Type of log message, for example "feeds_import"."',
324
      ),
325
      'message' => array(
326
        'type' => 'text',
327
        'not null' => TRUE,
328
        'size' => 'big',
329
        'description' => 'Text of log message to be passed into the t() function.',
330
      ),
331
      'variables' => array(
332
        'type' => 'blob',
333
        'not null' => TRUE,
334
        'size' => 'big',
335
        'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
336
      ),
337
      'severity' => array(
338
        'type' => 'int',
339
        'unsigned' => TRUE,
340
        'not null' => TRUE,
341
        'default' => 0,
342
        'size' => 'tiny',
343
        'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
344
      ),
345
    ),
346
    'primary key' => array('flid'),
347
    'indexes' => array(
348
      'id' => array('id'),
349
      'id_feed_nid' => array('id', 'feed_nid'),
350
      'request_time' => array('request_time'),
351
      'log_time' => array('log_time'),
352
      'type' => array('type'),
353
    ),
354
  );
355

    
356
  $schema['cache_feeds_http'] = drupal_get_schema_unprocessed('system', 'cache');
357
  $schema['cache_feeds_http']['description'] = 'Cache table for Feeds downloads.';
358

    
359
  return $schema;
360
}
361

    
362
/**
363
 * Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
364
 * result.
365
 */
366
function feeds_update_7100() {
367
  $spec = array(
368
    'type' => 'text',
369
    'size' => 'big',
370
    'not null' => FALSE,
371
    'description' => 'State of import or clearing batches.',
372
    'serialize' => TRUE,
373
  );
374
  db_change_field('feeds_source', 'batch', 'state', $spec);
375

    
376
  $spec = array(
377
    'type' => 'text',
378
    'size' => 'big',
379
    'not null' => FALSE,
380
    'description' => 'Cache for fetcher result.',
381
    'serialize' => TRUE,
382
  );
383
  db_add_field('feeds_source', 'fetcher_result', $spec);
384
}
385

    
386
/**
387
 * Add imported timestamp to feeds_source table.
388
 */
389
function feeds_update_7201() {
390
  $spec = array(
391
    'type' => 'int',
392
    'not null' => TRUE,
393
    'default' => 0,
394
    'unsigned' => TRUE,
395
    'description' => 'Timestamp when this source was imported last.',
396
  );
397
  db_add_field('feeds_source', 'imported', $spec);
398
}
399

    
400
/**
401
 * Create a single feeds_item table tracking all imports.
402
 */
403
function feeds_update_7202() {
404
  $spec = array(
405
    'description' => 'Tracks items such as nodes, terms, users.',
406
    'fields' => array(
407
      'entity_type' => array(
408
        'type' => 'varchar',
409
        'length' => 32,
410
        'not null' => TRUE,
411
        'default' => '',
412
        'description' => 'The entity type.',
413
      ),
414
      'entity_id' => array(
415
        'type' => 'int',
416
        'unsigned' => TRUE,
417
        'not null' => TRUE,
418
        'description' => 'The imported entity\'s serial id.',
419
      ),
420
      'id' => array(
421
        'type' => 'varchar',
422
        'length' => 128,
423
        'not null' => TRUE,
424
        'default' => '',
425
        'description' => 'The id of the importer that created this item.',
426
      ),
427
      'feed_nid' => array(
428
        'type' => 'int',
429
        'unsigned' => TRUE,
430
        'not null' => TRUE,
431
        'description' => 'Node id of the source, if available.',
432
      ),
433
      'imported' => array(
434
        'type' => 'int',
435
        'not null' => TRUE,
436
        'default' => 0,
437
        'description' => 'Import date of the feed item, as a Unix timestamp.',
438
      ),
439
      'url' => array(
440
        'type' => 'text',
441
        'not null' => TRUE,
442
        'description' => 'Link to the feed item.',
443
      ),
444
      'guid' => array(
445
        'type' => 'text',
446
        'not null' => TRUE,
447
        'description' => 'Unique identifier for the feed item.'
448
      ),
449
      'hash' => array(
450
        'type' => 'varchar',
451
        'length' => 32, // The length of an MD5 hash.
452
        'not null' => TRUE,
453
        'default' => '',
454
        'description' => 'The hash of the source item.',
455
      ),
456
    ),
457
    'primary key' => array('entity_type', 'entity_id'),
458
    'indexes' => array(
459
      'id' => array('id'),
460
      'feed_nid' => array('feed_nid'),
461
      'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
462
      'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
463
      'imported' => array('imported'),
464
    ),
465
  );
466
  db_create_table('feeds_item', $spec);
467
  // Copy all existing values from old tables and drop them.
468
  $insert = "INSERT INTO {feeds_item} (entity_type, entity_id, id, feed_nid, imported, url, guid, hash)";
469
  db_query($insert . " SELECT 'node', nid, id, feed_nid, imported, url, guid, hash FROM {feeds_node_item}");
470
  db_query($insert . " SELECT 'taxonomy_term', tid, id, feed_nid, 0, '', '', '' FROM {feeds_term_item}");
471
  db_drop_table('feeds_node_item');
472
  db_drop_table('feeds_term_item');
473
}
474

    
475
/**
476
 * Add feeds_log table.
477
 */
478
function feeds_update_7203() {
479
  $schema = array(
480
    'description' => 'Table that contains logs of feeds events.',
481
    'fields' => array(
482
      'flid' => array(
483
        'type' => 'serial',
484
        'not null' => TRUE,
485
        'description' => 'Primary Key: Unique feeds event ID.',
486
      ),
487
      'id' => array(
488
        'type' => 'varchar',
489
        'length' => 128,
490
        'not null' => TRUE,
491
        'default' => '',
492
        'description' => 'The id of the importer that logged the event.',
493
      ),
494
      'feed_nid' => array(
495
        'type' => 'int',
496
        'unsigned' => TRUE,
497
        'not null' => TRUE,
498
        'description' => 'Node id of the source, if available.',
499
      ),
500
      'log_time' => array(
501
        'type' => 'int',
502
        'not null' => TRUE,
503
        'default' => 0,
504
        'description' => 'Unix timestamp of when event occurred.',
505
      ),
506
      'request_time' => array(
507
        'type' => 'int',
508
        'not null' => TRUE,
509
        'default' => 0,
510
        'description' => 'Unix timestamp of the request when the event occurred.',
511
      ),
512
      'type' => array(
513
        'type' => 'varchar',
514
        'length' => 64,
515
        'not null' => TRUE,
516
        'default' => '',
517
        'description' => 'Type of log message, for example "feeds_import"."',
518
      ),
519
      'message' => array(
520
        'type' => 'text',
521
        'not null' => TRUE,
522
        'size' => 'big',
523
        'description' => 'Text of log message to be passed into the t() function.',
524
      ),
525
      'variables' => array(
526
        'type' => 'blob',
527
        'not null' => TRUE,
528
        'size' => 'big',
529
        'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
530
      ),
531
      'severity' => array(
532
        'type' => 'int',
533
        'unsigned' => TRUE,
534
        'not null' => TRUE,
535
        'default' => 0,
536
        'size' => 'tiny',
537
        'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
538
      ),
539
    ),
540
    'primary key' => array('flid'),
541
    'indexes' => array(
542
      'id' => array('id'),
543
      'id_feed_nid' => array('id', 'feed_nid'),
544
      'request_time' => array('request_time'),
545
      'log_time' => array('log_time'),
546
      'type' => array('type'),
547
    ),
548
  );
549
  db_create_table('feeds_log', $schema);
550
}
551

    
552
/**
553
 * Add index for looking up by entity_type + url/ guid to feeds_item table.
554
 */
555
function feeds_update_7204() {
556
  db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
557
  db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
558
}
559

    
560
/**
561
 * Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
562
 */
563
function feeds_update_7205() {
564
  db_drop_primary_key('feeds_item');
565
  db_drop_index('feeds_item', 'lookup_url');
566
  db_drop_index('feeds_item', 'lookup_guid');
567
  db_drop_index('feeds_item', 'global_lookup_url');
568
  db_drop_index('feeds_item', 'global_lookup_guid');
569

    
570
  db_change_field('feeds_item', 'entity_type', 'entity_type', array(
571
    'type' => 'varchar',
572
    'length' => 32,
573
    'not null' => TRUE,
574
    'default' => '',
575
    'description' => 'The entity type.',
576
  ));
577

    
578
  db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
579
  db_add_index('feeds_item', 'lookup_url', array('entity_type', 'id', 'feed_nid', array('url', 128)));
580
  db_add_index('feeds_item', 'lookup_guid', array('entity_type', 'id', 'feed_nid', array('guid', 128)));
581
  db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
582
  db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
583
}
584

    
585
/**
586
 * Change state and fetcher_result fields from text to blob.
587
 */
588
function feeds_update_7206() {
589
  db_change_field('feeds_source', 'state', 'state', array(
590
    'type' => 'blob',
591
    'size' => 'big',
592
    'not null' => FALSE,
593
    'description' => 'State of import or clearing batches.',
594
    'serialize' => TRUE,
595
  ));
596

    
597
  db_change_field('feeds_source', 'fetcher_result', 'fetcher_result', array(
598
    'type' => 'blob',
599
    'size' => 'big',
600
    'not null' => FALSE,
601
    'description' => 'Cache for fetcher result.',
602
    'serialize' => TRUE,
603
  ));
604
}
605

    
606
/**
607
 * Change config fields from text to big blobs.
608
 */
609
function feeds_update_7207() {
610
  db_change_field('feeds_importer', 'config', 'config', array(
611
    'type' => 'blob',
612
    'size' => 'big',
613
    'not null' => FALSE,
614
    'description' => 'Configuration of the feeds object.',
615
    'serialize' => TRUE,
616
  ));
617

    
618
  db_change_field('feeds_source', 'config', 'config', array(
619
    'type' => 'blob',
620
    'size' => 'big',
621
    'not null' => FALSE,
622
    'description' => 'Configuration of the feeds object.',
623
    'serialize' => TRUE,
624
  ));
625
}
626

    
627
/**
628
 * Update to use generic bundle handling.
629
 */
630
function feeds_update_7208(&$sandbox) {
631

    
632
  if (!isset($sandbox['importers'])) {
633
    // Get all importers.
634
    $sandbox['importers'] = db_query("SELECT id FROM {feeds_importer}")->fetchCol();
635
    $sandbox['total'] = count($sandbox['importers']);
636
  }
637

    
638
  $importer = array_pop($sandbox['importers']);
639
  $config = db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $importer))->fetchField();
640

    
641
  if ($config) {
642
    $config = unserialize($config);
643

    
644
    switch ($config['processor']['plugin_key']) {
645
      case 'FeedsNodeProcessor':
646
        $config_key = 'content_type';
647
        break;
648

    
649
      case 'FeedsTermProcessor':
650
        $config_key = 'vocabulary';
651
        break;
652

    
653
      default:
654
        $config_key = FALSE;
655
        break;
656
    }
657

    
658
    if ($config_key && isset($config['processor']['config'][$config_key])) {
659
      $config['processor']['config']['bundle'] = $config['processor']['config'][$config_key];
660
      unset($config['processor']['config'][$config_key]);
661

    
662
      // Update databse.
663
      db_update('feeds_importer')
664
        ->fields(array(
665
          'config' => serialize($config),
666
        ))
667
        ->condition('id', $importer)
668
        ->execute();
669
    }
670

    
671
    $sandbox['#finished'] = 1 - count($sandbox['importers']) / $sandbox['total'];
672
  }
673
  else {
674
    $sandbox['#finished'] = 1;
675
  }
676
}
677

    
678
/**
679
 * Reschedules feeds jobs.
680
 */
681
function feeds_update_7209() {
682
  // Reschedule all importers.
683
  variable_set('feeds_reschedule', TRUE);
684

    
685
  // Our expire callback has changed names, remove all existing callbacks.
686
  db_delete('job_schedule')
687
    ->condition('name', 'feeds_importer_expire')
688
    ->execute();
689

    
690
  DrupalQueue::get('feeds_importer_expire')->deleteQueue();
691
}
692

    
693
 /**
694
  * Does nothing. Update removed.
695
  */
696
function feeds_update_7211(&$sandbox) {
697
}
698

    
699
/**
700
 * Create {cache_feeds_http} table.
701
 */
702
function feeds_update_7212() {
703
  if (!db_table_exists('cache_feeds_http')) {
704
    $schema = drupal_get_schema_unprocessed('system', 'cache');
705
    $schema['description'] = 'Cache table for Feeds downloads.';
706
    db_create_table('cache_feeds_http', $schema);
707
  }
708
}