Projet

Général

Profil

Paste
Télécharger (22,8 ko) Statistiques
| Branche: | Révision:

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

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
 * Implements hook_install().
59
 */
60
function feeds_install() {
61
  // Activate our custom cache handler for the HTTP cache.
62
  variable_set('cache_class_cache_feeds_http', 'FeedsHTTPCache');
63
}
64

    
65
/**
66
 * Implements hook_uninstall().
67
 */
68
function feeds_uninstall() {
69
  variable_del('cache_class_cache_feeds_http');
70
  variable_del('cache_flush_cache_feeds_http');
71
  variable_del('default_feeds_importer');
72
  variable_del('feeds_debug');
73
  variable_del('feeds_http_file_cache_dir');
74
  variable_del('feeds_importer_class');
75
  variable_del('feeds_in_progress_dir');
76
  variable_del('feeds_library_dir');
77
  variable_del('feeds_never_use_curl');
78
  variable_del('feeds_process_limit');
79
  variable_del('feeds_reschedule');
80
  variable_del('feeds_source_class');
81
  variable_del('feeds_sync_cache_feeds_http_interval');
82
  variable_del('feeds_sync_cache_feeds_http_last_check');
83
  variable_del('feeds_use_mbstring');
84
  variable_del('http_request_timeout');
85

    
86
  // Remove Feeds related jobs from job scheduler.
87
  $names = db_or()
88
    ->condition('name', 'feeds_source_import')
89
    ->condition('name', 'feeds_source_clear')
90
    ->condition('name', 'feeds_source_expire')
91
    ->condition('name', 'feeds_push_unsubscribe');
92

    
93
  db_delete('job_schedule')
94
    ->condition($names)
95
    ->execute();
96
}
97

    
98
/**
99
 * Implements hook_schema().
100
 */
101
function feeds_schema() {
102
  $schema = array();
103

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

    
391
  $schema['cache_feeds_http'] = drupal_get_schema_unprocessed('system', 'cache');
392
  $schema['cache_feeds_http']['description'] = 'Cache table for Feeds downloads.';
393

    
394
  return $schema;
395
}
396

    
397
/**
398
 * Rename feeds_source.batch to feeds_source.state, add slot for caching fetcher
399
 * result.
400
 */
401
function feeds_update_7100() {
402
  $spec = array(
403
    'type' => 'text',
404
    'size' => 'big',
405
    'not null' => FALSE,
406
    'description' => 'State of import or clearing batches.',
407
    'serialize' => TRUE,
408
  );
409
  db_change_field('feeds_source', 'batch', 'state', $spec);
410

    
411
  $spec = array(
412
    'type' => 'text',
413
    'size' => 'big',
414
    'not null' => FALSE,
415
    'description' => 'Cache for fetcher result.',
416
    'serialize' => TRUE,
417
  );
418
  db_add_field('feeds_source', 'fetcher_result', $spec);
419
}
420

    
421
/**
422
 * Add imported timestamp to feeds_source table.
423
 */
424
function feeds_update_7201() {
425
  $spec = array(
426
    'type' => 'int',
427
    'not null' => TRUE,
428
    'default' => 0,
429
    'unsigned' => TRUE,
430
    'description' => 'Timestamp when this source was imported last.',
431
  );
432
  db_add_field('feeds_source', 'imported', $spec);
433
}
434

    
435
/**
436
 * Create a single feeds_item table tracking all imports.
437
 */
