461be3439e40d68071f7889ca419fa6fd1cd9dcd
[civicrm-core.git] / CRM / Utils / Check / Env.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id: $
33 *
34 */
35 class CRM_Utils_Check_Env {
36
37 /**
38 * Run some sanity checks.
39 *
40 * @return array<CRM_Utils_Check_Message>
41 */
42 public function checkAll() {
43 $messages = array_merge(
44 $this->checkMysqlTime(),
45 $this->checkDebug(),
46 $this->checkOutboundMail()
47 );
48 return $messages;
49 }
50
51 /**
52 * Check that the MySQL time settings match the PHP time settings.
53 *
54 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
55 */
56 public function checkMysqlTime() {
57 $messages = array();
58
59 $phpNow = date('Y-m-d H:i');
60 $sqlNow = CRM_Core_DAO::singleValueQuery("SELECT date_format(now(), '%Y-%m-%d %H:%i')");
61 if (!CRM_Utils_Time::isEqual($phpNow, $sqlNow, 2.5 * 60)) {
62 $messages[] = new CRM_Utils_Check_Message(
63 'checkMysqlTime',
64 ts('Timestamps reported by MySQL (eg "%2") and PHP (eg "%3" ) are mismatched.<br /><a href="%1">Read more about this warning</a>', array(
65 1 => CRM_Utils_System::getWikiBaseURL() . 'checkMysqlTime',
66 2 => $sqlNow,
67 3 => $phpNow,
68 )),
69 ts('Environment Settings'),
70 \Psr\Log\LogLevel::ERROR
71 );
72 }
73
74 return $messages;
75 }
76
77 /**
78 * @return array
79 */
80 public function checkDebug() {
81 $messages = array();
82
83 $config = CRM_Core_Config::singleton();
84 if ($config->debug) {
85 $messages[] = new CRM_Utils_Check_Message(
86 'checkDebug',
87 ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.',
88 array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))),
89 ts('Debug Mode'),
90 \Psr\Log\LogLevel::WARNING
91 );
92 }
93
94 return $messages;
95 }
96
97 /**
98 * @return array
99 */
100 public function checkOutboundMail() {
101 $messages = array();
102
103 $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
104 if (($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB
105 || (defined('CIVICRM_MAIL_LOG') && CIVICRM_MAIL_LOG)
106 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED
107 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK)
108 ) {
109 $messages[] = new CRM_Utils_Check_Message(
110 'checkOutboundMail',
111 ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.',
112 array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))),
113 ts('Outbound Email Settings'),
114 \Psr\Log\LogLevel::WARNING
115 );
116 }
117
118 return $messages;
119 }
120
121 }