commiting uncommited changes on live site
[weblabels.fsf.org.git] / crm.fsf.org / 20131203 / files / sites / all / modules-new / civicrm / CRM / Utils / Check / Case.php
1 <?php
2 /*
3 +--------------------------------------------------------------------+
4 | CiviCRM version 4.6 |
5 +--------------------------------------------------------------------+
6 | Copyright CiviCRM LLC (c) 2004-2015 |
7 +--------------------------------------------------------------------+
8 | This file is a part of CiviCRM. |
9 | |
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. |
13 | |
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. |
18 | |
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 +--------------------------------------------------------------------+
26 */
27
28 /**
29 *
30 * @package CRM
31 * @copyright CiviCRM LLC (c) 2004-2015
32 * $Id: $
33 *
34 */
35 class CRM_Utils_Check_Case {
36
37 /**
38 * @var CRM_Case_XMLRepository
39 */
40 protected $xmlRepo;
41
42 /**
43 * @var array<string>
44 */
45 protected $caseTypeNames;
46
47 /**
48 * @param CRM_Case_XMLRepository $xmlRepo
49 * @param array <string> $caseTypeNames
50 */
51 public function __construct($xmlRepo, $caseTypeNames) {
52 $this->caseTypeNames = $caseTypeNames;
53 $this->xmlRepo = $xmlRepo;
54 }
55
56 /**
57 * Run some sanity checks.
58 *
59 * @return array<CRM_Utils_Check_Message>
60 */
61 public function checkAll() {
62 $messages = array_merge(
63 $this->checkCaseTypeNameConsistency()
64 );
65 return $messages;
66 }
67
68 /**
69 * Check that the case-type names don't rely on double-munging.
70 *
71 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
72 */
73 public function checkCaseTypeNameConsistency() {
74 $messages = array();
75
76 foreach ($this->caseTypeNames as $caseTypeName) {
77 $normalFile = $this->xmlRepo->findXmlFile($caseTypeName);
78 $mungedFile = $this->xmlRepo->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseTypeName));
79
80 if ($normalFile && $mungedFile && $normalFile == $mungedFile) {
81 // ok
82 }
83 elseif ($normalFile && $mungedFile) {
84 $messages[] = new CRM_Utils_Check_Message(
85 __FUNCTION__,
86 ts('Case type "%2" has duplicate XML files ("%3" and "%4").<br /><a href="%1">Read more about this warning</a>', array(
87 1 => CRM_Utils_System::getWikiBaseURL() . __FUNCTION__,
88 2 => $caseTypeName,
89 3 => $normalFile,
90 4 => $mungedFile,
91 )),
92 ts('CiviCase')
93 );
94 }
95 elseif ($normalFile && !$mungedFile) {
96 // ok
97 }
98 elseif (!$normalFile && $mungedFile) {
99 $messages[] = new CRM_Utils_Check_Message(
100 __FUNCTION__,
101 ts('Case type "%2" corresponds to XML file ("%3") The XML file should be named "%4".<br /><a href="%1">Read more about this warning</a>', array(
102 1 => CRM_Utils_System::getWikiBaseURL() . __FUNCTION__,
103 2 => $caseTypeName,
104 3 => $mungedFile,
105 4 => "{$caseTypeName}.xml",
106 )),
107 ts('CiviCase')
108 );
109 }
110 elseif (!$normalFile && !$mungedFile) {
111 // ok -- probably a new or DB-based CaseType
112 }
113 }
114
115 return $messages;
116 }
117
118 }