CRM-17637 - Add scheduled job
[civicrm-core.git] / CRM / Utils / Check / Case.php
CommitLineData
2aa3d7ab
TO
1<?php
2/*
3 +--------------------------------------------------------------------+
7e9e8871 4 | CiviCRM version 4.7 |
2aa3d7ab 5 +--------------------------------------------------------------------+
e7112fa7 6 | Copyright CiviCRM LLC (c) 2004-2015 |
2aa3d7ab
TO
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 +--------------------------------------------------------------------+
d25dd0ee 26 */
2aa3d7ab
TO
27
28/**
29 *
30 * @package CRM
e7112fa7 31 * @copyright CiviCRM LLC (c) 2004-2015
2aa3d7ab
TO
32 */
33class CRM_Utils_Check_Case {
34
35 /**
36 * @var CRM_Case_XMLRepository
37 */
38 protected $xmlRepo;
39
40 /**
41 * @var array<string>
42 */
43 protected $caseTypeNames;
44
45 /**
46 * @param CRM_Case_XMLRepository $xmlRepo
353ffa53 47 * @param array <string> $caseTypeNames
2aa3d7ab 48 */
00be9182 49 public function __construct($xmlRepo, $caseTypeNames) {
2aa3d7ab
TO
50 $this->caseTypeNames = $caseTypeNames;
51 $this->xmlRepo = $xmlRepo;
52 }
53
54 /**
165aab59 55 * Run all checks in this class.
2aa3d7ab
TO
56 *
57 * @return array<CRM_Utils_Check_Message>
58 */
59 public function checkAll() {
60 $messages = array_merge(
61 $this->checkCaseTypeNameConsistency()
62 );
63 return $messages;
64 }
65
66 /**
67 * Check that the case-type names don't rely on double-munging.
68 *
69 * @return array<CRM_Utils_Check_Message> an empty array, or a list of warnings
70 */
71 public function checkCaseTypeNameConsistency() {
72 $messages = array();
73
74 foreach ($this->caseTypeNames as $caseTypeName) {
75 $normalFile = $this->xmlRepo->findXmlFile($caseTypeName);
76 $mungedFile = $this->xmlRepo->findXmlFile(CRM_Case_XMLProcessor::mungeCaseType($caseTypeName));
77
78 if ($normalFile && $mungedFile && $normalFile == $mungedFile) {
79 // ok
80 }
81 elseif ($normalFile && $mungedFile) {
82 $messages[] = new CRM_Utils_Check_Message(
83 __FUNCTION__,
165aab59
CW
84 ts('Case type "%1" has duplicate XML files ("%2" and "%3")', array(
85 1 => $caseTypeName,
86 2 => $normalFile,
87 3 => $mungedFile,
88 )) .
89 '<br /><a href="' . CRM_Utils_System::getWikiBaseURL() . __FUNCTION__ . '">' .
90 ts('Read more about this warning') .
91 '</a>',
92 ts('CiviCase'),
93 \Psr\Log\LogLevel::WARNING,
94 'fa-puzzle-piece'
2aa3d7ab
TO
95 );
96 }
97 elseif ($normalFile && !$mungedFile) {
98 // ok
99 }
100 elseif (!$normalFile && $mungedFile) {
101 $messages[] = new CRM_Utils_Check_Message(
102 __FUNCTION__,
165aab59
CW
103 ts('Case type "%1" corresponds to XML file ("%2") The XML file should be named "%3".', array(
104 1 => $caseTypeName,
105 2 => $mungedFile,
106 3 => "{$caseTypeName}.xml",
107 )) .
108 '<br /><a href="' . CRM_Utils_System::getWikiBaseURL() . __FUNCTION__ . '">' .
109 ts('Read more about this warning') .
110 '</a>',
111 ts('CiviCase'),
112 \Psr\Log\LogLevel::WARNING,
113 'fa-puzzle-piece'
2aa3d7ab
TO
114 );
115 }
116 elseif (!$normalFile && !$mungedFile) {
117 // ok -- probably a new or DB-based CaseType
118 }
119 }
120
121 return $messages;
122 }
96025800 123
ef10e0b5 124}