From 3a0d0bbd0b08e69b640ad0ee02cc393bcbb4c406 Mon Sep 17 00:00:00 2001 From: Coleman Watts Date: Thu, 10 Dec 2015 21:32:59 -0500 Subject: [PATCH] Cleanup CRM_Utils_Check classes --- CRM/Utils/Check.php | 24 +++----- CRM/Utils/Check/Component.php | 59 ++++++++++++++++++++ CRM/Utils/Check/{ => Component}/Case.php | 26 ++++----- CRM/Utils/Check/{ => Component}/Env.php | 25 +-------- CRM/Utils/Check/{ => Component}/Security.php | 21 +------ 5 files changed, 80 insertions(+), 75 deletions(-) create mode 100644 CRM/Utils/Check/Component.php rename CRM/Utils/Check/{ => Component}/Case.php (89%) rename CRM/Utils/Check/{ => Component}/Env.php (97%) rename CRM/Utils/Check/{ => Component}/Security.php (95%) diff --git a/CRM/Utils/Check.php b/CRM/Utils/Check.php index 73129d04c4..ea6c3c9b12 100644 --- a/CRM/Utils/Check.php +++ b/CRM/Utils/Check.php @@ -194,24 +194,14 @@ class CRM_Utils_Check { * Array of CRM_Utils_Check_Message objects */ public static function checkAll($max = FALSE) { - $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()); + foreach (glob(__DIR__ . '/Check/Component/*.php') as $filePath) { + $className = 'CRM_Utils_Check_Component_' . basename($filePath, '.php'); + /* @var CRM_Utils_Check_Component $check */ + $check = new $className(); + if ($check->isEnabled()) { + $messages = array_merge($messages, $check->checkAll()); + } } CRM_Utils_Hook::check($messages); diff --git a/CRM/Utils/Check/Component.php b/CRM/Utils/Check/Component.php new file mode 100644 index 0000000000..fe05ee2507 --- /dev/null +++ b/CRM/Utils/Check/Component.php @@ -0,0 +1,59 @@ +$method()); + } + } + return $messages; + } +} \ No newline at end of file diff --git a/CRM/Utils/Check/Case.php b/CRM/Utils/Check/Component/Case.php similarity index 89% rename from CRM/Utils/Check/Case.php rename to CRM/Utils/Check/Component/Case.php index 85bc78d215..e3da6d1501 100644 --- a/CRM/Utils/Check/Case.php +++ b/CRM/Utils/Check/Component/Case.php @@ -30,7 +30,7 @@ * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 */ -class CRM_Utils_Check_Case { +class CRM_Utils_Check_Component_Case extends CRM_Utils_Check_Component { /** * @var CRM_Case_XMLRepository @@ -46,27 +46,23 @@ class CRM_Utils_Check_Case { * @param CRM_Case_XMLRepository $xmlRepo * @param array $caseTypeNames */ - public function __construct($xmlRepo, $caseTypeNames) { - $this->caseTypeNames = $caseTypeNames; - $this->xmlRepo = $xmlRepo; + public function __construct() { + $this->caseTypeNames = CRM_Case_PseudoConstant::caseType('name'); + $this->xmlRepo = CRM_Case_XMLRepository::singleton(); } /** - * Run all checks in this class. - * - * @return array + * @inheritDoc */ - public function checkAll() { - $messages = array_merge( - $this->checkCaseTypeNameConsistency() - ); - return $messages; + 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 + * @return array + * An empty array, or a list of warnings */ public function checkCaseTypeNameConsistency() { $messages = array(); @@ -80,7 +76,7 @@ class CRM_Utils_Check_Case { } elseif ($normalFile && $mungedFile) { $messages[] = new CRM_Utils_Check_Message( - __FUNCTION__, + __FUNCTION__ . $caseTypeName, ts('Case type "%1" has duplicate XML files ("%2" and "%3")', array( 1 => $caseTypeName, 2 => $normalFile, @@ -99,7 +95,7 @@ class CRM_Utils_Check_Case { } elseif (!$normalFile && $mungedFile) { $messages[] = new CRM_Utils_Check_Message( - __FUNCTION__, + __FUNCTION__ . $caseTypeName, ts('Case type "%1" corresponds to XML file ("%2") The XML file should be named "%3".', array( 1 => $caseTypeName, 2 => $mungedFile, diff --git a/CRM/Utils/Check/Env.php b/CRM/Utils/Check/Component/Env.php similarity index 97% rename from CRM/Utils/Check/Env.php rename to CRM/Utils/Check/Component/Env.php index 6d5b616e2b..05855f6110 100644 --- a/CRM/Utils/Check/Env.php +++ b/CRM/Utils/Check/Component/Env.php @@ -30,30 +30,7 @@ * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 */ -class CRM_Utils_Check_Env { - - /** - * Run all checks in this class. - * - * @return array - */ - public function checkAll() { - $messages = array_merge( - $this->checkPhpVersion(), - $this->checkMysqlTime(), - $this->checkDebug(), - $this->checkOutboundMail(), - $this->checkDomainNameEmail(), - $this->checkDefaultMailbox(), - $this->checkLastCron(), - $this->checkVersion(), - $this->checkExtensions(), - $this->checkExtensionUpgrades(), - $this->checkDbVersion(), - $this->checkDbEngine() - ); - return $messages; - } +class CRM_Utils_Check_Component_Env extends CRM_Utils_Check_Component { /** * @return array diff --git a/CRM/Utils/Check/Security.php b/CRM/Utils/Check/Component/Security.php similarity index 95% rename from CRM/Utils/Check/Security.php rename to CRM/Utils/Check/Component/Security.php index 5ab5147d58..828ccf69d4 100644 --- a/CRM/Utils/Check/Security.php +++ b/CRM/Utils/Check/Component/Security.php @@ -30,13 +30,12 @@ * @package CRM * @copyright CiviCRM LLC (c) 2004-2015 */ -class CRM_Utils_Check_Security { +class CRM_Utils_Check_Component_Security extends CRM_Utils_Check_Component { /** * CMS have a different pattern to their default file path and URL. * - * @todo This function might be better shared in CRM_Utils_Check - * class, but that class doesn't yet exist. + * @todo Use Civi::paths instead? */ public function getFilePathMarker() { $config = CRM_Core_Config::singleton(); @@ -49,22 +48,6 @@ class CRM_Utils_Check_Security { } } - /** - * Run all checks in this class. - * - * @return array - */ - public function checkAll() { - $messages = array_merge( - $this->checkCxnOverrides(), - $this->checkLogFileIsNotAccessible(), - $this->checkUploadsAreNotAccessible(), - $this->checkDirectoriesAreNotBrowseable(), - $this->checkFilesAreNotPresent() - ); - return $messages; - } - /** * Check if our logfile is directly accessible. * -- 2.25.1