-
Notifications
You must be signed in to change notification settings - Fork 5
/
feeds_jsonpath_parser.install
109 lines (89 loc) · 4.37 KB
/
feeds_jsonpath_parser.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
<?php
/**
* @file
* Install, update, and uninstall functions for the Feeds JSONPath Parser
* module.
*/
/**
* Implements hook_enable().
*/
function feeds_jsonpath_parser_enable() {
// Clear Feeds' plugin cache so that this plugin shows up.
cache_clear_all('plugins:feeds:plugins', 'cache');
}
/**
* Implements hook_requirements().
*/
function feeds_jsonpath_parser_requirements($phase) {
$requirements = array();
if ($phase !== 'runtime') {
return $requirements;
}
$t = get_t();
$requirements['feeds_jsonpath_parser']['title'] = $t('JSONPath library');
// Check that the library is successfully installed.
if (class_exists('\Flow\JSONPath\JSONPath', TRUE)) {
// Get the active class location.
$ReflectionClass = new ReflectionClass('\Flow\JSONPath\JSONPath');
$active_class_file = $ReflectionClass->getFileName();
// We are using the bundled class.
$value = $t('Version %version included with the feeds_json_parser module.', array('%version' => FEEDS_JSONPATH_PARSER_LIBRARY_VERSION));
$description = $t('The JSONPath library is bundled with the <em>feeds_jsonpath_parser</em> module.');
$severity = REQUIREMENT_OK;
// Set values based on known or unknown library.
$requirements['feeds_jsonpath_parser']['value'] = $value;
$requirements['feeds_jsonpath_parser']['description'] = $description;
$requirements['feeds_jsonpath_parser']['severity'] = $severity;
}
else {
// Mising Library.
$message = 'The <a href="@jsonpath">JSONPath</a> library is missing. This library is normally included automatically since it is bundled with the <em>feeds_jsonpath_parser</em> module.';
$substitutions = array(
'@jsonpath' => 'https://github.com/SoftCreatR/JSONPath',
);
$requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_ERROR;
$requirements['feeds_jsonpath_parser']['description'] = $t($message, $substitutions);
$requirements['feeds_jsonpath_parser']['value'] = $t('The JSONPath library is missing.');
}
// Let's check for libraries in the libraries module location.
if (module_exists('libraries')) {
// Check for an insecure version.
$file_path_insecure = libraries_get_path('jsonpath') . '/jsonpath.php';
if (file_exists($file_path_insecure)) {
$message = 'An insecure copy of the JSONPath library has been detected at %file. Because of issues identified in <a href="@sa">SA-CONTRIB-2019-083</a>, you must remove this library.';
$substitutions = array(
'%file' => $file_path_insecure,
'@sa' => 'https://www.drupal.org/sa-contrib-2019-083',
);
$requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_ERROR;
$requirements['feeds_jsonpath_parser']['description'] = $t($message, $substitutions);
$requirements['feeds_jsonpath_parser']['value'] = $t('Insecure version detected.');
}
// Check for a previous version.
$file_path_outdated = libraries_get_path('jsonpath');
if (file_exists($file_path_outdated . '/src/JSONPath.php')) {
$message = 'An out-of-date copy of the JSONPath library has been detected at %file. If you are only using JSONPath for <em>feeds_jsonpath_parser</em> module, this copy can be removed.';
$substitutions = array('%file' => $file_path_outdated);
$requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_WARNING;
$requirements['feeds_jsonpath_parser']['description'] = $t($message, $substitutions);
$requirements['feeds_jsonpath_parser']['value'] = $t('Out of date copy detected.');
}
// Check for a duplicate copy.
$file_path_duplicate = libraries_get_path('jsonpath');
if (file_exists($file_path_duplicate . '/src/Flow/JSONPath/JSONPath.php')) {
$message = 'A duplicate copy of the JSONPath library was detected at %file. If you are only using JSONPath for <em>feeds_jsonpath_parser</em> module, this copy can be removed.';
$substitutions = array('%file' => $file_path_duplicate);
$requirements['feeds_jsonpath_parser']['severity'] = REQUIREMENT_WARNING;
$requirements['feeds_jsonpath_parser']['description'] = $t($message, $substitutions);
$requirements['feeds_jsonpath_parser']['value'] = $t('Duplicate copy detected.');
}
}
return $requirements;
}
/**
* Delete JSONPath Parser variables.
*/
function feeds_jsonpath_parser_update_1000() {
// Delete variables.
update_variable_del('feeds_jsonpath_library_dir');
}