Squiz Matrix  4.12.2
 All Data Structures Namespaces Functions Variables Pages
test_invalid_num_kids.inc
1 <?php
28 {
29 
30 
37  public static function getName()
38  {
39  return 'Invalid Number of Kids on Link Tree Test';
40 
41  }//end getName()
42 
43 
50  public static function getDescription()
51  {
52  return 'A test to detect invalid number of kids entries on link tree';
53 
54  }//end getDescription()
55 
56 
66  public static function test(&$messages, &$errors)
67  {
68  $status = TRUE;
69  $count = 0;
70 
71  // Check the root folder first
72  $root_sql = "SELECT pt.linkid, pt.treeid, pt.num_kids, count(ct.treeid) AS count FROM sq_ast_lnk_tree ct, sq_ast_lnk_tree pt WHERE pt.linkid = '1' AND ct.treeid LIKE '0000%' AND LENGTH(ct.treeid) = (LENGTH(pt.treeid) + ".SQ_CONF_ASSET_TREE_SIZE.") GROUP BY pt.linkid, pt.treeid, pt.num_kids";
73  $root_results = MatrixDAL::executeSqlAssoc($root_sql);
74  foreach ($root_results as $result) {
75  if ($result['num_kids'] != $result['count']) {
76  $status = FALSE;
77  $count++;
78  $errors[] = 'Link #'.$result['linkid'].' has '.$result['num_kids'].' kids listed, but actually '.$result['count'].' kids were found';
79  }//end if
80  }//end foreach
81 
82  // Next the rest of the tree
83  $sql = "SELECT pt.linkid, pt.treeid, pt.num_kids, count(ct.treeid) AS count FROM sq_ast_lnk_tree ct, sq_ast_lnk_tree pt WHERE pt.linkid IN (SELECT DISTINCT linkid FROM sq_ast_lnk_tree WHERE linkid > '1' AND num_kids>0) AND ct.treeid LIKE pt.treeid || '%' AND LENGTH(ct.treeid) = (LENGTH(pt.treeid) + ".SQ_CONF_ASSET_TREE_SIZE.") GROUP BY pt.linkid, pt.treeid, pt.num_kids";
84  $results = MatrixDAL::executeSqlAssoc($sql);
85  foreach ($results as $result) {
86  if ($result['num_kids'] != $result['count']) {
87  $status = FALSE;
88  $count++;
89  $errors[] = 'Link #'.$result['linkid'].' has '.$result['num_kids'].' kids listed, but actually '.$result['count'].' kids were found';
90  }//end if
91  }//end foreach
92 
93  if (!$status && !empty($count)) {
94  $messages[] = 'There are '.$count.' invalid number of kids found on the system';
95  }//end if
96 
97  return $status;
98 
99  }//end test()
100 
101 }//end class
102 ?>