From: Tim Otten Date: Sat, 28 Jun 2014 00:43:10 +0000 (-0700) Subject: CRM-14798 - CRM_Utils_Check - Display warning if site has mismatched file names X-Git-Url: https://vcs.fsf.org/?a=commitdiff_plain;h=2aa3d7abceb0442c6d967494d4bce11a7d98a42d;p=civicrm-core.git CRM-14798 - CRM_Utils_Check - Display warning if site has mismatched file names --- diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 822f40de27..32782c3ebd 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -119,12 +119,24 @@ class CRM_Utils_Check { * https://api.drupal.org/api/drupal/modules%21system%21system.api.php/function/hook_requirements */ public function checkAll() { - $security = new CRM_Utils_Check_Security(); - $env = new CRM_Utils_Check_Env(); - $messages = array_merge( - $security->checkAll(), - $env->checkAll() - ); + $checks = array(); + $checks[] = new CRM_Utils_Check_Security(); + $checks[] = new CRM_Utils_Check_Env(); + + $compInfo = CRM_Core_Component::getEnabledComponents(); + foreach ($compInfo as $compObj) { + switch ($compObj->info['name']) { + case 'CiviCase': + $checks[] = new CRM_Utils_Check_Case(CRM_Case_XMLRepository::singleton(), CRM_Case_PseudoConstant::caseType('name')); + break; + default: + } + } + + $messages = array(); + foreach ($checks as $check) { + $messages = array_merge($messages, $check->checkAll()); + } return $messages; } diff --git a/CRM/Utils/Check/Case.php b/CRM/Utils/Check/Case.php new file mode 100644 index 0000000000..a3995ecc4e --- /dev/null +++ b/CRM/Utils/Check/Case.php @@ -0,0 +1,117 @@ + + */ + protected $caseTypeNames; + + /** + * @param CRM_Case_XMLRepository $xmlRepo + * @param array $caseTypeNames + */ + function __construct($xmlRepo, $caseTypeNames) { + $this->caseTypeNames = $caseTypeNames; + $this->xmlRepo = $xmlRepo; + } + + /** + * Run some sanity checks. + * + * @return array + */ + public function checkAll() { + $messages = array_merge( + $this->checkCaseTypeNameConsistency() + ); + return $messages; + } + + /** + * 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__, + ts('Case type "%2" has duplicate XML files ("%3" and "%4").
Read more about this warning', array( + 1 => CRM_Utils_System::getWikiBaseURL() . __FUNCTION__, + 2 => $caseTypeName, + 3 => $normalFile, + 4 => $mungedFile, + )), + ts('CiviCase') + ); + } + elseif ($normalFile && !$mungedFile) { + // ok + } + elseif (!$normalFile && $mungedFile) { + $messages[] = new CRM_Utils_Check_Message( + __FUNCTION__, + ts('Case type "%2" corresponds to XML file ("%3") The XML file should be named "%4".
Read more about this warning', array( + 1 => CRM_Utils_System::getWikiBaseURL() . __FUNCTION__, + 2 => $caseTypeName, + 3 => $mungedFile, + 4 => "{$caseTypeName}.xml", + )), + ts('CiviCase') + ); + } + elseif (!$normalFile && !$mungedFile) { + // ok -- probably a new or DB-based CaseType + } + } + + return $messages; + } +} \ No newline at end of file