438
function feeds_update_7202() {
439
  $spec = array(
440
    'description' => 'Tracks items such as nodes, terms, users.',
441
    'fields' => array(
442
      'entity_type' => array(
443
        'type' => 'varchar',
444
        'length' => 32,
445
        'not null' => TRUE,
446
        'default' => '',
447
        'description' => 'The entity type.',
448
      ),
449
      'entity_id' => array(
450
        'type' => 'int',
451
        'unsigned' => TRUE,
452
        'not null' => TRUE,
453
        'description' => 'The imported entity\'s serial id.',
454
      ),
455
      'id' => array(
456
        'type' => 'varchar',
457
        'length' => 128,
458
        'not null' => TRUE,
459
        'default' => '',
460
        'description' => 'The id of the importer that created this item.',
461
      ),
462
      'feed_nid' => array(
463
        'type' => 'int',
464
        'unsigned' => TRUE,
465
        'not null' => TRUE,
466
        'description' => 'Node id of the source, if available.',
467
      ),
468
      'imported' => array(
469
        'type' => 'int',
470
        'not null' => TRUE,
471
        'default' => 0,
472
        'description' => 'Import date of the feed item, as a Unix timestamp.',
473
      ),
474
      'url' => array(
475
        'type' => 'text',
476
        'not null' => TRUE,
477
        'description' => 'Link to the feed item.',
478
      ),
479
      'guid' => array(
480
        'type' => 'text',
481
        'not null' => TRUE,
482
        'description' => 'Unique identifier for the feed item.',
483
      ),
484
      'hash' => array(
485
        'type' => 'varchar',
486
        // 32 is the length of an MD5 hash.
487
        'length' => 32,
488
        'not null' => TRUE,
489
        'default' => '',
490
        'description' => 'The hash of the source item.',
491
      ),
492
    ),
493
    'primary key' => array('entity_type', 'entity_id'),
494
    'indexes' => array(
495
      'id' => array('id'),
496
      'feed_nid' => array('feed_nid'),
497
      'lookup_url' => array('entity_type', 'id', 'feed_nid', array('url', 128)),
498
      'lookup_guid' => array('entity_type', 'id', 'feed_nid', array('guid', 128)),
499
      'imported' => array('imported'),
500
    ),
501
  );
502
  db_create_table('feeds_item', $spec);
503
  // Copy all existing values from old tables and drop them.
504
  $insert = "INSERT INTO {feeds_item} (entity_type, entity_id, id, feed_nid, imported, url, guid, hash)";
505
  db_query($insert . " SELECT 'node', nid, id, feed_nid, imported, url, guid, hash FROM {feeds_node_item}");
506
  db_query($insert . " SELECT 'taxonomy_term', tid, id, feed_nid, 0, '', '', '' FROM {feeds_term_item}");
507
  db_drop_table('feeds_node_item');
508
  db_drop_table('feeds_term_item');
509
}
510

    
511
/**
512
 * Add feeds_log table.
513
 */
514
function feeds_update_7203() {
515
  $schema = array(
516
    'description' => 'Table that contains logs of feeds events.',
517
    'fields' => array(
518
      'flid' => array(
519
        'type' => 'serial',
520
        'not null' => TRUE,
521
        'description' => 'Primary Key: Unique feeds event ID.',
522
      ),
523
      'id' => array(
524
        'type' => 'varchar',
525
        'length' => 128,
526
        'not null' => TRUE,
527
        'default' => '',
528
        'description' => 'The id of the importer that logged the event.',
529
      ),
530
      'feed_nid' => array(
531
        'type' => 'int',
532
        'unsigned' => TRUE,
533
        'not null' => TRUE,
534
        'description' => 'Node id of the source, if available.',
535
      ),
536
      'log_time' => array(
537
        'type' => 'int',
538
        'not null' => TRUE,
539
        'default' => 0,
540
        'description' => 'Unix timestamp of when event occurred.',
541
      ),
542
      'request_time' => array(
543
        'type' => 'int',
544
        'not null' => TRUE,
545
        'default' => 0,
546
        'description' => 'Unix timestamp of the request when the event occurred.',
547
      ),
548
      'type' => array(
549
        'type' => 'varchar',
550
        'length' => 64,
551
        'not null' => TRUE,
552
        'default' => '',
553
        'description' => 'Type of log message, for example "feeds_import"."',
554
      ),
555
      'message' => array(
556
        'type' => 'text',
557
        'not null' => TRUE,
558
        'size' => 'big',
559
        'description' => 'Text of log message to be passed into the t() function.',
560
      ),
561
      'variables' => array(
562
        'type' => 'blob',
563
        'not null' => TRUE,
564
        'size' => 'big',
565
        'description' => 'Serialized array of variables that match the message string and that is passed into the t() function.',
566
      ),
567
      'severity' => array(
568
        'type' => 'int',
569
        'unsigned' => TRUE,
570
        'not null' => TRUE,
571
        'default' => 0,
572
        'size' => 'tiny',
573
        'description' => 'The severity level of the event; ranges from 0 (Emergency) to 7 (Debug)',
574
      ),
575
    ),
576
    'primary key' => array('flid'),
577
    'indexes' => array(
578
      'id' => array('id'),
579
      'id_feed_nid' => array('id', 'feed_nid'),
580
      'request_time' => array('request_time'),
581
      'log_time' => array('log_time'),
582
      'type' => array('type'),
583
    ),
584
  );
585
  db_create_table('feeds_log', $schema);
586
}
587

    
588
/**
589
 * Add index for looking up by entity_type + url/ guid to feeds_item table.
590
 */
