Newer
Older
Alex Barth
committed
Alex Barth
committed
* Schema definitions install/update/uninstall hooks.
/**
* Implements hook_requirements().
*/
function feeds_requirements($phase) {
$t = get_t();
$requirements = array();
module_load_include('module', 'feeds');
// Check if we have any SimplePie importers.
$needs_simplepie = FALSE;
foreach (feeds_importer_load_all() as $importer) {
if ($importer->config['parser']['plugin_key'] === 'FeedsSimplePieParser') {
$needs_simplepie = TRUE;
break;
}
if (!$needs_simplepie) {
return $requirements;
}
$requirements['simplepie'] = array(
'title' => $t('SimplePie'),
'value' => $t('Installed'),
'description' => $t('The SimplePie library is required for Feeds SimplePie Parser.'),
'severity' => REQUIREMENT_OK,
);
if (!feeds_simplepie_exists()) {
$requirements['simplepie']['value'] = $t('Not installed');
$folder = drupal_get_path('module', 'feeds') . '/libraries';
if (module_exists('libraries')) {
$folder = 'sites/all/libraries/simplepie';
$args = array(
'!url' => 'http://simplepie.org/downloads/',
'%folder' => $folder,
'%file' => 'simplepie.compiled.php',
);
$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);
$requirements['simplepie']['severity'] = REQUIREMENT_ERROR;
return $requirements;
}
/**
* Implement hook_uninstall()
*/
function feeds_uninstall() {
variable_del('http_request_timeout');
variable_del('feeds_reschedule');
}
*/
function feeds_schema() {
Alex Barth
committed
$schema = array();
$schema['feeds_importer'] = array(
'description' => 'Configuration of feeds objects.',
'export' => array(
'key' => 'id',
Alex Barth
committed
'identifier' => 'feeds_importer',
'default hook' => 'feeds_importer_default', // Function hook name.
Alex Barth
committed
'owner' => 'feeds',
'api' => 'feeds_importer_default', // Base name for api include files.
'minimum_version' => 1,
'current_version' => 1,
),
),
'fields' => array(
'id' => array(
'type' => 'varchar',
Alex Barth
committed
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the fields object.',
),
'config' => array(
theduke
committed
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the feeds object.',
'serialize' => TRUE,
),
),
Alex Barth
committed
'primary key' => array('id'),
$schema['feeds_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
Alex Barth
committed
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
Alex Barth
committed
'feed_nid' => array(
Alex Barth
committed
'not null' => TRUE,
'default' => 0,
Alex Barth
committed
'description' => 'Node nid if this particular source is attached to a feed node.',
Alex Barth
committed
'config' => array(
theduke
committed
'type' => 'blob',
'size' => 'big',
Alex Barth
committed
'description' => 'Configuration of the source.',
Alex Barth
committed
'source' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Main source resource identifier. E. g. a path or a URL.',
Alex Barth
committed
),
Chris Leppanen
committed
'type' => 'blob',
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
),
'fetcher_result' => array(
Chris Leppanen
committed
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
Alex Barth
committed
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
Alex Barth
committed
'primary key' => array('id', 'feed_nid'),
Alex Barth
committed
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'id_source' => array('id', array('source', 128)),
),
);
$schema['feeds_item'] = array(
'description' => 'Tracks items such as nodes, terms, users.',
Alex Barth
committed
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
Dave Reid
committed
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
),
'entity_id' => array(
Alex Barth
committed
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The imported entity\'s serial id.',
Alex Barth
committed
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that created this item.',
Alex Barth
committed
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, if available.',
Alex Barth
committed
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
Alex Barth
committed
'description' => 'Import date of the feed item, as a Unix timestamp.',
Alex Barth
committed
),
'url' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Link to the feed item.',
Alex Barth
committed
),
'guid' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'Unique identifier for the feed item.'
Alex Barth
committed
),
'hash' => array(
'type' => 'varchar',
'length' => 32, // The length of an MD5 hash.
'not null' => TRUE,
'default' => '',
'description' => 'The hash of the source item.',
Alex Barth
committed
),
'primary key' => array('entity_type', 'entity_id'),
Alex Barth
committed
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
Dave Reid
committed
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
'global_lookup_url' => array('entity_type', array('url', 128)),
'global_lookup_guid' => array('entity_type', array('guid', 128)),
Alex Barth
committed
'imported' => array('imported'),
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
$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,
Alex Barth
committed
'description' => 'The URL of the hub endpoint of this subscription.',
),
'topic' => array(
'type' => 'text',
'not null' => TRUE,
Alex Barth
committed
'description' => 'The topic URL (feed URL) of this subscription.',
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
),
'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'),
),
);
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
$schema['feeds_log'] = array(
'description' => 'Table that contains logs of feeds events.',
'fields' => array(
'flid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique feeds event ID.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that logged the event.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, if available.',
),
'log_time' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of when event occurred.',
),
'request_time' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of the request when the event occurred.',
),
'type' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Type of log message, for example "feeds_import"."',
),
'message' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => 'Text of log message to be passed into the t() function.',
),
'variables' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
),
'severity' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
),
),
'primary key' => array('flid'),
'indexes' => array(
'id' => array('id'),
'id_feed_nid' => array('id', 'feed_nid'),
'request_time' => array('request_time'),
'log_time' => array('log_time'),
'type' => array('type'),
),
);
return $schema;
}
/**
* Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
* result.
*/
Dave Reid
committed
function feeds_update_7100() {
$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);
}
Alex Barth
committed
/**
* Add imported timestamp to feeds_source table.
*/
Dave Reid
committed
function feeds_update_7201() {
Alex Barth
committed
$spec = array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
);
db_add_field('feeds_source', 'imported', $spec);
}
/**
* Create a single feeds_item table tracking all imports.
*/
Dave Reid
committed
function feeds_update_7202() {
$spec = array(
'description' => 'Tracks items such as nodes, terms, users.',
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
Dave Reid
committed
'length' => 32,
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
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
),
'entity_id' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'The imported entity\'s serial id.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that created this item.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, 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 source item.',
),
),
'primary key' => array('entity_type', 'entity_id'),
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
Dave Reid
committed
'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
'imported' => array('imported'),
),
);
db_create_table('feeds_item', $spec);
// Copy all existing values from old tables and drop them.
$insert = "INSERT INTO {feeds_item} (entity_type, entity_id, id, feed_nid, imported, url, guid, hash)";
db_query($insert . " SELECT 'node', nid, id, feed_nid, imported, url, guid, hash FROM {feeds_node_item}");
db_query($insert . " SELECT 'taxonomy_term', tid, id, feed_nid, 0, '', '', '' FROM {feeds_term_item}");
db_drop_table('feeds_node_item');
db_drop_table('feeds_term_item');
}
Dave Reid
committed
function feeds_update_7203() {
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
$schema = array(
'description' => 'Table that contains logs of feeds events.',
'fields' => array(
'flid' => array(
'type' => 'serial',
'not null' => TRUE,
'description' => 'Primary Key: Unique feeds event ID.',
),
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'The id of the importer that logged the event.',
),
'feed_nid' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'description' => 'Node id of the source, if available.',
),
'log_time' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of when event occurred.',
),
'request_time' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'description' => 'Unix timestamp of the request when the event occurred.',
),
'type' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Type of log message, for example "feeds_import"."',
),
'message' => array(
'type' => 'text',
'not null' => TRUE,
'size' => 'big',
'description' => 'Text of log message to be passed into the t() function.',
),
'variables' => array(
'type' => 'blob',
'not null' => TRUE,
'size' => 'big',
'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
),
'severity' => array(
'type' => 'int',
'unsigned' => TRUE,
'not null' => TRUE,
'default' => 0,
'size' => 'tiny',
'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
),
),
'primary key' => array('flid'),
'indexes' => array(
'id' => array('id'),
'id_feed_nid' => array('id', 'feed_nid'),
'request_time' => array('request_time'),
'log_time' => array('log_time'),
'type' => array('type'),
),
);
db_create_table('feeds_log', $schema);
}
/**
* Add index for looking up by entity_type + url/ guid to feeds_item table.
*/
Dave Reid
committed
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
576
577
function feeds_update_7204() {
db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
}
/**
* Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
*/
function feeds_update_7205() {
db_drop_primary_key('feeds_item');
db_drop_index('feeds_item', 'lookup_url');
db_drop_index('feeds_item', 'lookup_guid');
db_drop_index('feeds_item', 'global_lookup_url');
db_drop_index('feeds_item', 'global_lookup_guid');
db_change_field('feeds_item', 'entity_type', 'entity_type', array(
'type' => 'varchar',
'length' => 32,
'not null' => TRUE,
'default' => '',
'description' => 'The entity type.',
));
db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
db_add_index('feeds_item', 'lookup_url', array('entity_type', 'id', 'feed_nid', array('url', 128)));
db_add_index('feeds_item', 'lookup_guid', array('entity_type', 'id', 'feed_nid', array('guid', 128)));
db_add_index('feeds_item', 'global_lookup_url', array('entity_type', array('url', 128)));
db_add_index('feeds_item', 'global_lookup_guid', array('entity_type', array('guid', 128)));
Chris Leppanen
committed
/**
* Change state and fetcher_result fields from text to blob.
*/
function feeds_update_7206() {
db_change_field('feeds_source', 'state', 'state', array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
));
db_change_field('feeds_source', 'fetcher_result', 'fetcher_result', array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
'serialize' => TRUE,
));
}
theduke
committed
/**
* Change config fields from text to big blobs.
*/
function feeds_update_7207() {
db_change_field('feeds_importer', 'config', 'config', array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the feeds object.',
'serialize' => TRUE,
));
db_change_field('feeds_source', 'config', 'config', array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the feeds object.',
'serialize' => TRUE,
));
}
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
/**
* Update to use generic bundle handling.
*/
function feeds_update_7208(&$sandbox) {
if (!isset($sandbox['importers'])) {
// Get all importers.
$sandbox['importers'] = db_query("SELECT id FROM {feeds_importer}")->fetchCol();
$sandbox['total'] = count($sandbox['importers']);
}
$importer = array_pop($sandbox['importers']);
$config = db_query("SELECT config FROM {feeds_importer} WHERE id = :id", array(':id' => $importer))->fetchField();
if ($config) {
$config = unserialize($config);
switch ($config['processor']['plugin_key']) {
case 'FeedsNodeProcessor':
$config_key = 'content_type';
break;
case 'FeedsTermProcessor':
$config_key = 'vocabulary';
break;
default:
$config_key = FALSE;
break;
}
if ($config_key && isset($config['processor']['config'][$config_key])) {
$config['processor']['config']['bundle'] = $config['processor']['config'][$config_key];
unset($config['processor']['config'][$config_key]);
// Update databse.
db_update('feeds_importer')
->fields(array(
'config' => serialize($config),
))
->condition('id', $importer)
->execute();
}
damienmckenna
committed
$sandbox['#finished'] = 1 - count($sandbox['importers']) / $sandbox['total'];
}
else {
$sandbox['#finished'] = 1;
}
/**
* Reschedules feeds jobs.
*/
function feeds_update_7209() {
// Reschedule all importers.
variable_set('feeds_reschedule', TRUE);
// Our expire callback has changed names, remove all existing callbacks.
db_delete('job_schedule')
->condition('name', 'feeds_importer_expire')
->execute();
DrupalQueue::get('feeds_importer_expire')->deleteQueue();
}