Projet

Général

Profil

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

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

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
    'simplexml' => array(
16
      'title' => $t('SimpleXML'),
17
      'value' => extension_loaded('SimpleXML') ? $t('Enabled') : $t('Disabled'),
18
      'description' => $t('SimpleXML PHP module is required for Feeds Syndication Parser.'),
19
      'severity' => REQUIREMENT_INFO,
20
    ),
21
    'simplepie' => array(
22
      'title' => $t('SimplePie'),
23
      'value' => $t('Unknown at install time.'),
24
      'description' => $t('SimplePie library is required for Feeds SimplePie Parser.'),
25
      'severity' => REQUIREMENT_INFO,
26
    )
27
  );
28
  if ($phase == 'runtime') {
29
    // Check for SimpleXML, required by FeedsSyndicationParser.
30
    if (extension_loaded('SimpleXML')) {
31
      $requirements['simplexml']['severity'] = REQUIREMENT_OK;
32
    }
33
    else {
34
      $requirements['simplexml']['severity'] = REQUIREMENT_WARNING;
35
      $requirements['simplexml']['description'] .= ' ' . t('It has been disabled at compile time, seek instructions from the server mantainers to enable it.');
36
    }
37
    // Check for SimplePie, required by FeedsSimplePieParser.
38
    if (feeds_simplepie_exists()) {
39
      $requirements['simplepie']['value'] = t('Enabled');
40
      $requirements['simplepie']['severity'] = REQUIREMENT_OK;
41
    }
42
    else {
43
      $requirements['simplepie']['value'] = t('Not installed');
44
      $requirements['simplepie']['severity'] = REQUIREMENT_WARNING;
45
      $requirements['simplepie']['description'] .= ' ' . t(
46
        'Download the compiled version of the library from <a href="@simplepie-download-url">SimplePie download page</a>.',
47
        array('@simplepie-download-url' => 'http://simplepie.org/downloads/')
48
      );
49
    }
50
  }
51
  return $requirements;
52
}
53

    
54
/**
55
  * Implement hook_uninstall()
56
  */
57
function feeds_uninstall() {
58
  variable_del('http_request_timeout');
59
}
60

    
61
/**
62
 * Implements hook_schema().
63
 */
64
function feeds_schema() {
65
  $schema = array();
66

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

    
353
/**
354
 * Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
355
 * result.
356
 */
357
function feeds_update_7100() {
358
  $spec = array(
359
    'type' => 'text',
360
    'size' => 'big',
361
    'not null' => FALSE,
362
    'description' => 'State of import or clearing batches.',
363
    'serialize' => TRUE,
364
  );
365
  db_change_field('feeds_source', 'batch', 'state', $spec);
366

    
367
  $spec = array(
368
    'type' => 'text',
369
    'size' => 'big',
370
    'not null' => FALSE,
371
    'description' => 'Cache for fetcher result.',
372
    'serialize' => TRUE,
373
  );
374
  db_add_field('feeds_source', 'fetcher_result', $spec);
375
}
376

    
377
/**
378
 * Add imported timestamp to feeds_source table.
379
 */
380
function feeds_update_7201() {
381
  $spec = array(
382
    'type' => 'int',
383
    'not null' => TRUE,
384
    'default' => 0,
385
    'unsigned' => TRUE,
386
    'description' => 'Timestamp when this source was imported last.',
387
  );
388
  db_add_field('feeds_source', 'imported', $spec);
389
}
390

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

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

    
543
/**
544
 * Add index for looking up by entity_type + url/ guid to feeds_item table.
545
 */
546
function feeds_update_7204() {
547
  db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
548
  db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
549
}
550

    
551
/**
552
 * Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
553
 */
554
function feeds_update_7205() {
555
  db_drop_primary_key('feeds_item');
556
  db_drop_index('feeds_item', 'lookup_url');
557
  db_drop_index('feeds_item', 'lookup_guid');
558
  db_drop_index('feeds_item', 'global_lookup_url');
559
  db_drop_index('feeds_item', 'global_lookup_guid');
560

    
561
  db_change_field('feeds_item', 'entity_type', 'entity_type', array(
562
    'type' => 'varchar',
563
    'length' => 32,
564
    'not null' => TRUE,
565
    'default' => '',
566
    'description' => 'The entity type.',
567
  ));
568

    
569
  db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
570
  db_add_index('feeds_item', 'lookup_url', array('entity_type', 'id', 'feed_nid', array('url', 128)));
571
  db_add_index('feeds_item', 'lookup_guid', array('entity_type', 'id', 'feed_nid', array('guid', 128)));
572
  db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
573
  db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
574
}
575

    
576
/**
577
 * Change state and fetcher_result fields from text to blob.
578
 */
579
function feeds_update_7206() {
580
  db_change_field('feeds_source', 'state', 'state', array(
581
    'type' => 'blob',
582
    'size' => 'big',
583
    'not null' => FALSE,
584
    'description' => 'State of import or clearing batches.',
585
    'serialize' => TRUE,
586
  ));
587

    
588
  db_change_field('feeds_source', 'fetcher_result', 'fetcher_result', array(
589
    'type' => 'blob',
590
    'size' => 'big',
591
    'not null' => FALSE,
592
    'description' => 'Cache for fetcher result.',
593
    'serialize' => TRUE,
594
  ));
595
}
596

    
597
/**
598
 * Change config fields from text to big blobs.
599
 */
600
function feeds_update_7207() {
601
  db_change_field('feeds_importer', 'config', 'config', array(
602
    'type' => 'blob',
603
    'size' => 'big',
604
    'not null' => FALSE,
605
    'description' => 'Configuration of the feeds object.',
606
    'serialize' => TRUE,
607
  ));
608

    
609
  db_change_field('feeds_source', 'config', 'config', array(
610
    'type' => 'blob',
611
    'size' => 'big',
612
    'not null' => FALSE,
613
    'description' => 'Configuration of the feeds object.',
614
    'serialize' => TRUE,
615
  ));
616
}
617

    
618
/**
619
 * Update to use generic bundle handling.
620
 */
621
function feeds_update_7208(&$sandbox) {
622

    
623
  if (!isset($sandbox['importers'])) {
624
    // Get all importers.
625
    $sandbox['importers'] = db_query("SELECT id FROM {feeds_importer}")->fetchCol();
626
    $sandbox['total'] = count($sandbox['importers']);
627
  }
628

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

    
632
  if ($config) {
633
    $config = unserialize($config);
634

    
635
    switch ($config['processor']['plugin_key']) {
636
      case 'FeedsNodeProcessor':
637
        $config_key = 'content_type';
638
        break;
639

    
640
      case 'FeedsTermProcessor':
641
        $config_key = 'vocabulary';
642
        break;
643

    
644
      default:
645
        $config_key = FALSE;
646
        break;
647
    }
648

    
649
    if ($config_key && isset($config['processor']['config'][$config_key])) {
650
      $config['processor']['config']['bundle'] = $config['processor']['config'][$config_key];
651
      unset($config['processor']['config'][$config_key]);
652

    
653
      // Update databse.
654
      db_update('feeds_importer')
655
        ->fields(array(
656
          'config' => serialize($config),
657
        ))
658
        ->condition('id', $importer)
659
        ->execute();
660
    }
661

    
662
    $sandbox['#finished'] = 1 - count($sandbox['importers']) / $sandbox['total'];
663
  }
664
  else {
665
    $sandbox['#finished'] = 1;
666
  }
667
}