5 * Install, update and uninstall functions for the webprofiler module.
11 * Implements hook_schema().
13 function webprofiler_schema() {
14 $schema['webprofiler'] = [
15 'description' => 'Webprofiler profiles storage.',
18 'description' => 'Profile token.',
24 'description' => 'Profile data.',
30 'description' => 'Request IP.',
36 'description' => 'Request method.',
42 'description' => 'Requested URL.',
48 'description' => 'Request time.',
54 'description' => 'Profile parent.',
60 'description' => 'Profile created time.',
66 'description' => 'Profile status code.',
74 'created_at' => ['created_at'],
76 'method' => ['method'],
77 'parent' => ['parent'],
79 'primary key' => ['token'],
86 * Implements hook_requirements().
88 function webprofiler_requirements($phase) {
91 if ('runtime' == $phase) {
92 $has_d3 = _webprofiler_verify_library('webprofiler', 'd3');
93 $requirements['d3js'] = [
94 'title' => t('D3.js library'),
95 'value' => $has_d3 ? t('Enabled') : t('Not found'),
99 $requirements['d3js']['severity'] = REQUIREMENT_WARNING;
100 $requirements['d3js']['description'] = [
102 '#markup' => t('Webprofiler module requires D3.js library to properly render data. Composer based install recommended, see README.md file for instructions.'),
106 $has_highlight = _webprofiler_verify_library('webprofiler', 'highlightjs');
107 $requirements['highlightjs'] = [
108 'title' => t('highlight.js library'),
109 'value' => $has_highlight ? t('Enabled') : t('Not found'),
112 if (!$has_highlight) {
113 $requirements['highlightjs']['severity'] = REQUIREMENT_WARNING;
114 $requirements['highlightjs']['description'] = [
116 '#markup' => t('Webprofiler module requires highlight.js library to syntax highlight collected queries. Composer based install recommended, see README.md file for instructions.'),
121 return $requirements;
125 * Verify that the library files exist.
127 * @param string $extension
128 * The name of the extension that registered a library.
129 * @param string $name
130 * The name of a registered library to retrieve.
133 * TRUE if all files of this library exists, FALSE otherwise
135 * @see https://drupal.org/node/2231385
137 function _webprofiler_verify_library($extension, $name) {
138 /** @var Drupal\Core\Asset\LibraryDiscovery $library_discovery */
139 $library_discovery = \Drupal::service('library.discovery');
140 $library = $library_discovery->getLibraryByName($extension, $name);
143 if ($library['js']) {
144 foreach ($library['js'] as $js) {
145 if ($js['type'] == 'file') {
146 if (!file_exists(DRUPAL_ROOT . '/' . $js['data'])) {
153 if ($library['css']) {
154 foreach ($library['css'] as $css) {
155 if ($css['type'] == 'file') {
156 if (!file_exists(DRUPAL_ROOT . '/' . $css['data'])) {
163 if ($library['dependencies']) {
164 foreach ($library['dependencies'] as $dependency) {
165 $parts = explode('/', $dependency);
166 $exist = _webprofiler_verify_library($parts[0], $parts[1]);
174 * Add a status_code column to the webprofiler table.
176 function webprofiler_update_8001() {
177 $database = \Drupal::database();
178 $schema = $database->schema();
181 'description' => 'Profile status code.',
187 $schema->addField('webprofiler', 'status_code', $spec);