Commit | Line | Data |
---|---|---|
24877581 SL |
1 | <?php |
2 | /* | |
3 | +--------------------------------------------------------------------+ | |
fee14197 | 4 | | CiviCRM version 5 | |
24877581 | 5 | +--------------------------------------------------------------------+ |
f299f7db | 6 | | Copyright CiviCRM LLC (c) 2004-2020 | |
24877581 SL |
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 | |
f299f7db | 31 | * @copyright CiviCRM LLC (c) 2004-2020 |
24877581 SL |
32 | */ |
33 | class CRM_Utils_Check_Component_OptionGroups extends CRM_Utils_Check_Component { | |
34 | ||
35 | /** | |
36 | * @return array | |
37 | */ | |
38 | public function checkOptionGroupValues() { | |
be2fb01f CW |
39 | $messages = []; |
40 | $problemValues = []; | |
41 | $optionGroups = civicrm_api3('OptionGroup', 'get', [ | |
24877581 | 42 | 'sequential' => 1, |
be2fb01f CW |
43 | 'data_type' => ['IS NOT NULL' => 1], |
44 | 'options' => ['limit' => 0], | |
45 | ]); | |
24877581 SL |
46 | if ($optionGroups['count'] > 0) { |
47 | foreach ($optionGroups['values'] as $optionGroup) { | |
89c05afc SL |
48 | $values = CRM_Core_BAO_OptionValue::getOptionValuesArray($optionGroup['id']); |
49 | if (count($values) > 0) { | |
50 | foreach ($values as $value) { | |
8f352cb6 MWMC |
51 | try { |
52 | CRM_Utils_Type::validate($value['value'], $optionGroup['data_type'], FALSE, '', TRUE); | |
53 | } | |
54 | catch (Exception $e) { | |
be2fb01f | 55 | $problemValues[] = [ |
c62c37c7 | 56 | 'group_name' => $optionGroup['title'], |
24877581 | 57 | 'value_name' => $value['label'], |
be2fb01f | 58 | ]; |
24877581 SL |
59 | } |
60 | } | |
61 | } | |
62 | } | |
63 | } | |
64 | if (!empty($problemValues)) { | |
a37e4e6c | 65 | $strings = ''; |
24877581 | 66 | foreach ($problemValues as $problemValue) { |
be2fb01f | 67 | $strings .= ts('<tr><td> "%1" </td><td> "%2" </td></tr>', [ |
24877581 SL |
68 | 1 => $problemValue['group_name'], |
69 | 2 => $problemValue['value_name'], | |
be2fb01f | 70 | ]); |
24877581 SL |
71 | } |
72 | ||
73 | $messages[] = new CRM_Utils_Check_Message( | |
74 | __FUNCTION__, | |
75 | ts('The Following Option Values contain value fields that do not match the Data Type of the Option Group</p> | |
76 | <p><table><tbody><th>Option Group</th><th>Option Value</th></tbody><tbody>') . | |
a37e4e6c | 77 | $strings . ts('</tbody></table></p>'), |
24877581 SL |
78 | ts('Option Values with problematic Values'), |
79 | \Psr\Log\LogLevel::NOTICE, | |
80 | 'fa-server' | |
81 | ); | |
82 | } | |
83 | ||
84 | return $messages; | |
85 | } | |
86 | ||
87 | } |