CRM-13823 find status preference by name/domain combo
[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 $this->checkDomainNameEmail(),
48 $this->checkDefaultMailbox()
49 );
50 return $messages;
51 }
52
53 /**
54 * Check that the MySQL time settings match the PHP time settings.
55 *
56 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
57 */
58 public function checkMysqlTime() {
59 $messages = array();
60
61 $phpNow = date('Y-m-d H:i');
62 $sqlNow = CRM_Core_DAO::singleValueQuery("SELECT date_format(now(), '%Y-%m-%d %H:%i')");
63 if (!CRM_Utils_Time::isEqual($phpNow, $sqlNow, 2.5 * 60)) {
64 $messages[] = new CRM_Utils_Check_Message(
65 'checkMysqlTime',
66 ts('Timestamps reported by MySQL (eg "%2") and PHP (eg "%3" ) are mismatched.<br /><a href="%1">Read more about this warning</a>', array(
67 1 => CRM_Utils_System::getWikiBaseURL() . 'checkMysqlTime',
68 2 => $sqlNow,
69 3 => $phpNow,
70 )),
71 ts('Timestamp Mismatch'),
72 \Psr\Log\LogLevel::ERROR
73 );
74 }
75
76 return $messages;
77 }
78
79 /**
80 * @return array
81 */
82 public function checkDebug() {
83 $messages = array();
84
85 $config = CRM_Core_Config::singleton();
86 if ($config->debug) {
87 $messages[] = new CRM_Utils_Check_Message(
88 'checkDebug',
89 ts('Warning: Debug is enabled in <a href="%1">system settings</a>. This should not be enabled on production servers.',
90 array(1 => CRM_Utils_System::url('civicrm/admin/setting/debug', 'reset=1'))),
91 ts('Debug Mode Enabled'),
92 \Psr\Log\LogLevel::WARNING
93 );
94 }
95
96 return $messages;
97 }
98
99 /**
100 * @return array
101 */
102 public function checkOutboundMail() {
103 $messages = array();
104
105 $mailingInfo = CRM_Core_BAO_Setting::getItem(CRM_Core_BAO_Setting::MAILING_PREFERENCES_NAME, 'mailing_backend');
106 if (($mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_REDIRECT_TO_DB
107 || (defined('CIVICRM_MAIL_LOG') && CIVICRM_MAIL_LOG)
108 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_DISABLED
109 || $mailingInfo['outBound_option'] == CRM_Mailing_Config::OUTBOUND_OPTION_MOCK)
110 ) {
111 $messages[] = new CRM_Utils_Check_Message(
112 'checkOutboundMail',
113 ts('Warning: Outbound email is disabled in <a href="%1">system settings</a>. Proper settings should be enabled on production servers.',
114 array(1 => CRM_Utils_System::url('civicrm/admin/setting/smtp', 'reset=1'))),
115 ts('Outbound Email Disabled'),
116 \Psr\Log\LogLevel::WARNING
117 );
118 }
119
120 return $messages;
121 }
122
123 /**
124 * Check that domain email and org name are set
125 * @return array
126 */
127
128 public function checkDomainNameEmail() {
129 $messages = array();
130
131 list($domainEmailName, $domainEmailAddress) = CRM_Core_BAO_Domain::getNameAndEmail(TRUE);
132 $domain = CRM_Core_BAO_Domain::getDomain();
133 $domainName = $domain->name;
134 $fixEmailUrl = CRM_Utils_System::url("civicrm/admin/domain", "action=update&reset=1");
135
136 if (!$domainEmailAddress || $domainEmailAddress == 'info@EXAMPLE.ORG') {
137 if (!$domainName || $domainName == 'Default Domain Name') {
138 $msg = ts("Please enter your organization's <a href=\"%1\">name, primary address, and default FROM Email Address</a> (for system-generated emails).",
139 array(1 => $fixEmailUrl));
140 }
141 else {
142 $msg = ts('Please enter a <a href="%1">default FROM Email Address</a> (for system-generated emails).',
143 array(1 => $fixEmailUrl));
144 }
145 }
146 elseif (!$domainName || $domainName == 'Default Domain Name') {
147 $msg = ts("Please enter your organization's <a href=\"%1\">name and primary address</a>.",
148 array(1 => $fixEmailUrl));
149 }
150
151 if (!empty($msg)) {
152 $messages[] = new CRM_Utils_Check_Message(
153 'checkDomainNameEmail',
154 $msg,
155 ts('Complete Setup'),
156 \Psr\Log\LogLevel::WARNING
157 );
158 }
159
160 return $messages;
161 }
162
163 /**
164 * Checks if a default bounce handling mailbox is set up
165 * @return array
166 */
167
168 public function checkDefaultMailbox() {
169 $messages = array();
170 $config = CRM_Core_Config::singleton();
171
172 if (in_array('CiviMail', $config->enableComponents) &&
173 CRM_Core_BAO_MailSettings::defaultDomain() == "EXAMPLE.ORG"
174 ) {
175 $message = new CRM_Utils_Check_Message(
176 'checkDefaultMailbox',
177 ts('Please configure a default mailbox for CiviMail.',
178 array(1 => CRM_Utils_System::url('civicrm/admin/mailSettings', "reset=1"))),
179 ts('Configure Default Mailbox'),
180 \Psr\Log\LogLevel::WARNING
181 );
182 $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/')));
183 $messages[] = $message;
184 }
185
186 return $messages;
187 }
188 }