CRM-13823 - Cleanup and add icons to system status messages
[civicrm-core.git] / CRM / Utils / Check / Env.php
CommitLineData
1e927c45
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
1e927c45 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
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
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
1e927c45
TO
32 */
33class CRM_Utils_Check_Env {
34
35 /**
165aab59 36 * Run all checks in this class.
1e927c45
TO
37 *
38 * @return array<CRM_Utils_Check_Message>
39 */
40 public function checkAll() {
41 $messages = array_merge(
31e80d5a 42 $this->checkPhpVersion(),
7342d7c4
TO
43 $this->checkMysqlTime(),
44 $this->checkDebug(),
1b366958
AH
45 $this->checkOutboundMail(),
46 $this->checkDomainNameEmail(),
aa96ce62 47 $this->checkDefaultMailbox(),
06576a03 48 $this->checkLastCron(),
580ad3ef
AH
49 $this->checkVersion(),
50 $this->checkExtensions(),
51 $this->checkExtensionUpgrades(),
52 $this->checkDbVersion(),
53 $this->checkDbEngine()
1e927c45
TO
54 );
55 return $messages;
56 }
57
31e80d5a
CW
58 /**
59 * @return array
60 */
61 public function checkPhpVersion() {
62 $messages = array();
63
e0aee35d 64 if (version_compare(phpversion(), CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER) < 0) {
31e80d5a 65 $messages[] = new CRM_Utils_Check_Message(
165aab59 66 __FUNCTION__,
31e80d5a
CW
67 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.',
68 array(
69 1 => phpversion(),
e0aee35d 70 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
31e80d5a
CW
71 )),
72 ts('PHP Out-of-Date'),
165aab59
CW
73 \Psr\Log\LogLevel::NOTICE,
74 'fa-server'
31e80d5a
CW
75 );
76 }
77 else {
78 $messages[] = new CRM_Utils_Check_Message(
165aab59 79 __FUNCTION__,
31e80d5a
CW
80 ts('This system uses PHP version %1 which meets or exceeds the minimum recommendation of %2.',
81 array(
82 1 => phpversion(),
e0aee35d 83 2 => CRM_Upgrade_Incremental_General::MIN_RECOMMENDED_PHP_VER,
31e80d5a
CW
84 )),
85 ts('PHP Up-to-Date'),
165aab59
CW
86 \Psr\Log\LogLevel::INFO,
87 'fa-server'
31e80d5a
CW
88 );
89 }
90
91 return $messages;
92 }
93
7342d7c4
TO
94 /**
95 * Check that the MySQL time settings match the PHP time settings.
96 *
97 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
98 */
1e927c45
TO
99 public function checkMysqlTime() {
100 $messages = array();
101
102 $phpNow = date('Y-m-d H:i');
103 $sqlNow = CRM_Core_DAO::singleValueQuery("SELECT date_format(now(), '%Y-%m-%d %H:%i')");
8010540a 104 if (!CRM_Utils_Time::isEqual($phpNow, $sqlNow, 2.5 * 60)) {
1e927c45 105 $messages[] = new CRM_Utils_Check_Message(
165aab59 106 __FUNCTION__,
1e927c45 107 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 108 1 => CRM_Utils_System::getWikiBaseURL() . 'checkMysqlTime',
1e927c45
TO
109 2 => $sqlNow,
110 3 => $phpNow,
111 )),
1b366958 112 ts('Timestamp Mismatch'),
165aab59
CW
113 \Psr\Log\LogLevel::ERROR,
114 'fa-server'
1e927c45
TO
115 );
116 }
117
118 return $messages;
119 }
7342d7c4 120
5bc392e6
EM
121 /**
122 * @return array
123 */
7342d7c4
TO
124 public function checkDebug() {
125 $messages = array();
126
127 $config = CRM_Core_Config::singleton();
128 if ($config->debug) {
129 $messages[] = new CRM_Utils_Check_Message(
165aab59 130 __FUNCTION__,
7342d7c4
TO
131 ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.',
132 array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))),
1b366958 133 ts('Debug Mode Enabled'),
165aab59
CW
134 \Psr\Log\LogLevel::WARNING,
135 'fa-bug'
7342d7c4
TO
136 );
137 }
138
139 return $messages;
140 }
141
5bc392e6
EM
142 /**
143 * @return array
144 */
7342d7c4
TO
145 public function checkOutboundMail() {
146 $messages = array();
147
148 $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
149 if (($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB
150 || (defined('CIVICRM_MAIL_LOG') && CIVICRM_MAIL_LOG)
151 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED
152 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK)
153 ) {
154 $messages[] = new CRM_Utils_Check_Message(
165aab59 155 __FUNCTION__,
7342d7c4
TO
156 ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.',
157 array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))),
1b366958 158 ts('Outbound Email Disabled'),
165aab59
CW
159 \Psr\Log\LogLevel::WARNING,
160 'fa-envelope'
7342d7c4
TO
161 );
162 }
163
164 return $messages;
165 }
96025800 166
1b366958
AH
167 /**
168 * Check that domain email and org name are set
169 * @return array
170 */
1b366958
AH
171 public function checkDomainNameEmail() {
172 $messages = array();
173
174 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
175 $domain = CRM_Core_BAO_Domain::getDomain();
176 $domainName = $domain->name;
177 $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1");
178
179 if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
180 if (!$domainName || $domainName == 'Default Domain Name') {
181 $msg = ts("Please enter your organization's <a href=\"%1\">name, primary address, and default FROM Email Address</a> (for system-generated emails).",
182 array(1 => $fixEmailUrl));
183 }
184 else {
185 $msg = ts('Please enter a <a href="%1">default FROM Email Address</a> (for system-generated emails).',
186 array(1 => $fixEmailUrl));
187 }
188 }
189 elseif (!$domainName || $domainName == 'Default Domain Name') {
190 $msg = ts("Please enter your organization's <a href=\"%1\">name and primary address</a>.",
191 array(1 => $fixEmailUrl));
192 }
aacaa119
AH
193
194 if (!empty($msg)) {
195 $messages[] = new CRM_Utils_Check_Message(
165aab59 196 __FUNCTION__,
aacaa119
AH
197 $msg,
198 ts('Complete Setup'),
165aab59
CW
199 \Psr\Log\LogLevel::WARNING,
200 'fa-check-square-o'
aacaa119
AH
201 );
202 }
1b366958
AH
203
204 return $messages;
205 }
206
207 /**
208 * Checks if a default bounce handling mailbox is set up
209 * @return array
210 */
1b366958
AH
211 public function checkDefaultMailbox() {
212 $messages = array();
213 $config = CRM_Core_Config::singleton();
214
215 if (in_array('CiviMail', $config->enableComponents) &&
216 CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG"
217 ) {
218 $message = new CRM_Utils_Check_Message(
165aab59 219 __FUNCTION__,
aa96ce62 220 ts('Please configure a <a href="%1">default mailbox</a> for CiviMail.',
1b366958
AH
221 array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))),
222 ts('Configure Default Mailbox'),
165aab59
CW
223 \Psr\Log\LogLevel::WARNING,
224 'fa-envelope'
1b366958
AH
225 );
226 $message->addHelp(ts('Learn more in the <a href="%1">user guide</a>', array(1 => 'http://book.civicrm.org/user/advanced-configuration/email-system-configuration/')));
227 $messages[] = $message;
228 }
229
230 return $messages;
231 }
aa96ce62
AH
232
233 /**
234 * Checks if cron has run in a reasonable amount of time
235 * @return array
236 */
aa96ce62
AH
237 public function checkLastCron() {
238 $messages = array();
239
240 $statusPreference = new CRM_Core_DAO_StatusPreference();
241 $statusPreference->domain_id = CRM_Core_Config::domainID();
242 $statusPreference->name = 'checkLastCron';
243
fba5f6ac
AH
244 if ($statusPreference->find(TRUE)) {
245 $lastCron = CRM_Core_DAO::getFieldValue('CRM_Core_DAO_StatusPreference', $statusPreference->id, 'check_info');
246 $msg = ts('Last cron run at %1.', array(1 => CRM_Utils_Date::customFormat(date('c', $lastCron))));
247 }
248 else {
249 $lastCron = 0;
250 $msg = ts('No cron runs have been recorded.');
251 }
aa96ce62 252
aa96ce62
AH
253 if ($lastCron > gmdate('U') - 3600) {
254 $messages[] = new CRM_Utils_Check_Message(
165aab59 255 __FUNCTION__,
aa96ce62
AH
256 $msg,
257 ts('Cron Running OK'),
165aab59
CW
258 \Psr\Log\LogLevel::INFO,
259 'fa-clock-o'
aa96ce62
AH
260 );
261 }
262 elseif ($lastCron > gmdate('U') - 86400) {
263 $message = new CRM_Utils_Check_Message(
165aab59 264 __FUNCTION__,
aa96ce62
AH
265 $msg,
266 ts('Cron Not Running'),
165aab59
CW
267 \Psr\Log\LogLevel::WARNING,
268 'fa-clock-o'
aa96ce62 269 );
06576a03 270 $message->addHelp(ts('Learn more in the <a href="%1">Administrator\'s Guide supplement</a>', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs')));
aa96ce62
AH
271 $messages[] = $message;
272 }
fba5f6ac 273 else {
aa96ce62 274 $message = new CRM_Utils_Check_Message(
165aab59 275 __FUNCTION__,
aa96ce62
AH
276 $msg,
277 ts('Cron Not Running'),
165aab59
CW
278 \Psr\Log\LogLevel::ERROR,
279 'fa-clock-o'
aa96ce62 280 );
06576a03 281 $message->addHelp(ts('Learn more in the <a href="%1">Administrator\'s Guide supplement</a>', array(1 => 'http://wiki.civicrm.org/confluence/display/CRMDOC/Managing+Scheduled+Jobs')));
aa96ce62
AH
282 $messages[] = $message;
283 }
284
285 return $messages;
286 }
fba5f6ac
AH
287
288 /**
289 * Checks if new versions are available
290 * @return array
291 */
fba5f6ac
AH
292 public function checkVersion() {
293 $messages = array();
294
06576a03 295 if (CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::SYSTEM_PREFERENCES_NAME, 'versionAlert', NULL, 1)) {
097c681e 296 $vc = CRM_Utils_VersionCheck::singleton();
06576a03
AH
297 $newerVersion = $vc->isNewerVersionAvailable();
298
299 if ($newerVersion['version']) {
300 $vInfo = array(
301 1 => $newerVersion['version'],
302 2 => $vc->localVersion,
303 );
165aab59 304 // LTS = long-term support version
06576a03 305 if ($newerVersion['status'] == 'lts') {
165aab59 306 $vInfo[1] .= ' ' . ts('(long-term support)');
06576a03
AH
307 }
308
309 if ($newerVersion['upgrade'] == 'security') {
165aab59 310 // Security
06576a03
AH
311 $severity = \Psr\Log\LogLevel::CRITICAL;
312 $message = ts('New security release %1 is available. The site is currently running %2.', $vInfo);
313 }
314 elseif ($newerVersion['status'] == 'eol') {
315 // Warn about EOL
316 $severity = \Psr\Log\LogLevel::WARNING;
317 $message = ts('New version %1 is available. The site is currently running %2, which has reached its end of life.', $vInfo);
318 }
319 else {
320 // For most new versions, just make them notice
321 $severity = \Psr\Log\LogLevel::NOTICE;
322 $message = ts('New version %1 is available. The site is currently running %2.', $vInfo);
323 }
324 }
325 else {
326 $vNum = $vc->localVersion;
165aab59 327 // LTS = long-term support version
06576a03 328 if ($newerVersion['status'] == 'lts') {
165aab59 329 $vNum .= ' ' . ts('(long-term support)');
06576a03 330 }
fba5f6ac 331
06576a03
AH
332 $severity = \Psr\Log\LogLevel::INFO;
333 $message = ts('Version %1 is up-to-date.', array(1 => $vNum));
334 }
fba5f6ac 335
06576a03 336 $messages[] = new CRM_Utils_Check_Message(
165aab59 337 __FUNCTION__,
06576a03
AH
338 $message,
339 ts('Update Status'),
165aab59
CW
340 $severity,
341 'fa-cloud-upload'
06576a03
AH
342 );
343 }
344 else {
345 $messages[] = new CRM_Utils_Check_Message(
165aab59 346 __FUNCTION__,
06576a03
AH
347 ts('The check for new versions of CiviCRM has been disabled.'),
348 ts('Update Check Disabled'),
165aab59
CW
349 \Psr\Log\LogLevel::NOTICE,
350 'fa-times-circle-o'
06576a03
AH
351 );
352 }
fba5f6ac 353
06576a03 354 return $messages;
fba5f6ac 355 }
580ad3ef
AH
356
357 /**
358 * Checks if extensions are set up properly
359 * @return array
360 */
580ad3ef
AH
361 public function checkExtensions() {
362 $messages = array();
363 $extensionSystem = CRM_Extension_System::singleton();
364 $mapper = $extensionSystem->getMapper();
365 $manager = $extensionSystem->getManager();
580ad3ef
AH
366
367 if ($extensionSystem->getDefaultContainer()) {
368 $basedir = $extensionSystem->getDefaultContainer()->baseDir;
369 }
370
371 if (empty($basedir)) {
372 // no extension directory
373 $messages[] = new CRM_Utils_Check_Message(
165aab59 374 __FUNCTION__,
580ad3ef
AH
375 ts('Your extensions directory is not set. Click <a href="%1">here</a> to set the extensions directory.',
376 array(1 => CRM_Utils_System::url('civicrm/admin/setting/path', 'reset=1'))),
377 ts('Extensions directory not writable'),
165aab59
CW
378 \Psr\Log\LogLevel::NOTICE,
379 'fa-plug'
580ad3ef
AH
380 );
381 return $messages;
382 }
383
384 if (!is_dir($basedir)) {
385 $messages[] = new CRM_Utils_Check_Message(
165aab59 386 __FUNCTION__,
9329d168
AH
387 ts('Your extensions directory path points to %1, which is not a directory. Please check your file system.',
388 array(1 => $basedir)),
580ad3ef 389 ts('Extensions directory incorrect'),
165aab59
CW
390 \Psr\Log\LogLevel::ERROR,
391 'fa-plug'
580ad3ef
AH
392 );
393 return $messages;
394 }
395 elseif (!is_writable($basedir)) {
396 $messages[] = new CRM_Utils_Check_Message(
165aab59 397 __FUNCTION__,
9329d168
AH
398 ts('Your extensions directory, %1, is not writable. Please change your file permissions.',
399 array(1 => $basedir)),
580ad3ef 400 ts('Extensions directory not writable'),
165aab59
CW
401 \Psr\Log\LogLevel::ERROR,
402 'fa-plug'
580ad3ef
AH
403 );
404 return $messages;
405 }
406
407 if (empty($extensionSystem->getDefaultContainer()->baseUrl)) {
408 $messages[] = new CRM_Utils_Check_Message(
165aab59 409 __FUNCTION__,
580ad3ef
AH
410 ts('The extensions URL is not properly set. Please go to the <a href="%1">URL setting page</a> and correct it.',
411 array(1 => CRM_Utils_System::url('civicrm/admin/setting/url', 'reset=1'))),
165aab59
CW
412 ts('Extensions url missing'),
413 \Psr\Log\LogLevel::ERROR,
414 'fa-plug'
580ad3ef
AH
415 );
416 return $messages;
417 }
418
b769826b
CW
419 if (!$extensionSystem->getBrowser()->isEnabled()) {
420 $messages[] = new CRM_Utils_Check_Message(
165aab59 421 __FUNCTION__,
b769826b
CW
422 ts('Not checking remote URL for extensions since ext_repo_url is set to false.'),
423 ts('Extensions check disabled'),
165aab59
CW
424 \Psr\Log\LogLevel::NOTICE,
425 'fa-plug'
b769826b
CW
426 );
427 return $messages;
428 }
429
430 try {
431 $remotes = $extensionSystem->getBrowser()->getExtensions();
432 }
433 catch (CRM_Extension_Exception $e) {
434 $messages[] = new CRM_Utils_Check_Message(
165aab59 435 __FUNCTION__,
b769826b
CW
436 $e->getMessage(),
437 ts('Extension download error'),
165aab59
CW
438 \Psr\Log\LogLevel::ERROR,
439 'fa-plug'
b769826b
CW
440 );
441 return $messages;
442 }
443
444 if (!$remotes) {
445 // 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.
446 $messages[] = new CRM_Utils_Check_Message(
165aab59 447 __FUNCTION__,
b769826b
CW
448 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(
449 1 => CRM_Utils_System::majorVersion(),
450 2 => 'href="http://wiki.civicrm.org/confluence/display/CRMDOC/Extensions"',
451 )),
452 ts('No Extensions Available for this Version'),
165aab59
CW
453 \Psr\Log\LogLevel::NOTICE,
454 'fa-plug'
b769826b
CW
455 );
456 return $messages;
457 }
458
580ad3ef
AH
459 $keys = array_keys($manager->getStatuses());
460 sort($keys);
461 $severity = 1;
462 $msgArray = $okextensions = array();
463 foreach ($keys as $key) {
464 try {
465 $obj = $mapper->keyToInfo($key);
466 }
467 catch (CRM_Extension_Exception $ex) {
468 $severity = 4;
469 $msgArray[] = ts('Failed to read extension (%1). Please refresh the extension list.', array(1 => $key));
470 continue;
471 }
472 $row = CRM_Admin_Page_Extensions::createExtendedInfo($obj);
473 switch ($row['status']) {
474 case CRM_Extension_Manager::STATUS_INSTALLED_MISSING:
475 $severity = 4;
476 $msgArray[] = ts('%1 extension (%2) is installed but missing files.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key));
477 break;
478
479 case CRM_Extension_Manager::STATUS_INSTALLED:
480 if (CRM_Utils_Array::value($key, $remotes)) {
481 if (version_compare($row['version'], $remotes[$key]->version, '<')) {
482 $severity = ($severity < 3) ? 3 : $severity;
483 $msgArray[] = ts('%1 extension (%2) is upgradeable to version %3.', array(1 => CRM_Utils_Array::value('label', $row), 2 => $key, 3 => $remotes[$key]->version));
484 }
485 else {
486 $okextensions[] = CRM_Utils_Array::value('label', $row) ? "{$row['label']} ($key)" : $key;
487 }
488 }
489 else {
490 $okextensions[] = CRM_Utils_Array::value('label', $row) ? "{$row['label']} ($key)" : $key;
491 }
492 break;
493
494 case CRM_Extension_Manager::STATUS_UNINSTALLED:
495 case CRM_Extension_Manager::STATUS_DISABLED:
496 case CRM_Extension_Manager::STATUS_DISABLED_MISSING:
497 default:
498 }
499 }
500 $msg = implode(' ', $msgArray);
501 if (empty($msgArray)) {
502 $msg = (empty($okextensions)) ? ts('No extensions installed.') : ts('Extensions are up-to-date:') . ' ' . implode(', ', $okextensions);
503 }
504 elseif (!empty($okextensions)) {
505 $msg .= ' ' . ts('Other extensions are up-to-date:') . ' ' . implode(', ', $okextensions);
506 }
097c681e
AH
507
508 // OK, return several data rows
580ad3ef 509 $messages[] = new CRM_Utils_Check_Message(
165aab59 510 __FUNCTION__,
580ad3ef
AH
511 $msg,
512 ts('Extension Updates'),
165aab59
CW
513 CRM_Utils_Check::severityMap($severity, TRUE),
514 'fa-plug'
580ad3ef
AH
515 );
516
517 return $messages;
518 }
519
520
521 /**
522 * Checks if extensions are set up properly
523 * @return array
524 */
525 public function checkExtensionUpgrades() {
526 $messages = array();
527
528 if (CRM_Extension_Upgrades::hasPending()) {
529 $messages[] = new CRM_Utils_Check_Message(
165aab59 530 __FUNCTION__,
580ad3ef
AH
531 ts('Extension upgrades are pending. Please visit <a href="%1">the upgrade page</a> to run them.',
532 array(1 => CRM_Utils_System::url('civicrm/admin/extensions/upgrade', 'reset=1'))),
533 ts('Run Extension Upgrades'),
165aab59
CW
534 \Psr\Log\LogLevel::ERROR,
535 'fa-plug'
580ad3ef
AH
536 );
537 }
538 return $messages;
539 }
540
541 /**
542 * Checks if CiviCRM database version is up-to-date
543 * @return array
544 */
580ad3ef
AH
545 public function checkDbVersion() {
546 $messages = array();
547 $dbVersion = CRM_Core_BAO_Domain::version();
548 $upgradeUrl = CRM_Utils_System::url("civicrm/upgrade", "reset=1");
549
550 if (!$dbVersion) {
551 // if db.ver missing
552 $messages[] = new CRM_Utils_Check_Message(
165aab59 553 __FUNCTION__,
580ad3ef
AH
554 ts('Version information found to be missing in database. You will need to determine the correct version corresponding to your current database state.'),
555 ts('Database Version Missing'),
165aab59
CW
556 \Psr\Log\LogLevel::ERROR,
557 'fa-database'
580ad3ef
AH
558 );
559 }
560 elseif (!CRM_Utils_System::isVersionFormatValid($dbVersion)) {
561 $messages[] = new CRM_Utils_Check_Message(
165aab59 562 __FUNCTION__,
580ad3ef
AH
563 ts('Database is marked with invalid version format. You may want to investigate this before you proceed further.'),
564 ts('Database Version Invalid'),
165aab59
CW
565 \Psr\Log\LogLevel::ERROR,
566 'fa-database'
580ad3ef
AH
567 );
568 }
569 elseif (stripos($dbVersion, 'upgrade')) {
570 // if db.ver indicates a partially upgraded db
571 $messages[] = new CRM_Utils_Check_Message(
165aab59 572 __FUNCTION__,
580ad3ef
AH
573 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)),
574 ts('Database Partially Upgraded'),
165aab59
CW
575 \Psr\Log\LogLevel::ALERT,
576 'fa-database'
580ad3ef
AH
577 );
578 }
579 else {
580 $codeVersion = CRM_Utils_System::version();
581
582 // if db.ver < code.ver, time to upgrade
583 if (version_compare($dbVersion, $codeVersion) < 0) {
584 $messages[] = new CRM_Utils_Check_Message(
165aab59 585 __FUNCTION__,
580ad3ef
AH
586 ts('New codebase version detected. You must visit <a href=\'%1\'>upgrade screen</a> to upgrade the database.', array(1 => $upgradeUrl)),
587 ts('Database Upgrade Required'),
165aab59
CW
588 \Psr\Log\LogLevel::ALERT,
589 'fa-database'
580ad3ef
AH
590 );
591 }
592
593 // if db.ver > code.ver, sth really wrong
594 if (version_compare($dbVersion, $codeVersion) > 0) {
595 $messages[] = new CRM_Utils_Check_Message(
165aab59 596 __FUNCTION__,
580ad3ef
AH
597 ts('Your database is marked with an unexpected version number: %1. The v%2 codebase may not be compatible with your database state.
598 You will need to determine the correct version corresponding to your current database state. You may want to revert to the codebase
599 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.',
600 array(1 => $dbVersion, 2 => $codeVersion)
601 ),
602 ts('Database In Unexpected Version'),
165aab59
CW
603 \Psr\Log\LogLevel::ERROR,
604 'fa-database'
580ad3ef
AH
605 );
606 }
607 }
608
609 return $messages;
610 }
611
612 /**
613 * ensure that all CiviCRM tables are InnoDB
614 * @return array
615 */
580ad3ef
AH
616 public function checkDbEngine() {
617 $messages = array();
618
619 if (CRM_Core_DAO::isDBMyISAM(150)) {
620 $messages[] = new CRM_Utils_Check_Message(
165aab59 621 __FUNCTION__,
580ad3ef
AH
622 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.'),
623 ts('MyISAM Database Engine'),
165aab59
CW
624 \Psr\Log\LogLevel::ERROR,
625 'fa-database'
580ad3ef
AH
626 );
627 }
628 return $messages;
629 }
630
5bc392e6 631}