count-null-parent-ids.php

Return a count of information objects with no parent ID - Dan Gillean, 03/27/2018 02:50 PM

Download (729 Bytes)

 
1
<?php
2

    
3
print "Counting...\n";
4

    
5
function recursiveChildCount($parentId = null)
6
{
7
  $criteria = new Criteria;
8

    
9
  if ($parentId === null)
10
  {
11
    $criteria->add(QubitInformationObject::PARENT_ID, null, Criteria::ISNULL);
12
  }
13
  else
14
  {
15
    $criteria->add(QubitInformationObject::PARENT_ID, $parentId);
16
  }
17

    
18
  $result = QubitInformationObject::get($criteria);
19

    
20
  $count = count($result);
21
  foreach($result as $io)
22
  {
23
    if ($io->id != QubitInformationObject::ROOT_ID)
24
    {
25
      $count += recursiveChildCount($io->id);
26
    }
27
  }
28

    
29
  return $count;
30
}
31

    
32
$count = recursiveChildCount();
33

    
34
// Subtract the root information object from the count
35
print "Counted ". ($count - 1) ." information objects with NULL parents and descendants.\n";