-
Notifications
You must be signed in to change notification settings - Fork 0
/
govinfo.module
102 lines (90 loc) · 2.89 KB
/
govinfo.module
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
<?php
/**
* @file
* Contains govinfo.module.
*/
use Drupal\Core\Routing\RouteMatchInterface;
/**
* Implements hook_help().
*/
function govinfo_help($route_name, RouteMatchInterface $route_match) {
switch ($route_name) {
case 'help.page.govinfo':
$output = '<h3>' . t('govinfo help') . '</h3>';
return $output;
default:
}
}
function govinfo_rate_limit_cop($remaining, $limit) {
// if ($remaining )
// \Drupal::logger()->notice(dt('@rll of @rl rate limit requests remaining.', [
// '@rll' => $this->api->getRateLimitRemaining(),
// '@rl' => $this->api->getRateLimit()
// ]));
}
/**
* Add links (from download fields) to a queue to be indexed and/or stored.
*
* @param string $doctype
* The type of document this is. Comes from govinfo
* @param array $links
* The associative array of URL's to be stored in the queue. The type is
* the key and the url is in the value.
*/
function govinfo_add_links_to_queue($doctype, $date_issued, $links, $summary_id = NULL, $granule_id = NULL): void {
$db = \Drupal::database();
foreach ($links as $key => $value) {
$db->insert('govinfo_document_queue')
->fields([
'category' => $doctype,
'date_issued' => $date_issued,
'document_type' => $key,
'summary_id' => $summary_id,
'granule_id' => $granule_id,
'document_link' => $value,
])
->execute();
}
}
/**
* Handles the queue of documents. The priority of documents is as follows.
*
* 1. If there is a zip file, get that and nothing else, decompress the file
* and store the files in a manner where they can be found for indexing.
* 2. If there is no zip file retrieve documents in the following order:
* a) PDF
* b) premise
* b) mods
* 3. Store the files in the file system as follows
* public://govinfo/year_issued/month_issued/day_issued/package_id<-granule_id>.extension
*/
function govinfo_process_document_queue() {
$result = $db->select('govinfo_document_queue', 'dq')
->fields('dq')
->orderBy('did', 'ASC')
->execute();
foreach ($result as $ddata) {
}
}
/**
* Implements hook_requirements().
*/
function govinfo_requirements($phase) {
$requirements = [];
if ($phase == 'runtime') {
$config = \Drupal::service('config.factory')->get('govinfo.settings');
$api_key = ($config->get('api_key') != NULL) ? $config->get('api_key') : NULL;
$requirements['govinfo_api'] = [
'title' => t('govinfo api'),
];
if (!empty($api_key)) {
$requirements['govinfo_api']['severity'] = REQUIREMENT_OK;
$requirements['govinfo_api']['description'] = t('You have a govinfo API key assigned');
}
else {
$requirements['govinfo_api']['severity'] = REQUIREMENT_ERROR;
$requirements['govinfo_api']['description'] = t('You must assign a govinfo API key in order to use the govinfo entity type.');
}
}
return $requirements;
}