@@ -1026,6 +1026,13 @@ private static function testFieldTypeValidationRules($remove_orphans)
10261026 }
10271027
10281028
1029+ /**
1030+ * N.B. The field_validation table has a composite primary key of rule_id and field_id. rule_id is just an integer
1031+ * from 1-N, where N is the number of validation rules for the field type. So this test just looks for and clears out
1032+ * invalid field IDs - rule IDs are neither here nor there.
1033+ * @param $remove_orphans
1034+ * @return array
1035+ */
10291036 private static function testFieldValidation ($ remove_orphans )
10301037 {
10311038 $ db = Core::$ db ;
@@ -1036,37 +1043,23 @@ private static function testFieldValidation($remove_orphans)
10361043 );
10371044
10381045 $ valid_field_ids = General::getFieldIds ();
1039- $ valid_rule_ids = General::getValidationRuleIds ();
10401046
10411047 $ db ->query ("SELECT rule_id, field_id FROM {PREFIX}field_validation " );
10421048 $ db ->execute ();
10431049 $ rows = $ db ->fetchAll ();
10441050
10451051 $ num_tests = 0 ;
10461052 foreach ($ rows as $ row ) {
1047- if (!in_array ($ row ["rule_id " ], $ valid_rule_ids )) {
1048- $ response ["problems " ][] = "Invalid reference to rule_id: {$ row ["rule_id " ]} for field_id: {$ row ["field_id " ]}" ;
1049-
1050- // clean-up code
1051- if ($ remove_orphans ) {
1052- $ db ->query ("
1053- DELETE FROM {PREFIX}field_validation
1054- WHERE rule_id = :rule_id
1055- " );
1056- $ db ->bind ("rule_id " , $ row ["rule_id " ]);
1057- $ db ->execute ();
1058- }
1059- }
10601053 if (!in_array ($ row ["field_id " ], $ valid_field_ids )) {
10611054 $ response ["problems " ][] = "Invalid reference to field_id: {$ row ["field_id " ]} for rule_id: {$ row ["rule_id " ]}" ;
10621055
10631056 // clean-up code
10641057 if ($ remove_orphans ) {
10651058 $ db ->query ("
10661059 DELETE FROM {PREFIX}field_validation
1067- WHERE rule_id = :rule_id
1060+ WHERE field_id = :field_id
10681061 " );
1069- $ db ->bind ("rule_id " , $ row ["rule_id " ]);
1062+ $ db ->bind ("field_id " , $ row ["field_id " ]);
10701063 $ db ->execute ();
10711064 }
10721065 }
0 commit comments