591
function feeds_update_7204() {
592
  db_add_index('feeds_item', 'global_lookup_url', array(
593
    'entity_type',
594
    array('url', 128),
595
  ));
596
  db_add_index('feeds_item', 'global_lookup_guid', array(
597
    'entity_type',
598
    array('guid', 128),
599
  ));
600
}
601

    
602
/**
603
 * Shorten {feeds_item}.entity_type to 32 chars and shorten relevant indexes.
604
 */
605
function feeds_update_7205() {
606
  db_drop_primary_key('feeds_item');
607
  db_drop_index('feeds_item', 'lookup_url');
608
  db_drop_index('feeds_item', 'lookup_guid');
609
  db_drop_index('feeds_item', 'global_lookup_url');
610
  db_drop_index('feeds_item', 'global_lookup_guid');
611

    
612
  db_change_field('feeds_item', 'entity_type', 'entity_type', array(
613
    'type' => 'varchar',
614
    'length' => 32,
615
    'not null' => TRUE,
616
    'default' => '',
617
    'description' => 'The entity type.',
618
  ));
619

    
620
  db_add_primary_key('feeds_item', array('entity_type', 'entity_id'));
621
  db_add_index('feeds_item', 'lookup_url', array(
622
    'entity_type',
623
    'id',
624
    'feed_nid',
625
    array('url', 128),
626
  ));
627
  db_add_index('feeds_item', 'lookup_guid', array(
628
    'entity_type',
629
    'id',
630
    'feed_nid',
631
    array('guid', 128),
632
  ));
633
  db_add_index('feeds_item', 'global_lookup_url', array(
634
    'entity_type',
635
    array('url', 128),
636
  ));
637
  db_add_index('feeds_item', 'global_lookup_guid', array(
638
    'entity_type',
639
    array('guid', 128),
640
  ));
641
}
642

    
643
/**
644
 * Change state and fetcher_result fields from text to blob.
645
 */
646
function feeds_update_7206() {
647
  db_change_field('feeds_source', 'state', 'state', array(
648
    'type' => 'blob',
649
    'size' => 'big',
650
    'not null' => FALSE,
651
    'description' => 'State of import or clearing batches.',
652
    'serialize' => TRUE,
653
  ));
654

    
655
  db_change_field('feeds_source', 'fetcher_result', 'fetcher_result', array(
656
    'type' => 'blob',
657
    'size' => 'big',
658
    'not null' => FALSE,
659
    'description' => 'Cache for fetcher result.',
660
    'serialize' => TRUE,
661
  ));
662
}
663

    
664
/**
665
 * Change config fields from text to big blobs.
666
 */
667
function feeds_update_7207() {
668
  db_change_field('feeds_importer', 'config', 'config', array(
669
    'type' => 'blob',
670
    'size' => 'big',
671
    'not null' => FALSE,
672
    'description' => 'Configuration of the feeds object.',
673
    'serialize' => TRUE,
674
  ));
675

    
676
  db_change_field('feeds_source', 'config', 'config', array(
677
    'type' => 'blob',
678
    'size' => 'big',
679
    'not null' => FALSE,
680
    'description' => 'Configuration of the feeds object.',
681
    'serialize' => TRUE,
682
  ));
683
}
684

    
685
/**
686
 * Update to use generic bundle handling.
687
 */
