Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_broken_sort_order.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Broken Sort Order Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to find any broken sort order on the links table';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69 
70  // Find the maximum sort order and count the links
71  $sql = 'SELECT majorid, MAX(sort_order) AS max, count(*) AS count FROM sq_ast_lnk WHERE majorid IN (SELECT DISTINCT majorid FROM sq_ast_lnk) GROUP BY majorid';
72  $results = MatrixDAL::executeSqlAssoc($sql);
73  if (!empty($results)) {
74  $count = 0;
75  foreach ($results as $result) {
76  if (($result['max'] + 1) != ($result['count'])) {
77  $status = FALSE;
78  $errors[] = 'The Asset #'.$result['majorid'].' has '.$result['count'].' assets underneath, but the sort order finishes at '.$result['max'];
79  $count++;
80  }//end if
81  }//end foreach
82  if (!$status && !empty($count)) {
83  $messages[] = 'There are '.$count.' broken sort orders found on the system';
84  }//end if
85  }//end if
86 
87  return $status;
88 
89  }//end test()
90 
91 }//end class
92 ?>