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