Pathologic was missing because of a .git folder inside.
[yaffs-website] / web / modules / contrib / devel / webprofiler / webprofiler.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the webprofiler module.
6  */
7
8 use Drupal\Core\Url;
9
10 /**
11  * Implements hook_schema().
12  */
13 function webprofiler_schema() {
14   $schema['webprofiler'] = [
15     'description' => 'Webprofiler profiles storage.',
16     'fields' => [
17       'token' => [
18         'description' => 'Profile token.',
19         'type' => 'varchar',
20         'length' => 6,
21         'not null' => TRUE,
22       ],
23       'data' => [
24         'description' => 'Profile data.',
25         'type' => 'text',
26         'size' => 'big',
27         'not null' => TRUE,
28       ],
29       'ip' => [
30         'description' => 'Request IP.',
31         'type' => 'varchar',
32         'length' => 64,
33         'not null' => TRUE,
34       ],
35       'method' => [
36         'description' => 'Request method.',
37         'type' => 'varchar',
38         'length' => 6,
39         'not null' => TRUE,
40       ],
41       'url' => [
42         'description' => 'Requested URL.',
43         'type' => 'varchar',
44         'length' => 2048,
45         'not null' => TRUE,
46       ],
47       'time' => [
48         'description' => 'Request time.',
49         'type' => 'int',
50         'unsigned' => TRUE,
51         'not null' => TRUE,
52       ],
53       'parent' => [
54         'description' => 'Profile parent.',
55         'type' => 'varchar',
56         'length' => 6,
57         'not null' => FALSE,
58       ],
59       'created_at' => [
60         'description' => 'Profile created time.',
61         'type' => 'int',
62         'unsigned' => TRUE,
63         'not null' => TRUE,
64       ],
65       'status_code' => [
66         'description' => 'Profile status code.',
67         'type' => 'int',
68         'size' => 'small',
69         'unsigned' => TRUE,
70         'not null' => TRUE,
71       ],
72     ],
73     'indexes' => [
74       'created_at' => ['created_at'],
75       'ip' => ['ip'],
76       'method' => ['method'],
77       'parent' => ['parent'],
78     ],
79     'primary key' => ['token'],
80   ];
81
82   return $schema;
83 }
84
85 /**
86  * Implements hook_requirements().
87  */
88 function webprofiler_requirements($phase) {
89   $requirements = [];
90
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'),
96     ];
97
98     if (!$has_d3) {
99       $requirements['d3js']['severity'] = REQUIREMENT_WARNING;
100       $requirements['d3js']['description'] = [
101         '#prefix' => ' ',
102         '#markup' => t('Webprofiler module requires D3.js library to properly render data. Composer based install recommended, see README.md file for instructions.'),
103       ];
104     }
105
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'),
110     ];
111
112     if (!$has_highlight) {
113       $requirements['highlightjs']['severity'] = REQUIREMENT_WARNING;
114       $requirements['highlightjs']['description'] = [
115         '#prefix' => ' ',
116         '#markup' => t('Webprofiler module requires highlight.js library to syntax highlight collected queries. Composer based install recommended, see README.md file for instructions.'),
117       ];
118     }
119   }
120
121   return $requirements;
122 }
123
124 /**
125  * Verify that the library files exist.
126  *
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.
131  *
132  * @return bool
133  *   TRUE if all files of this library exists, FALSE otherwise
134  *
135  * @see https://drupal.org/node/2231385
136  */
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);
141
142   $exist = TRUE;
143   if ($library['js']) {
144     foreach ($library['js'] as $js) {
145       if ($js['type'] == 'file') {
146         if (!file_exists(DRUPAL_ROOT . '/' . $js['data'])) {
147           $exist = FALSE;
148         }
149       }
150     }
151   }
152
153   if ($library['css']) {
154     foreach ($library['css'] as $css) {
155       if ($css['type'] == 'file') {
156         if (!file_exists(DRUPAL_ROOT . '/' . $css['data'])) {
157           $exist = FALSE;
158         }
159       }
160     }
161   }
162
163   if ($library['dependencies']) {
164     foreach ($library['dependencies'] as $dependency) {
165       $parts = explode('/', $dependency);
166       $exist = _webprofiler_verify_library($parts[0], $parts[1]);
167     }
168   }
169
170   return $exist;
171 }
172
173 /**
174  * Add a status_code column to the webprofiler table.
175  */
176 function webprofiler_update_8001() {
177   $database = \Drupal::database();
178   $schema = $database->schema();
179
180   $spec = array(
181     'description' => 'Profile status code.',
182     'type' => 'int',
183     'size' => 'small',
184     'unsigned' => TRUE,
185     'not null' => TRUE,
186   );
187   $schema->addField('webprofiler', 'status_code', $spec);
188 }