Added the Porter Stemmer module to improve searches. This doesn't deal with some...
[yaffs-website] / web / modules / contrib / security_review / security_review.install
1 <?php
2
3 /**
4  * @file
5  * Install, update and uninstall functions for the security_review module.
6  */
7
8 use Drupal\Core\Url;
9 use Drupal\security_review\CheckResult;
10
11 /**
12  * Implements hook_install().
13  */
14 function security_review_install() {
15   // Remind the user to set the permissions.
16   drupal_set_message(
17     t(
18       'Security Review module enabled. You should first set the module access permissions at <a href=":url">admin/people/permissions</a>. Be sure to grant permissions to trusted users only as this module can show sensitive site information.',
19       [':url' => Url::fromRoute('user.admin_permissions')->toString()]
20     )
21   );
22 }
23
24 /**
25  * Implements hook_requirements().
26  */
27 function security_review_requirements($phase) {
28   $requirements = [];
29
30   // Provides a Status Report entry.
31   if ($phase == 'runtime') {
32     /** @var \Drupal\security_review\Checklist $checklist */
33     $checklist = Drupal::service('security_review.checklist');
34
35     $failed_checks = FALSE;
36     $no_results = TRUE;
37
38     // Looks for failed checks.
39     foreach ($checklist->getEnabledChecks() as $check) {
40       $result = $check->lastResult();
41       if ($result instanceof CheckResult) {
42         $no_results = FALSE;
43         if ($result->result() === CheckResult::FAIL) {
44           $failed_checks = TRUE;
45           break;
46         }
47       }
48     }
49
50     $module_url = Url::fromRoute('security_review')->toString();
51     if ($no_results) {
52       $severity = REQUIREMENT_WARNING;
53       $value = t(
54         'The Security Review checklist has not been run. <a href=":url">Run the checklist</a>',
55         [':url' => $module_url]
56       );
57     }
58     elseif ($failed_checks) {
59       $severity = REQUIREMENT_WARNING;
60       $value = t(
61         'There are failed Security Review checks. <a href=":url">Review the checklist</a>',
62         [':url' => $module_url]
63       );
64     }
65     else {
66       $severity = REQUIREMENT_OK;
67       $value = t(
68         'Passing all non-ignored Security Review checks. <a href=":url">Review the checklist</a>',
69         [':url' => $module_url]
70       );
71     }
72     $requirements['security_review'] = [
73       'title' => t('Security Review'),
74       'severity' => $severity,
75       'value' => $value,
76     ];
77   }
78
79   return $requirements;
80 }