From 46ec593d75407a89a97ddcfbd7ba18755754ab33 Mon Sep 17 00:00:00 2001 From: Tim Otten Date: Mon, 11 Aug 2014 20:52:11 -0700 Subject: [PATCH] CRM-14798 - Allow loading CiviCase XML files even if case-type name is malformed For case-types registered via GUI in old (pre-4.5) versions, the autogenerated machine names were often ucky, and there was no way to clean them up. We'll allow backward-compatibility in 4.5 -- and also provide warnings/tools to facilitate cleanup. --- CRM/Case/BAO/CaseType.php | 6 ++++-- CRM/Case/XMLRepository.php | 19 ++++++++++++------- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/CRM/Case/BAO/CaseType.php b/CRM/Case/BAO/CaseType.php index ff2979ead1..4b33515613 100644 --- a/CRM/Case/BAO/CaseType.php +++ b/CRM/Case/BAO/CaseType.php @@ -70,8 +70,10 @@ class CRM_Case_BAO_CaseType extends CRM_Case_DAO_CaseType { if (!$nameParam && empty($params['id'])) { $params['name'] = CRM_Utils_String::titleToVar($params['title']); } - if (!empty($params['name']) && !CRM_Case_BAO_CaseType::isValidName($params['name'])) { - throw new CRM_Core_Exception("Cannot create caseType with malformed name [{$params['name']}]"); + + // Old case-types (pre-4.5) may keep their ucky names, but new case-types must satisfy isValidName() + if (empty($params['id']) && !empty($params['name']) && !CRM_Case_BAO_CaseType::isValidName($params['name'])) { + throw new CRM_Core_Exception("Cannot create new case-type with malformed name [{$params['name']}]"); } // function to format definition column diff --git a/CRM/Case/XMLRepository.php b/CRM/Case/XMLRepository.php index 5193f468c6..8560e022c6 100644 --- a/CRM/Case/XMLRepository.php +++ b/CRM/Case/XMLRepository.php @@ -84,16 +84,21 @@ class CRM_Case_XMLRepository { return simplexml_load_string($definition); } - if (!CRM_Case_BAO_CaseType::isValidName($caseType)) { - // perhaps caller provider a the label instead of the name? - throw new CRM_Core_Exception("Cannot load caseType with malformed name [$caseType]"); - } + // TODO In 4.6 or 5.0, remove support for weird machine-names + //if (!CRM_Case_BAO_CaseType::isValidName($caseType)) { + // // perhaps caller provider a the label instead of the name? + // throw new CRM_Core_Exception("Cannot load caseType with malformed name [$caseType]"); + //} if (!CRM_Utils_Array::value($caseType, $this->xml)) { - // Search for a file based directly on the $caseType name - $fileName = $this->findXmlFile($caseType); + $fileName = NULL; + + if (CRM_Case_BAO_CaseType::isValidName($caseType)) { + // Search for a file based directly on the $caseType name + $fileName = $this->findXmlFile($caseType); + } - // For backward compatibility, also search for double-mungd file names + // For backward compatibility, also search for double-munged file names // TODO In 4.6 or 5.0, remove support for loading double-munged file names if (!$fileName || !file_exists($fileName)) { $fileName = $this->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseType)); -- 2.25.1