*/ protected $caseTypeNames; /** * Class constructor. */ public function __construct() { $this->caseTypeNames = CRM_Case_PseudoConstant::caseType('name'); $this->xmlRepo = CRM_Case_XMLRepository::singleton(); } /** * @inheritDoc */ public function isEnabled() { return CRM_Case_BAO_Case::enabled(); } /** * Check that the case-type names don't rely on double-munging. * * @return array * An empty array, or a list of warnings */ public function checkCaseTypeNameConsistency() { $messages = array(); foreach ($this->caseTypeNames as $caseTypeName) { $normalFile = $this->xmlRepo->findXmlFile($caseTypeName); $mungedFile = $this->xmlRepo->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseTypeName)); if ($normalFile && $mungedFile && $normalFile == $mungedFile) { // ok } elseif ($normalFile && $mungedFile) { $messages[] = new CRM_Utils_Check_Message( __FUNCTION__ . $caseTypeName, ts('Case type "%1" has duplicate XML files ("%2" and "%3")', array( 1 => $caseTypeName, 2 => $normalFile, 3 => $mungedFile, )) . '
' . ts('Read more about this warning') . '', ts('CiviCase'), \Psr\Log\LogLevel::WARNING, 'fa-puzzle-piece' ); } elseif ($normalFile && !$mungedFile) { // ok } elseif (!$normalFile && $mungedFile) { $messages[] = new CRM_Utils_Check_Message( __FUNCTION__ . $caseTypeName, ts('Case type "%1" corresponds to XML file ("%2") The XML file should be named "%3".', array( 1 => $caseTypeName, 2 => $mungedFile, 3 => "{$caseTypeName}.xml", )) . '
' . ts('Read more about this warning') . '', ts('CiviCase'), \Psr\Log\LogLevel::WARNING, 'fa-puzzle-piece' ); } elseif (!$normalFile && !$mungedFile) { // ok -- probably a new or DB-based CaseType } } return $messages; } /** * Check that the timestamp columns are populated. (CRM-20958) * * @return array * An empty array, or a list of warnings */ public function checkNullTimestamps() { $messages = array(); $nullCount = 0; $nullCount += CRM_Utils_SQL_Select::from('civicrm_activity') ->where('created_date IS NULL OR modified_date IS NULL') ->select('COUNT(*)') ->execute() ->fetchValue(); $nullCount += CRM_Utils_SQL_Select::from('civicrm_case') ->where('created_date IS NULL OR modified_date IS NULL') ->select('COUNT(*)') ->execute() ->fetchValue(); if ($nullCount > 0) { $messages[] = new CRM_Utils_Check_Message( __FUNCTION__, '

' . ts('The tables "civicrm_activity" and "civicrm_case" were updated to support two new fields, "created_date" and "modified_date". For historical data, these fields may appear blank. (%1 records have NULL timestamps.)', array( 1 => $nullCount, )) . '

' . 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.') . '

' . ts('For further discussion, please visit %1', array( 1 => sprintf('%s', self::DOCTOR_WHEN, self::DOCTOR_WHEN), )) . '

', ts('Timestamps for Activities and Cases'), \Psr\Log\LogLevel::NOTICE, 'fa-clock-o' ); } return $messages; } }