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