Commit | Line | Data |
---|---|---|
1248c859 TO |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
39de6fd5 | 4 | | CiviCRM version 4.6 | |
1248c859 TO |
5 | +--------------------------------------------------------------------+ |
6 | | Copyright CiviCRM LLC (c) 2004-2014 | | |
7 | +--------------------------------------------------------------------+ | |
8 | | This file is a part of CiviCRM. | | |
9 | | | | |
10 | | CiviCRM is free software; you can copy, modify, and distribute it | | |
11 | | under the terms of the GNU Affero General Public License | | |
12 | | Version 3, 19 November 2007 and the CiviCRM Licensing Exception. | | |
13 | | | | |
14 | | CiviCRM is distributed in the hope that it will be useful, but | | |
15 | | WITHOUT ANY WARRANTY; without even the implied warranty of | | |
16 | | MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. | | |
17 | | See the GNU Affero General Public License for more details. | | |
18 | | | | |
19 | | You should have received a copy of the GNU Affero General Public | | |
20 | | License and the CiviCRM Licensing Exception along | | |
21 | | with this program; if not, contact CiviCRM LLC | | |
22 | | at info[AT]civicrm[DOT]org. If you have questions about the | | |
23 | | GNU Affero General Public License or the licensing of CiviCRM, | | |
24 | | see the CiviCRM license FAQ at http://civicrm.org/licensing | | |
25 | +--------------------------------------------------------------------+ | |
d25dd0ee | 26 | */ |
1248c859 TO |
27 | |
28 | /** | |
29 | * | |
30 | * @package CRM | |
31 | * @copyright CiviCRM LLC (c) 2004-2014 | |
32 | * $Id: $ | |
33 | * | |
34 | */ | |
35 | class CRM_Utils_Check { | |
7da04cde | 36 | const |
1248c859 TO |
37 | // How often to run checks and notify admins about issues. |
38 | CHECK_TIMER = 86400; | |
39 | ||
40 | /** | |
41 | * We only need one instance of this object, so we use the | |
42 | * singleton pattern and cache the instance in this variable | |
43 | * | |
44 | * @var object | |
1248c859 TO |
45 | */ |
46 | static private $_singleton = NULL; | |
47 | ||
48 | /** | |
49 | * Provide static instance of CRM_Utils_Check. | |
50 | * | |
51 | * @return CRM_Utils_Check | |
52 | */ | |
00be9182 | 53 | public static function &singleton() { |
1248c859 TO |
54 | if (!isset(self::$_singleton)) { |
55 | self::$_singleton = new CRM_Utils_Check(); | |
56 | } | |
57 | return self::$_singleton; | |
58 | } | |
59 | ||
60 | /** | |
fe482240 | 61 | * Execute "checkAll". |
7c42ee33 TO |
62 | * |
63 | * @param array|NULL $messages list of CRM_Utils_Check_Message; or NULL if the default list should be fetched | |
1248c859 | 64 | */ |
7c42ee33 | 65 | public function showPeriodicAlerts($messages = NULL) { |
1248c859 TO |
66 | if (CRM_Core_Permission::check('administer CiviCRM') |
67 | && CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'securityAlert', NULL, TRUE) | |
68 | ) { | |
69 | $session = CRM_Core_Session::singleton(); | |
70 | if ($session->timer('check_' . __CLASS__, self::CHECK_TIMER)) { | |
71 | ||
72 | // Best attempt at re-securing folders | |
73 | $config = CRM_Core_Config::singleton(); | |
74 | $config->cleanup(0, FALSE); | |
75 | ||
7c42ee33 TO |
76 | if ($messages === NULL) { |
77 | $messages = $this->checkAll(); | |
78 | } | |
79 | foreach ($messages as $message) { | |
1248c859 TO |
80 | CRM_Core_Session::setStatus($message->getMessage(), $message->getTitle()); |
81 | } | |
82 | } | |
83 | } | |
84 | } | |
85 | ||
c0bc3902 | 86 | /** |
fe482240 | 87 | * Throw an exception if any of the checks fail. |
7c42ee33 TO |
88 | * |
89 | * @param array|NULL $messages list of CRM_Utils_Check_Message; or NULL if the default list should be fetched | |
f4aaa82a EM |
90 | * |
91 | * @throws Exception | |
c0bc3902 | 92 | */ |
7c42ee33 TO |
93 | public function assertValid($messages = NULL) { |
94 | if ($messages === NULL) { | |
95 | $messages = $this->checkAll(); | |
96 | } | |
c0bc3902 TO |
97 | if (!empty($messages)) { |
98 | $messagesAsArray = array(); | |
99 | foreach ($messages as $message) { | |
100 | $messagesAsArray[] = $message->toArray(); | |
101 | } | |
102 | throw new Exception('There are configuration problems with this installation: ' . print_r($messagesAsArray, TRUE)); | |
103 | } | |
104 | } | |
105 | ||
1248c859 TO |
106 | /** |
107 | * Run some sanity checks. | |
108 | * | |
109 | * This could become a hook so that CiviCRM can run both built-in | |
110 | * configuration & sanity checks, and modules/extensions can add | |
111 | * their own checks. | |
112 | * | |
113 | * We might even expose the results of these checks on the Wordpress | |
114 | * plugin status page or the Drupal admin/reports/status path. | |
115 | * | |
a6c01b45 | 116 | * @return array |
16b10e64 | 117 | * Array of messages |
d3e86119 | 118 | * @link https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements |
1248c859 TO |
119 | */ |
120 | public function checkAll() { | |
2aa3d7ab TO |
121 | $checks = array(); |
122 | $checks[] = new CRM_Utils_Check_Security(); | |
123 | $checks[] = new CRM_Utils_Check_Env(); | |
124 | ||
125 | $compInfo = CRM_Core_Component::getEnabledComponents(); | |
126 | foreach ($compInfo as $compObj) { | |
127 | switch ($compObj->info['name']) { | |
128 | case 'CiviCase': | |
129 | $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name')); | |
130 | break; | |
e7292422 | 131 | |
2aa3d7ab TO |
132 | default: |
133 | } | |
134 | } | |
135 | ||
136 | $messages = array(); | |
137 | foreach ($checks as $check) { | |
138 | $messages = array_merge($messages, $check->checkAll()); | |
139 | } | |
1248c859 TO |
140 | return $messages; |
141 | } | |
142 | ||
f4aaa82a | 143 | } |