688
function feeds_update_7208(&$sandbox) {
689

    
690
  if (!isset($sandbox['importers'])) {
691
    // Get all importers.
692
    $sandbox['importers'] = db_query("SELECT id FROM {feeds_importer}")->fetchCol();
693
    $sandbox['total'] = count($sandbox['importers']);
694
  }
695

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

    
699
  if ($config) {
700
    $config = unserialize($config);
701

    
702
    switch ($config['processor']['plugin_key']) {
703
      case 'FeedsNodeProcessor':
704
        $config_key = 'content_type';
705
        break;
706

    
707
      case 'FeedsTermProcessor':
708
        $config_key = 'vocabulary';
709
        break;
710

    
711
      default:
712
        $config_key = FALSE;
713
        break;
714
    }
715

    
716
    if ($config_key && isset($config['processor']['config'][$config_key])) {
717
      $config['processor']['config']['bundle'] = $config['processor']['config'][$config_key];
718
      unset($config['processor']['config'][$config_key]);
719

    
720
      // Update databse.
721
      db_update('feeds_importer')
722
        ->fields(array(
723
          'config' => serialize($config),
724
        ))
725
        ->condition('id', $importer)
726
        ->execute();
727
    }
728

    
729
    $sandbox['#finished'] = 1 - count($sandbox['importers']) / $sandbox['total'];
730
  }
731
  else {
732
    $sandbox['#finished'] = 1;
733
  }
734
}
735

    
736
/**
737
 * Reschedules feeds jobs.
738
 */
739
function feeds_update_7209() {
740
  // Reschedule all importers.
741
  variable_set('feeds_reschedule', TRUE);
742

    
743
  // Our expire callback has changed names, remove all existing callbacks.
744
  db_delete('job_schedule')
745
    ->condition('name', 'feeds_importer_expire')
746
    ->execute();
747

    
748
  DrupalQueue::get('feeds_importer_expire')->deleteQueue();
749
}
750

    
751
/**
752
 * Does nothing. Update removed.
753
 */
754
function feeds_update_7211(&$sandbox) {
755
}
756

    
757
/**
758
 * Create {cache_feeds_http} table.
759
 */
760
function feeds_update_7212() {
761
  if (!db_table_exists('cache_feeds_http')) {
762
    $schema = drupal_get_schema_unprocessed('system', 'cache');
763
    $schema['description'] = 'Cache table for Feeds downloads.';
764
    db_create_table('cache_feeds_http', $schema);
765
  }
766
}
767

    
768
/**
769
 * Set cache class for Feeds HTTP cache.
770
 */
771
function feeds_update_7213() {
772
  // Check if Feeds is enabled first.
773
  if (!class_exists('FeedsHTTPCache') && !module_exists('feeds')) {
774
    throw new DrupalUpdateException('Please enable the Feeds module to perform this update.');
775
  }
776

    
777
  // Perform a registry rebuild so the system hopefully discovers the
778
  // FeedsHTTPCache class.
779
  if (!class_exists('FeedsHTTPCache') && function_exists('registry_rebuild')) {
780
    registry_rebuild();
781
  }
782

    
783
  // Abort when the FeedsHTTPCache class is not yet found to avoid fatal errors
784
  // in _cache_get_object().
785
  if (!class_exists('FeedsHTTPCache')) {
786
    throw new DrupalUpdateException('Setting the cache class for the cache_feeds_http bin failed because the FeedsHTTPCache class could not be found. Please rebuild the Drupal class registry and perform database updates again.');
787
  }
788

    
789
  // Activate our custom cache handler for the HTTP cache.
790
  variable_set('cache_class_cache_feeds_http', 'FeedsHTTPCache');
791
}