Merge pull request #8899 from JKingsnorth/CRM-19179
[civicrm-core.git] / CRM / Utils / Check / Component / Env.php
CommitLineData
1e927c45
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
1e927c45 5 +--------------------------------------------------------------------+
fa938177 6 | Copyright CiviCRM LLC (c) 2004-2016 |
1e927c45
TO
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 */
1e927c45
TO
27
28/**
29 *
30 * @package CRM
fa938177 31 * @copyright CiviCRM LLC (c) 2004-2016
1e927c45 32 */
3a0d0bbd 33class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component {
1e927c45 34
31e80d5a
CW
35 /**
36 * @return array
37 */
38 public function checkPhpVersion() {
39 $messages = array();
40
d0c1e96f 41 if (version_compare(phpversion(), CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER) >= 0) {
31e80d5a 42 $messages[] = new CRM_Utils_Check_Message(
165aab59 43 __FUNCTION__,
d0c1e96f
TO
44 ts('This system uses PHP version %1 which meets or exceeds the minimum recommendation of %2.',
45 array(
46 1 => phpversion(),
47 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
48 )),
49 ts('PHP Up-to-Date'),
50 \Psr\Log\LogLevel::INFO,
51 'fa-server'
52 );
53 }
54 elseif (version_compare(phpversion(), CRM_Upgrade_Incremental_General::MIN_DEFECT_PHP_VER) >= 0) {
55 $messages[] = new CRM_Utils_Check_Message(
56 __FUNCTION__,
57 ts('This system uses PHP version %1. While this meets the minimum requirements for CiviCRM to function, upgrading to PHP version %2 or newer is recommended for maximum compatibility.',
31e80d5a
CW
58 array(
59 1 => phpversion(),
e0aee35d 60 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
d0c1e96f 61 3 => CRM_Upgrade_Incremental_General::MIN_DEFECT_PHP_VER,
31e80d5a
CW
62 )),
63 ts('PHP Out-of-Date'),
165aab59
CW
64 \Psr\Log\LogLevel::NOTICE,
65 'fa-server'
31e80d5a
CW
66 );
67 }
68 else {
69 $messages[] = new CRM_Utils_Check_Message(
165aab59 70 __FUNCTION__,
d0c1e96f 71 ts('This system uses PHP version %1. CiviCRM can be installed on this version, but some specific features are known to fail or degrade. Version %3 is the bare minimum to avoid known issues, and version %2 is recommended.',
31e80d5a
CW
72 array(
73 1 => phpversion(),
e0aee35d 74 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
d0c1e96f 75 3 => CRM_Upgrade_Incremental_General::MIN_DEFECT_PHP_VER,
31e80d5a 76 )),
d0c1e96f
TO
77 ts('PHP Out-of-Date'),
78 \Psr\Log\LogLevel::WARNING,
165aab59 79 'fa-server'
31e80d5a
CW
80 );
81 }
82
83 return $messages;
84 }
85
991298ee
TO
86 /**
87 * @return array
88 */
89 public function checkPhpMysqli() {
90 $messages = array();
91
92 if (!extension_loaded('mysqli')) {
93 $messages[] = new CRM_Utils_Check_Message(
94 __FUNCTION__,
95 ts('Future versions of CiviCRM may require the PHP extension "%2". To ensure that your system will be compatible, please install it in advance. For more explanation, see <a href="%1">the announcement</a>.',
96 array(
97 1 => 'https://civicrm.org/blog/totten/psa-please-verify-php-extension-mysqli',
98 2 => 'mysqli',
99 )),
100 ts('Forward Compatibility: Enable "mysqli"'),
101 \Psr\Log\LogLevel::WARNING,
102 'fa-server'
103 );
104 }
105
106 return $messages;
107 }
108
7342d7c4
TO
109 /**
110 * Check that the MySQL time settings match the PHP time settings.
111 *
112 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
113 */
1e927c45 114 public function checkMysqlTime() {
f3cfdce3
J
115 //CRM-19115 - Always set MySQL time before checking it.
116 CRM_Core_Config::singleton()->userSystem->setMySQLTimeZone();
1e927c45
TO
117 $messages = array();
118
119 $phpNow = date('Y-m-d H:i');
120 $sqlNow = CRM_Core_DAO::singleValueQuery("SELECT date_format(now(), '%Y-%m-%d %H:%i')");
8010540a 121 if (!CRM_Utils_Time::isEqual($phpNow, $sqlNow, 2.5 * 60)) {
1e927c45 122 $messages[] = new CRM_Utils_Check_Message(
165aab59 123 __FUNCTION__,
1e927c45 124 ts('Timestamps reported by MySQL (eg "%2") and PHP (eg "%3" ) are mismatched.<br /><a href="%1">Read more about this warning</a>', array(
7342d7c4 125 1 => CRM_Utils_System::getWikiBaseURL() . 'checkMysqlTime',
1e927c45
TO
126 2 => $sqlNow,
127 3 => $phpNow,
128 )),
1b366958 129 ts('Timestamp Mismatch'),
165aab59
CW
130 \Psr\Log\LogLevel::ERROR,
131 'fa-server'
1e927c45
TO
132 );
133 }
134
135 return $messages;
136 }
7342d7c4 137
5bc392e6
EM
138 /**
139 * @return array
140 */
7342d7c4
TO
141 public function checkDebug() {
142 $messages = array();
143
144 $config = CRM_Core_Config::singleton();
145 if ($config->debug) {
146 $messages[] = new CRM_Utils_Check_Message(
165aab59 147 __FUNCTION__,
7342d7c4
TO
148 ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.',
149 array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))),
1b366958 150 ts('Debug Mode Enabled'),
165aab59
CW
151 \Psr\Log\LogLevel::WARNING,
152 'fa-bug'
7342d7c4
TO
153 );
154 }
155
156 return $messages;
157 }
158
5bc392e6
EM
159 /**
160 * @return array
161 */
7342d7c4
TO
162 public function checkOutboundMail() {
163 $messages = array();
164
aaffa79f 165 $mailingInfo = Civi::settings()->get('mailing_backend');
7342d7c4
TO
166 if (($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB
167 || (defined('CIVICRM_MAIL_LOG') && CIVICRM_MAIL_LOG)
168 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED
169 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK)
170 ) {
171 $messages[] = new CRM_Utils_Check_Message(
165aab59 172 __FUNCTION__,
7342d7c4
TO
173 ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.',
174 array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))),
1b366958 175 ts('Outbound Email Disabled'),
165aab59
CW
176 \Psr\Log\LogLevel::WARNING,
177 'fa-envelope'
7342d7c4
TO
178 );
179 }
180
181 return $messages;
182 }
96025800 183
1b366958
AH
184 /**
185 * Check that domain email and org name are set
186 * @return array
187 */
1b366958
AH
188 public function checkDomainNameEmail() {
189 $messages = array();
190
191 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
192 $domain = CRM_Core_BAO_Domain::getDomain();
193 $domainName = $domain->name;
194 $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1");
195
196 if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
197 if (!$domainName || $domainName == 'Default Domain Name') {
198 $msg = ts("Please enter your organization's <a href=\"%1\">name, primary address, and default FROM Email Address</a> (for system-generated emails).",
199 array(1 => $fixEmailUrl));
200 }
201 else {
202 $msg = ts('Please enter a <a href="%1">default FROM Email Address</a> (for system-generated emails).',
203 array(1 => $fixEmailUrl));
204 }
205 }
206 elseif (!$domainName || $domainName == 'Default Domain Name') {
207 $msg = ts("Please enter your organization's <a href=\"%1\">name and primary address</a>.",
208 array(1 => $fixEmailUrl));
209 }
aacaa119
AH
210
211 if (!empty($msg)) {
212 $messages[] = new CRM_Utils_Check_Message(
165aab59 213 __FUNCTION__,
aacaa119
AH
214 $msg,
215 ts('Complete Setup'),
165aab59
CW
216 \Psr\Log\LogLevel::WARNING,
217 'fa-check-square-o'
aacaa119
AH
218 );
219 }
1b366958
AH
220
221 return $messages;
222 }
223
224 /**
225 * Checks if a default bounce handling mailbox is set up
226 * @return array
227 */
1b366958
AH
228 public function checkDefaultMailbox() {
229 $messages = array();
230 $config = CRM_Core_Config::singleton();
231
232 if (in_array('CiviMail', $config->enableComponents) &&
233 CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG"
234 ) {
235 $message = new CRM_Utils_Check_Message(
165aab59 236 __FUNCTION__,
aa96ce62 237 ts('Please configure a <a href="%1">default mailbox</a> for CiviMail.',
1b366958
AH
238 array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))),
239 ts('Configure Default Mailbox'),
165aab59
CW
240 \Psr\Log\LogLevel::WARNING,
241 'fa-envelope'
1b366958 242 );
2a243675
CW
243 $docUrl = 'target="_blank" href="' . CRM_Utils_System::docURL(array('page' => 'user/advanced-configuration/email-system-configuration/', 'URLonly' => TRUE)) . '""';
244 $message->addHelp(
245 ts('A default mailbox must be configured for email bounce processing.') . '<br />' .
246 ts("Learn more in the <a %1>online documentation</a>.", array(1 => $docUrl))
247 );
1b366958
AH
248 $messages[] = $message;
249 }
250
251 return $messages;
252 }
aa96ce62
AH
253
254 /**
255 * Checks if cron has run in a reasonable amount of time
256 * @return array
257 */
aa96ce62
AH
258 public function checkLastCron() {
259 $messages = array();
260
261 $statusPreference = new CRM_Core_DAO_StatusPreference();
262 $statusPreference->domain_id = CRM_Core_Config::domainID();
263 $statusPreference->name = 'checkLastCron';
264
0296367d
CW
265 if ($statusPreference->find(TRUE) && !empty($statusPreference->check_info)) {
266 $lastCron = $statusPreference->check_info;
fba5f6ac
AH
267 $msg = ts('Last cron run at %1.', array(1 => CRM_Utils_Date::customFormat(date('c', $lastCron))));
268 }
269 else {
270 $lastCron = 0;
271 $msg = ts('No cron runs have been recorded.');
272 }
aa96ce62 273
aa96ce62
AH
274 if ($lastCron > gmdate('U') - 3600) {
275 $messages[] = new CRM_Utils_Check_Message(
165aab59 276 __FUNCTION__,
aa96ce62
AH
277 $msg,
278 ts('Cron Running OK'),
165aab59
CW
279 \Psr\Log\LogLevel::INFO,
280 'fa-clock-o'
aa96ce62
AH
281 );
282 }
fba5f6ac 283 else {
aa96ce62 284 $message = new CRM_Utils_Check_Message(
165aab59 285 __FUNCTION__,
aa96ce62
AH
286 $msg,
287 ts('Cron Not Running'),
2a243675 288 ($lastCron > gmdate('U') - 86400) ? \Psr\Log\LogLevel::WARNING : \Psr\Log\LogLevel::ERROR,
165aab59 289 'fa-clock-o'
aa96ce62 290 );
2a243675
CW
291 $docUrl = 'target="_blank" href="' . CRM_Utils_System::docURL(array('resource' => 'wiki', 'page' => 'Managing Scheduled Jobs', 'URLonly' => TRUE)) . '""';
292 $message->addHelp(
293 ts('Configuring cron on your server is necessary for running scheduled jobs such as sending mail and scheduled reminders.') . '<br />' .
294 ts("Learn more in the <a %1>online documentation</a>.", array(1 => $docUrl))
295 );
aa96ce62
AH
296 $messages[] = $message;
297 }
298
299 return $messages;
300 }
fba5f6ac
AH
301
302 /**
303 * Checks if new versions are available
304 * @return array
305 */
fba5f6ac
AH
306 public function checkVersion() {
307 $messages = array();
e2fb6a98
CW
308 try {
309 $vc = new CRM_Utils_VersionCheck();
310 $vc->initialize();
311 }
312 catch (Exception $e) {
313 $messages[] = new CRM_Utils_Check_Message(
314 'checkVersionError',
315 ts('Directory %1 is not writable. Please change your file permissions.',
316 array(1 => dirname($vc->cacheFile))),
317 ts('Directory not writable'),
318 \Psr\Log\LogLevel::ERROR,
319 'fa-times-circle-o'
320 );
321 return $messages;
322 }
fba5f6ac 323
b864507b
CW
324 // Show a notice if the version_check job is disabled
325 if (empty($vc->cronJob['is_active'])) {
326 $args = empty($vc->cronJob['id']) ? array('reset' => 1) : array('reset' => 1, 'action' => 'update', 'id' => $vc->cronJob['id']);
540c3e63
CW
327 $messages[] = new CRM_Utils_Check_Message(
328 'checkVersionDisabled',
329 ts('The check for new versions of CiviCRM has been disabled. <a %1>Re-enable the scheduled job</a> to receive important security update notifications.', array(1 => 'href="' . CRM_Utils_System::url('civicrm/admin/job', $args) . '"')),
330 ts('Update Check Disabled'),
331 \Psr\Log\LogLevel::NOTICE,
332 'fa-times-circle-o'
333 );
334 }
335
83f064f2 336 if ($vc->isInfoAvailable) {
b864507b 337 $newerVersion = $vc->isNewerVersionAvailable();
83f064f2
CW
338 if ($newerVersion['version']) {
339 $vInfo = array(
340 1 => $newerVersion['version'],
341 2 => $vc->localVersion,
342 );
343 // LTS = long-term support version
344 if ($newerVersion['status'] == 'lts') {
345 $vInfo[1] .= ' ' . ts('(long-term support)');
346 }
347
348 if ($newerVersion['upgrade'] == 'security') {
349 // Security
350 $severity = \Psr\Log\LogLevel::CRITICAL;
351 $title = ts('CiviCRM Security Update Required');
352 $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo);
353 }
354 elseif ($newerVersion['status'] == 'eol') {
355 // Warn about EOL
356 $severity = \Psr\Log\LogLevel::WARNING;
357 $title = ts('CiviCRM Update Needed');
358 $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo);
359 }
360 else {
361 // For most new versions, just make them notice
362 $severity = \Psr\Log\LogLevel::NOTICE;
363 $title = ts('CiviCRM Update Available');
364 $message = ts('New version %1 is available. The site is currently running %2.', $vInfo);
365 }
06576a03 366 }
b864507b 367 elseif (!empty($vc->cronJob['is_active'])) {
83f064f2
CW
368 $vNum = $vc->localVersion;
369 // LTS = long-term support version
370 if ($newerVersion['status'] == 'lts') {
371 $vNum .= ' ' . ts('(long-term support)');
372 }
373
374 $severity = \Psr\Log\LogLevel::INFO;
375 $title = ts('CiviCRM Up-to-Date');
376 $message = ts('CiviCRM version %1 is up-to-date.', array(1 => $vNum));
d450a5f0
CW
377 }
378
540c3e63
CW
379 if (!empty($message)) {
380 $messages[] = new CRM_Utils_Check_Message(
381 __FUNCTION__,
382 $message,
383 $title,
384 $severity,
385 'fa-cloud-upload'
d450a5f0
CW
386 );
387 }
06576a03 388 }
fba5f6ac 389
06576a03 390 return $messages;
fba5f6ac 391 }
580ad3ef
AH
392
393 /**
394 * Checks if extensions are set up properly
395 * @return array
396 */
580ad3ef
AH
397 public function checkExtensions() {
398 $messages = array();
399 $extensionSystem = CRM_Extension_System::singleton();
400 $mapper = $extensionSystem->getMapper();
401 $manager = $extensionSystem->getManager();
580ad3ef
AH
402
403 if ($extensionSystem->getDefaultContainer()) {
404 $basedir = $extensionSystem->getDefaultContainer()->baseDir;
405 }
406
407 if (empty($basedir)) {
408 // no extension directory
409 $messages[] = new CRM_Utils_Check_Message(
165aab59 410 __FUNCTION__,
580ad3ef
AH
411 ts('Your extensions directory is not set. Click <a href="%1">here</a> to set the extensions directory.',
412 array(1 => CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1'))),
e2fb6a98 413 ts('Directory not writable'),
165aab59
CW
414 \Psr\Log\LogLevel::NOTICE,
415 'fa-plug'
580ad3ef
AH
416 );
417 return $messages;
418 }
419
420 if (!is_dir($basedir)) {
421 $messages[] = new CRM_Utils_Check_Message(
165aab59 422 __FUNCTION__,
9329d168
AH
423 ts('Your extensions directory path points to %1, which is not a directory. Please check your file system.',
424 array(1 => $basedir)),
580ad3ef 425 ts('Extensions directory incorrect'),
165aab59
CW
426 \Psr\Log\LogLevel::ERROR,
427 'fa-plug'
580ad3ef
AH
428 );
429 return $messages;
430 }
431 elseif (!is_writable($basedir)) {
432 $messages[] = new CRM_Utils_Check_Message(
165aab59 433 __FUNCTION__,
e2fb6a98 434 ts('Directory %1 is not writable. Please change your file permissions.',
9329d168 435 array(1 => $basedir)),
e2fb6a98 436 ts('Directory not writable'),
165aab59
CW
437 \Psr\Log\LogLevel::ERROR,
438 'fa-plug'
580ad3ef
AH
439 );
440 return $messages;
441 }
442
443 if (empty($extensionSystem->getDefaultContainer()->baseUrl)) {
444 $messages[] = new CRM_Utils_Check_Message(
165aab59 445 __FUNCTION__,
580ad3ef
AH
446 ts('The extensions URL is not properly set. Please go to the <a href="%1">URL setting page</a> and correct it.',
447 array(1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1'))),
165aab59
CW
448 ts('Extensions url missing'),
449 \Psr\Log\LogLevel::ERROR,
450 'fa-plug'
580ad3ef
AH
451 );
452 return $messages;
453 }
454
b769826b
CW
455 if (!$extensionSystem->getBrowser()->isEnabled()) {
456 $messages[] = new CRM_Utils_Check_Message(
165aab59 457 __FUNCTION__,
b769826b
CW
458 ts('Not checking remote URL for extensions since ext_repo_url is set to false.'),
459 ts('Extensions check disabled'),
165aab59
CW
460 \Psr\Log\LogLevel::NOTICE,
461 'fa-plug'
b769826b
CW
462 );
463 return $messages;
464 }
465
466 try {
467 $remotes = $extensionSystem->getBrowser()->getExtensions();
468 }
469 catch (CRM_Extension_Exception $e) {
470 $messages[] = new CRM_Utils_Check_Message(
165aab59 471 __FUNCTION__,
b769826b
CW
472 $e->getMessage(),
473 ts('Extension download error'),
165aab59
CW
474 \Psr\Log\LogLevel::ERROR,
475 'fa-plug'
b769826b
CW
476 );
477 return $messages;
478 }
479
480 if (!$remotes) {
481 // CRM-13141 There may not be any compatible extensions available for the requested CiviCRM version + CMS. If so, $extdir is empty so just return a notice.
482 $messages[] = new CRM_Utils_Check_Message(
165aab59 483 __FUNCTION__,
b769826b
CW
484 ts('There are currently no extensions on the CiviCRM public extension directory which are compatible with version %1. If you want to install an extension which is not marked as compatible, you may be able to <a %2>download and install extensions manually</a> (depending on access to your web server).', array(
485 1 => CRM_Utils_System::majorVersion(),
486 2 => 'href="http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions"',
487 )),
488 ts('No Extensions Available for this Version'),
165aab59
CW
489 \Psr\Log\LogLevel::NOTICE,
490 'fa-plug'
b769826b
CW
491 );
492 return $messages;
493 }
494
580ad3ef
AH
495 $keys = array_keys($manager->getStatuses());
496 sort($keys);
6e61248d 497 $updates = $errors = $okextensions = array();
48f03858 498
580ad3ef
AH
499 foreach ($keys as $key) {
500 try {
501 $obj = $mapper->keyToInfo($key);
502 }
503 catch (CRM_Extension_Exception $ex) {
6e61248d 504 $errors[] = ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key));
580ad3ef
AH
505 continue;
506 }
507 $row = CRM_Admin_Page_Extensions::createExtendedInfo($obj);
508 switch ($row['status']) {
509 case CRM_Extension_Manager::STATUS_INSTALLED_MISSING:
6e61248d 510 $errors[] = ts('%1 extension (%2) is installed but missing files.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key));
580ad3ef
AH
511 break;
512
513 case CRM_Extension_Manager::STATUS_INSTALLED:
48f03858 514 if (!empty($remotes[$key]) && version_compare($row['version'], $remotes[$key]->version, '<')) {
6e61248d 515 $updates[] = ts('%1 (%2) version %3 is installed. <a %4>Upgrade to version %5</a>.', array(
48f03858
CW
516 1 => CRM_Utils_Array::value('label', $row),
517 2 => $key,
518 3 => $row['version'],
519 4 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', "action=update&id=$key&key=$key") . '"',
95db6764 520 5 => $remotes[$key]->version,
48f03858
CW
521 ));
522 }
523 else {
524 if (empty($row['label'])) {
525 $okextensions[] = $key;
580ad3ef
AH
526 }
527 else {
48f03858
CW
528 $okextensions[] = ts('%1 (%2) version %3', array(
529 1 => $row['label'],
530 2 => $key,
531 3 => $row['version'],
532 ));
580ad3ef
AH
533 }
534 }
580ad3ef 535 break;
580ad3ef
AH
536 }
537 }
6e61248d
CW
538
539 if (!$okextensions && !$updates && !$errors) {
e2a3547b 540 $messages[] = new CRM_Utils_Check_Message(
c08d5b15 541 'extensionsOk',
6e61248d 542 ts('No extensions installed. <a %1>Browse available extensions</a>.', array(
81756b44 543 1 => 'href="' . CRM_Utils_System::url('civicrm/admin/extensions', 'reset=1') . '"',
6e61248d
CW
544 )),
545 ts('Extensions'),
546 \Psr\Log\LogLevel::INFO,
547 'fa-plug'
e2a3547b 548 );
580ad3ef 549 }
6e61248d
CW
550
551 if ($errors) {
552 $messages[] = new CRM_Utils_Check_Message(
553 __FUNCTION__,
554 '<ul><li>' . implode('</li><li>', $errors) . '</li></ul>',
555 ts('Extension Error'),
556 \Psr\Log\LogLevel::ERROR,
557 'fa-plug'
558 );
48f03858 559 }
6e61248d
CW
560
561 if ($updates) {
562 $messages[] = new CRM_Utils_Check_Message(
563 'extensionUpdates',
564 '<ul><li>' . implode('</li><li>', $updates) . '</li></ul>',
565 ts('Extension Update Available', array('plural' => '%count Extension Updates Available', 'count' => count($updates))),
566 \Psr\Log\LogLevel::WARNING,
567 'fa-plug'
568 );
580ad3ef 569 }
097c681e 570
6e61248d 571 if ($okextensions) {
c08d5b15
CW
572 if ($updates || $errors) {
573 $message = ts('1 extension is up-to-date:', array('plural' => '%count extensions are up-to-date:', 'count' => count($okextensions)));
574 }
575 else {
576 $message = ts('All extensions are up-to-date:');
577 }
6e61248d
CW
578 $messages[] = new CRM_Utils_Check_Message(
579 'extensionsOk',
c08d5b15 580 $message . '<ul><li>' . implode('</li><li>', $okextensions) . '</li></ul>',
6e61248d
CW
581 ts('Extensions'),
582 \Psr\Log\LogLevel::INFO,
583 'fa-plug'
584 );
585 }
580ad3ef
AH
586
587 return $messages;
588 }
589
590
591 /**
592 * Checks if extensions are set up properly
593 * @return array
594 */
595 public function checkExtensionUpgrades() {
596 $messages = array();
597
598 if (CRM_Extension_Upgrades::hasPending()) {
599 $messages[] = new CRM_Utils_Check_Message(
165aab59 600 __FUNCTION__,
580ad3ef
AH
601 ts('Extension upgrades are pending. Please visit <a href="%1">the upgrade page</a> to run them.',
602 array(1 => CRM_Utils_System::url('civicrm/admin/extensions/upgrade', 'reset=1'))),
603 ts('Run Extension Upgrades'),
165aab59
CW
604 \Psr\Log\LogLevel::ERROR,
605 'fa-plug'
580ad3ef
AH
606 );
607 }
608 return $messages;
609 }
610
611 /**
612 * Checks if CiviCRM database version is up-to-date
613 * @return array
614 */
580ad3ef
AH
615 public function checkDbVersion() {
616 $messages = array();
617 $dbVersion = CRM_Core_BAO_Domain::version();
618 $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
619
620 if (!$dbVersion) {
621 // if db.ver missing
622 $messages[] = new CRM_Utils_Check_Message(
165aab59 623 __FUNCTION__,
580ad3ef
AH
624 ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.'),
625 ts('Database Version Missing'),
165aab59
CW
626 \Psr\Log\LogLevel::ERROR,
627 'fa-database'
580ad3ef
AH
628 );
629 }
630 elseif (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
631 $messages[] = new CRM_Utils_Check_Message(
165aab59 632 __FUNCTION__,
580ad3ef
AH
633 ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'),
634 ts('Database Version Invalid'),
165aab59
CW
635 \Psr\Log\LogLevel::ERROR,
636 'fa-database'
580ad3ef
AH
637 );
638 }
639 elseif (stripos($dbVersion, 'upgrade')) {
640 // if db.ver indicates a partially upgraded db
641 $messages[] = new CRM_Utils_Check_Message(
165aab59 642 __FUNCTION__,
580ad3ef
AH
643 ts('Database check failed - the database looks to have been partially upgraded. You must reload the database with the backup and try the <a href=\'%1\'>upgrade process</a> again.', array(1 => $upgradeUrl)),
644 ts('Database Partially Upgraded'),
165aab59
CW
645 \Psr\Log\LogLevel::ALERT,
646 'fa-database'
580ad3ef
AH
647 );
648 }
649 else {
650 $codeVersion = CRM_Utils_System::version();
651
652 // if db.ver < code.ver, time to upgrade
653 if (version_compare($dbVersion, $codeVersion) < 0) {
654 $messages[] = new CRM_Utils_Check_Message(
165aab59 655 __FUNCTION__,
580ad3ef
AH
656 ts('New codebase version detected. You must visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl)),
657 ts('Database Upgrade Required'),
165aab59
CW
658 \Psr\Log\LogLevel::ALERT,
659 'fa-database'
580ad3ef
AH
660 );
661 }
662
663 // if db.ver > code.ver, sth really wrong
664 if (version_compare($dbVersion, $codeVersion) > 0) {
665 $messages[] = new CRM_Utils_Check_Message(
165aab59 666 __FUNCTION__,
580ad3ef
AH
667 ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state.
668 You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase
669 you were using until you resolve this problem.<br/>OR if this is a manual install from git, you might want to fix civicrm-version.php file.',
670 array(1 => $dbVersion, 2 => $codeVersion)
671 ),
672 ts('Database In Unexpected Version'),
165aab59
CW
673 \Psr\Log\LogLevel::ERROR,
674 'fa-database'
580ad3ef
AH
675 );
676 }
677 }
678
679 return $messages;
680 }
681
682 /**
683 * ensure that all CiviCRM tables are InnoDB
684 * @return array
685 */
580ad3ef
AH
686 public function checkDbEngine() {
687 $messages = array();
688
689 if (CRM_Core_DAO::isDBMyISAM(150)) {
690 $messages[] = new CRM_Utils_Check_Message(
165aab59 691 __FUNCTION__,
580ad3ef
AH
692 ts('Your database is configured to use the MyISAM database engine. CiviCRM requires InnoDB. You will need to convert any MyISAM tables in your database to InnoDB. Using MyISAM tables will result in data integrity issues.'),
693 ts('MyISAM Database Engine'),
165aab59
CW
694 \Psr\Log\LogLevel::ERROR,
695 'fa-database'
580ad3ef
AH
696 );
697 }
698 return $messages;
699 }
700
5bc392e6 701}