3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.7 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2018 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
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. |
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. |
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 +--------------------------------------------------------------------+
31 * @copyright CiviCRM LLC (c) 2004-2018
33 class CRM_Utils_Check_Component_Case
extends CRM_Utils_Check_Component
{
35 const DOCTOR_WHEN
= 'https://github.com/civicrm/org.civicrm.doctorwhen';
38 * @var CRM_Case_XMLRepository
45 protected $caseTypeNames;
50 public function __construct() {
51 $this->caseTypeNames
= CRM_Case_PseudoConstant
::caseType('name');
52 $this->xmlRepo
= CRM_Case_XMLRepository
::singleton();
58 public function isEnabled() {
59 return CRM_Case_BAO_Case
::enabled();
63 * Check that the case-type names don't rely on double-munging.
65 * @return array<CRM_Utils_Check_Message>
66 * An empty array, or a list of warnings
68 public function checkCaseTypeNameConsistency() {
71 foreach ($this->caseTypeNames
as $caseTypeName) {
72 $normalFile = $this->xmlRepo
->findXmlFile($caseTypeName);
73 $mungedFile = $this->xmlRepo
->findXmlFile(CRM_Case_XMLProcessor
::mungeCaseType($caseTypeName));
75 if ($normalFile && $mungedFile && $normalFile == $mungedFile) {
78 elseif ($normalFile && $mungedFile) {
79 $messages[] = new CRM_Utils_Check_Message(
80 __FUNCTION__
. $caseTypeName,
81 ts('Case type "%1" has duplicate XML files ("%2" and "%3")', array(
86 '<br /><a href="' . CRM_Utils_System
::getWikiBaseURL() . __FUNCTION__
. '">' .
87 ts('Read more about this warning') .
90 \Psr\Log\LogLevel
::WARNING
,
94 elseif ($normalFile && !$mungedFile) {
97 elseif (!$normalFile && $mungedFile) {
98 $messages[] = new CRM_Utils_Check_Message(
99 __FUNCTION__
. $caseTypeName,
100 ts('Case type "%1" corresponds to XML file ("%2") The XML file should be named "%3".', array(
103 3 => "{$caseTypeName}.xml",
105 '<br /><a href="' . CRM_Utils_System
::getWikiBaseURL() . __FUNCTION__
. '">' .
106 ts('Read more about this warning') .
109 \Psr\Log\LogLevel
::WARNING
,
113 elseif (!$normalFile && !$mungedFile) {
114 // ok -- probably a new or DB-based CaseType
122 * Check that the timestamp columns are populated. (CRM-20958)
124 * @return array<CRM_Utils_Check_Message>
125 * An empty array, or a list of warnings
127 public function checkNullTimestamps() {
131 $nullCount +
= CRM_Utils_SQL_Select
::from('civicrm_activity')
132 ->where('created_date IS NULL OR modified_date IS NULL')
136 $nullCount +
= CRM_Utils_SQL_Select
::from('civicrm_case')
137 ->where('created_date IS NULL OR modified_date IS NULL')
142 if ($nullCount > 0) {
143 $messages[] = new CRM_Utils_Check_Message(
146 ts('The tables "<em>civicrm_activity</em>" and "<em>civicrm_case</em>" were updated to support two new fields, "<em>created_date</em>" and "<em>modified_date</em>". For historical data, these fields may appear blank. (%1 records have NULL timestamps.)', array(
150 ts('At time of writing, this is not a problem. However, future extensions and improvements could rely on these fields, so it may be useful to back-fill them.') .
152 ts('For further discussion, please visit %1', array(
153 1 => sprintf('<a href="%s" target="_blank">%s</a>', self
::DOCTOR_WHEN
, self
::DOCTOR_WHEN
),
156 ts('Timestamps for Activities and Cases'),
157 \Psr\Log\LogLevel
::NOTICE
,