count-null-parent-ids-w-duped-identifiers.php

Count information objects missing parent IDs that have a non-unique identifier - Dan Gillean, 03/27/2018 02:50 PM

Download (1.27 KB)

 
1
<?php
2

    
3
$criteria = new Criteria;
4
$criteria->add(QubitInformationObject::PARENT_ID, null, Criteria::ISNULL);
5
$criteria->add(QubitInformationObject::ID, QubitInformationObject::ROOT_ID, Criteria::NOT_EQUAL);
6

    
7
$result = QubitInformationObject::get($criteria);
8

    
9
print sprintf("Found %d information objects with null IDs\n", count($result));
10

    
11
print "Checking identifiers...\n";
12

    
13
foreach($result as $io)
14
{
15
  $status = 'OK';
16
  $dupes = array();
17

    
18
  if (empty($io->identifier))
19
  {
20
    $status = 'No identifier';
21
  }
22
  else
23
  {
24
    $nonNullParents = 0;
25
    $nullParents = 0;
26

    
27
    $criteria = new Criteria;
28
    $criteria->add(QubitInformationObject::IDENTIFIER, $io->identifier);
29
    $criteria->add(QubitInformationObject::ID, $io->id, Criteria::NOT_EQUAL);
30

    
31
    $result2 = QubitInformationObject::get($criteria);
32

    
33
    // Amalgamate duplicate properties and summarize status
34
    if (count($result2))
35
    {
36
      foreach($result2 as $io2)
37
      {
38
        array_push($dupes, $io2);
39
      }
40

    
41
      $status = sprintf('Duplicate identifier "%s"', $io->identifier);
42
    }
43
  }
44

    
45
  print sprintf("%s: %s (%d)\n", $status, $io->slug, $io->id);
46
  foreach($dupes as $dupe)
47
  {
48
    print sprintf(" * %s (%d: parent ID %d)\n", $dupe->slug, $dupe->id, $dupe->parentId);
49
  }
50

    
51
  if (count($dupes))
52
  {
53
    print "\n";
54
  }
55
}