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