-
Notifications
You must be signed in to change notification settings - Fork 12
/
feeds.install
607 lines (563 loc) · 18.2 KB
/
feeds.install
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
<?php
/**
* @file
* Schema definitions install/update/uninstall hooks.
*/
/**
* Implements hook_requirements().
*/
function feeds_requirements($phase) {
$t = get_t();
$requirements = array();
module_load_include('module', 'feeds');
// Load class because hook_autoload_info() isn't loaded at this point.
module_load_include('module', 'feeds', 'includes/FeedsConfigurable');
// 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 = backdrop_get_path('module', 'feeds') . '/libraries';
if (module_exists('libraries')) {
$folder = 'libraries/simplepie';
}
$args = array(
'!url' => 'http://simplepie.org/downloads/',
'%folder' => $folder,
'%file' => 'library/SimplePie.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;
}
/**
* Implements hook_install().
*/
function feeds_install() {
// If view already exists make sure it's enabled.
$config = config('views.view.feeds_log');
$config->set('disabled', FALSE);
$config->save();
}
/**
* Implements hook_uninstall().
*/
function feeds_uninstall() {
// Remove Feeds related jobs from job scheduler.
$names = db_or()
->condition('name', 'feeds_source_import')
->condition('name', 'feeds_source_clear')
->condition('name', 'feeds_source_expire')
->condition('name', 'feeds_push_unsubscribe');
db_delete('job_schedule')
->condition($names)
->execute();
// Remove view
$config = config('views.view.feeds_log');
$config->delete();
// Clear admin bar cache to remove view from menu
cache('admin_bar')->flush();
}
/**
* Implements hook_schema().
*/
function feeds_schema() {
$schema = array();
$schema['feeds_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
'feed_nid' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Node nid if this particular source is attached to a feed node.',
),
'config' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the source.',
'serialize' => TRUE,
),
'source' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Main source resource identifier. E. g. a path or a URL.',
),
'state' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
),
'fetcher_result' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
'serialize' => TRUE,
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
),
'primary key' => array('id', 'feed_nid'),
'indexes' => array(
'id' => array('id'),
'feed_nid' => array('feed_nid'),
'id_source' => array('id', array('source', 128)),
),
);
$schema['feeds_item'] = array(
'description' => 'Tracks items such as nodes, terms, users.',
'fields' => array(
'entity_type' => array(
'type' => 'varchar',
'length' => 32,
'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',
// 32 is the length of an MD5 hash.
'length' => 32,
'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'),
'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)),
'imported' => array('imported'),
),
);
$schema['feeds_push_subscriptions'] = array(
'description' => 'PubSubHubbub subscriptions.',
'fields' => array(
'domain' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Domain of the subscriber. Corresponds to an importer id.',
),
'subscriber_id' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'ID of the subscriber. Corresponds to a feed nid.',
),
'timestamp' => array(
'type' => 'int',
'unsigned' => FALSE,
'default' => 0,
'not null' => TRUE,
'description' => 'Created timestamp.',
),
'hub' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'The URL of the hub endpoint of this subscription.',
),
'topic' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'The topic URL (feed URL) of this subscription.',
),
'secret' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Shared secret for message authentication.',
),
'status' => array(
'type' => 'varchar',
'length' => 64,
'not null' => TRUE,
'default' => '',
'description' => 'Status of subscription.',
),
'post_fields' => array(
'type' => 'text',
'not null' => FALSE,
'description' => 'Fields posted.',
'serialize' => TRUE,
),
),
'primary key' => array('domain', 'subscriber_id'),
'indexes' => array(
'timestamp' => array('timestamp'),
),
);
$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'),
),
);
$schema['feeds_preview_source'] = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
'config' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the source.',
'serialize' => TRUE,
),
'source' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Main source resource identifier. E. g. a path or a URL.',
),
'state' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
),
'fetcher_result' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
'serialize' => TRUE,
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
),
'primary key' => array('id'),
);
$schema['cache_feeds_http'] = backdrop_get_schema_unprocessed('system', 'cache');
$schema['cache_feeds_http']['description'] = 'Cache table for Feeds downloads.';
return $schema;
}
/**
* Implements hook_disable().
*/
function feeds_disable() {
// Disable the view.
$config = config('views.view.feeds_log');
$config->set('disabled', TRUE);
$config->save();
}
/**
* Update variables from Drupal 7 to Backdrop.
*/
function feeds_update_1000() {
$config = config('feeds.settings');
$config->set('feeds_debug', update_variable_get('feeds_debug', FALSE));
$config->set('feeds_importer_class', update_variable_get('feeds_importer_class', 'FeedsImporter'));
$config->set('feeds_library_dir', update_variable_get('feeds_library_dir', ''));
$config->set('default_feeds_importer', update_variable_get('default_feeds_importer', ''));
$config->set('feeds_source_class', update_variable_get('feeds_source_class', 'FeedsSource'));
$config->set('http_request_timeout', update_variable_get('http_request_timeout', 30));
$config->set('proxy_auth_method', update_variable_get('proxy_auth_method', ''));
$config->set('feeds_never_use_curl', update_variable_get('feeds_never_use_curl', FALSE));
$config->set('feeds_process_limit', update_variable_get('feeds_process_limit', 5));
$config->set('feeds_use_mbstring', update_variable_get('feeds_use_mbstring', TRUE));
$config->save();
state_set('feeds_reschedule', update_variable_get('feeds_reschedule', FALSE));
// Delete variables.
update_variable_del('feeds_reschedule');
update_variable_del('feeds_debug');
update_variable_del('feeds_importer_class');
update_variable_del('feeds_library_dir');
update_variable_del('default_feeds_importer');
update_variable_del('feeds_source_class');
update_variable_del('http_request_timeout');
update_variable_del('proxy_auth_method');
update_variable_del('feeds_never_use_curl');
update_variable_del('feeds_process_limit');
update_variable_del('feeds_use_mbstring');
}
/**
* Convert config that should be state. And remove config that are in core
* already.
*/
function feeds_update_1001() {
$config = config('feeds.settings');
state_set('feeds_reschedule', $config->get('feeds_reschedule'));
$config->clear('feeds_reschedule');
$config->clear('menu_rebuild_needed');
$config->clear('default_nodes_main');
$config->save();
}
/**
* Convert feeds_log View.
*/
function feeds_update_1002() {
// See if the feeds_log view has been created or modified on this site.
$config = config('views.view.feeds_log');
// Only update if view isn't overridden
if ($config->get('storage') != VIEWS_STORAGE_OVERRIDE) {
$path = backdrop_get_path('module', 'feeds') . '/config/';
$contents = file_get_contents($path . 'views.view.feeds_log.json');
$data = json_decode($contents, true);
$config->setData($data);
$config->save();
}
}
/**
* Move feeds_importer configuration from table to config files.
*/
function feeds_update_1003() {
if (db_table_exists('feeds_importer')) {
$feeds_importers = db_select('feeds_importer', 'fi')
->fields('fi')
->execute()
->fetchAllAssoc('id');
foreach($feeds_importers as $importer) {
$config = config('feeds.feeds_importer.' . $importer->id);
if ($config->isNew()) {
$config->set('id', $importer->id);
$config->set('disabled', FALSE);
$config->set('config', unserialize($importer->config));
$config->save();
}
}
db_drop_table('feeds_importer');
}
}
/**
* Convert cache variables to config.
*/
function feeds_update_1004() {
$config = config('feeds.settings');
$config->set('feeds_sync_cache_feeds_http_interval', update_variable_get('feeds_sync_cache_feeds_http_interval', 21600));
$config->set('feeds_http_file_cache_dir', update_variable_get('feeds_http_file_cache_dir', NULL));
$config->set('feeds_in_progress_dir', update_variable_get('feeds_in_progress_dir', NULL));
$config->save();
update_variable_del('feeds_sync_cache_feeds_http_interval');
update_variable_del('feeds_http_file_cache_dir');
// Don't need the cache class in config - we just hardcode it so
// settings_get() can use it.
// See feeds.module.
update_variable_del('cache_class_cache_feeds_http');
update_variable_del('feeds_in_progress_dir');
}
/**
* Add defaults for alternative feeds HTTP proxy.
*/
function feeds_update_1005() {
// These variables were mistakenly cleared earlier.
// Assuming the original variables still exist will convert them here.
$config = config('feeds.settings');
$config->set('proxy_auth_method', update_variable_get('proxy_auth_method', CURLAUTH_BASIC));
$config->set('proxy_server', update_variable_get('proxy_server', ''));
$config->set('proxy_port', update_variable_get('proxy_port', 8080));
$config->set('proxy_username', update_variable_get('proxy_username', ''));
$config->set('proxy_password', update_variable_get('proxy_password', ''));
$config->save();
update_variable_del('proxy_auth_method');
update_variable_del('proxy_server');
update_variable_del('proxy_port');
update_variable_del('proxy_username');
update_variable_del('proxy_password');
}
/**
* Create the feeds_preview_source table.
*/
function feeds_update_1006() {
if (db_table_exists('feedspreview_source')) {
db_rename_table('feedspreview_source', 'feeds_preview_source');
}
$schema = array(
'description' => 'Source definitions for feeds.',
'fields' => array(
'id' => array(
'type' => 'varchar',
'length' => 128,
'not null' => TRUE,
'default' => '',
'description' => 'Id of the feed configuration.',
),
'config' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Configuration of the source.',
'serialize' => TRUE,
),
'source' => array(
'type' => 'text',
'not null' => TRUE,
'description' => 'Main source resource identifier. E. g. a path or a URL.',
),
'state' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'State of import or clearing batches.',
'serialize' => TRUE,
),
'fetcher_result' => array(
'type' => 'blob',
'size' => 'big',
'not null' => FALSE,
'description' => 'Cache for fetcher result.',
'serialize' => TRUE,
),
'imported' => array(
'type' => 'int',
'not null' => TRUE,
'default' => 0,
'unsigned' => TRUE,
'description' => 'Timestamp when this source was imported last.',
),
),
'primary key' => array('id'),
);
if (!db_table_exists('feeds_preview_source')) {
db_create_table('feeds_preview_source', $schema);
}
}