Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_fragmented_attributes.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Fragmented Attributes Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to check for fragmented attributes on the attributes table';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  // Missing assets
70  $asset_sql = 'SELECT assetid FROM sq_ast_attr_val WHERE assetid NOT IN (SELECT DISTINCT assetid FROM sq_ast) OR attrid NOT IN (SELECT DISTINCT attrid FROM sq_ast_attr)';
71  $asset_results = MatrixDAL::executeSqlAssoc($asset_sql);
72 
73  foreach ($asset_results as $index => $result) {
74  $asset_results[$index] = $result['assetid'];
75  }
76  $asset_results = array_unique($asset_results);
77 
78  if (!empty($asset_results)) {
79  $status = FALSE;
80  foreach ($asset_results as $result) {
81  $errors[] = 'Asset #'.$result.' on the attributes table does not exist';
82  }//end foreach
83  }//end if
84 
85  // Missing attributes
86  $attr_sql = 'SELECT attrid FROM sq_ast_attr_val WHERE attrid NOT IN (SELECT DISTINCT attrid FROM sq_ast_attr)';
87  $attr_results = MatrixDAL::executeSqlAssoc($attr_sql);
88 
89  foreach ($attr_results as $index => $result) {
90  $attr_results[$index] = $result['attrid'];
91  }
92  $attr_results = array_unique($asset_results);
93 
94  if (!empty($attr_results)) {
95  $status = FALSE;
96  foreach ($attr_results as $result) {
97  $errors[] = 'Attribute #'.$result.' on the attributes table does not exist';
98  }//end foreach
99  }//end if
100 
101  if (!$status) {
102  $count = count($asset_results) + count($attr_results);
103  $messages[] = 'There are '.$count.' fragmented attribute(s) on the system';
104  }//end if
105 
106  return $status;
107 
108  }//end test()
109 
110 }//end class
111 ?>