Пример #1
0
function renderDataIntegrityReport()
{
    global $nextorder;
    $violations = FALSE;
    // check 1: EntityLink rows referencing not-existent relatives
    // check 1.1: children
    $realms = array('location' => 'Location', 'object' => 'RackObject', 'rack' => 'Rack', 'row' => 'Row');
    $orphans = array();
    foreach ($realms as $realm => $table) {
        $result = usePreparedSelectBlade('SELECT EL.* FROM EntityLink EL ' . "LEFT JOIN {$table} ON EL.child_entity_id = {$table}.id " . "WHERE EL.child_entity_type = ? AND {$table}.id IS NULL", array($realm));
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        unset($result);
        $orphans = array_merge($orphans, $rows);
    }
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('EntityLink: Missing Children (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Parent</th><th>Child Type</th><th>Child ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            $realm_name = formatRealmName($orphan['parent_entity_type']);
            $parent = spotEntity($orphan['parent_entity_type'], $orphan['parent_entity_id']);
            echo "<tr class=row_{$order}>";
            echo "<td>{$realm_name}: {$parent['name']}</td>";
            echo "<td>{$orphan['child_entity_type']}</td>";
            echo "<td>{$orphan['child_entity_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 1.2: parents
    $orphans = array();
    foreach ($realms as $realm => $table) {
        $result = usePreparedSelectBlade('SELECT EL.* FROM EntityLink EL ' . "LEFT JOIN {$table} ON EL.parent_entity_id = {$table}.id " . "WHERE EL.parent_entity_type = ? AND {$table}.id IS NULL", array($realm));
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        unset($result);
        $orphans = array_merge($orphans, $rows);
    }
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('EntityLink: Missing Parents (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Child</th><th>Parent Type</th><th>Parent ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            $realm_name = formatRealmName($orphan['child_entity_type']);
            $child = spotEntity($orphan['child_entity_type'], $orphan['child_entity_id']);
            echo "<tr class=row_{$order}>";
            echo "<td>{$realm_name}: {$child['name']}</td>";
            echo "<td>{$orphan['parent_entity_type']}</td>";
            echo "<td>{$orphan['parent_entity_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 3: multiple tables referencing non-existent dictionary entries
    // check 3.1: AttributeMap
    $orphans = array();
    $result = usePreparedSelectBlade('SELECT AM.*, A.name AS attr_name, C.name AS chapter_name ' . 'FROM AttributeMap AM ' . 'LEFT JOIN Attribute A ON AM.attr_id = A.id ' . 'LEFT JOIN Chapter C ON AM.chapter_id = C.id ' . 'LEFT JOIN Dictionary D ON AM.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL');
    $orphans = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('AttributeMap: Invalid Mappings (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Attribute</th><th>Chapter</th><th>Object TypeID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['attr_name']}</td>";
            echo "<td>{$orphan['chapter_name']}</td>";
            echo "<td>{$orphan['objtype_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 3.2: Object
    $orphans = array();
    $result = usePreparedSelectBlade('SELECT O.* FROM Object O ' . 'LEFT JOIN Dictionary D ON O.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL');
    $orphans = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('Object: Invalid Types (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>ID</th><th>Name</th><th>Type ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['id']}</td>";
            echo "<td>{$orphan['name']}</td>";
            echo "<td>{$orphan['objtype_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 3.3: ObjectHistory
    $orphans = array();
    $result = usePreparedSelectBlade('SELECT OH.* FROM ObjectHistory OH ' . 'LEFT JOIN Dictionary D ON OH.objtype_id = D.dict_key ' . 'WHERE D.dict_key IS NULL');
    $orphans = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('ObjectHistory: Invalid Types (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>ID</th><th>Name</th><th>Type ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['id']}</td>";
            echo "<td>{$orphan['name']}</td>";
            echo "<td>{$orphan['objtype_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 3.4: ObjectParentCompat
    $orphans = array();
    $result = usePreparedSelectBlade('SELECT OPC.*, PD.dict_value AS parent_name, CD.dict_value AS child_name ' . 'FROM ObjectParentCompat OPC ' . 'LEFT JOIN Dictionary PD ON OPC.parent_objtype_id = PD.dict_key ' . 'LEFT JOIN Dictionary CD ON OPC.child_objtype_id = CD.dict_key ' . 'WHERE PD.dict_key IS NULL OR CD.dict_key IS NULL');
    $orphans = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('Object Container Compatibility rules: Invalid Parent or Child Type (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Parent</th><th>Parent Type ID</th><th>Child</th><th>Child Type ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['parent_name']}</td>";
            echo "<td>{$orphan['parent_objtype_id']}</td>";
            echo "<td>{$orphan['child_name']}</td>";
            echo "<td>{$orphan['child_objtype_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 4: relationships that violate ObjectParentCompat Rules
    $invalids = array();
    $result = usePreparedSelectBlade('SELECT CO.id AS child_id, CO.objtype_id AS child_type_id, CD.dict_value AS child_type, CO.name AS child_name, ' . 'PO.id AS parent_id, PO.objtype_id AS parent_type_id, PD.dict_value AS parent_type, PO.name AS parent_name ' . 'FROM Object CO ' . 'LEFT JOIN EntityLink EL ON CO.id = EL.child_entity_id ' . 'LEFT JOIN Object PO ON EL.parent_entity_id = PO.id ' . 'LEFT JOIN ObjectParentCompat OPC ON PO.objtype_id = OPC.parent_objtype_id ' . 'LEFT JOIN Dictionary PD ON PO.objtype_id = PD.dict_key ' . 'LEFT JOIN Dictionary CD ON CO.objtype_id = CD.dict_key ' . "WHERE EL.parent_entity_type = 'object' AND EL.child_entity_type = 'object' " . 'AND OPC.parent_objtype_id IS NULL');
    $invalids = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($invalids)) {
        $violations = TRUE;
        startPortlet('Objects: Violate Object Container Compatibility rules (' . count($invalids) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Contained Obj Name</th><th>Contained Obj Type</th><th>Container Obj Name</th><th>Container Obj Type</th></tr>\n";
        $order = 'odd';
        foreach ($invalids as $invalid) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$invalid['child_name']}</td>";
            echo "<td>{$invalid['child_type']}</td>";
            echo "<td>{$invalid['parent_name']}</td>";
            echo "<td>{$invalid['parent_type']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 5: Links that violate PortCompat Rules
    $invalids = array();
    $result = usePreparedSelectBlade('SELECT OA.id AS obja_id, OA.name AS obja_name, L.porta AS porta_id, PA.name AS porta_name, POIA.oif_name AS porta_type, ' . 'OB.id AS objb_id, OB.name AS objb_name, L.portb AS portb_id, PB.name AS portb_name, POIB.oif_name AS portb_type ' . 'FROM Link L ' . 'LEFT JOIN Port PA ON L.porta = PA.id ' . 'LEFT JOIN Object OA ON PA.object_id = OA.id ' . 'LEFT JOIN PortOuterInterface POIA ON PA.type = POIA.id ' . 'LEFT JOIN Port PB ON L.portb = PB.id ' . 'LEFT JOIN Object OB ON PB.object_id = OB.id ' . 'LEFT JOIN PortOuterInterface POIB ON PB.type = POIB.id ' . 'LEFT JOIN PortCompat PC on PA.type = PC.type1 AND PB.type = PC.type2 ' . 'WHERE PC.type1 IS NULL OR PC.type2 IS NULL');
    $invalids = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    if (count($invalids)) {
        $violations = TRUE;
        startPortlet('Port Links: Violate Port Compatibility Rules (' . count($invalids) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Object A</th><th>Port A Name</th><th>Port A Type</th><th>Object B</th><th>Port B Name</th><th>Port B Type</th></tr>\n";
        $order = 'odd';
        foreach ($invalids as $invalid) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$invalid['obja_name']}</td>";
            echo "<td>{$invalid['porta_name']}</td>";
            echo "<td>{$invalid['porta_type']}</td>";
            echo "<td>{$invalid['objb_name']}</td>";
            echo "<td>{$invalid['portb_name']}</td>";
            echo "<td>{$invalid['portb_type']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 6: TagStorage rows referencing non-existent parents
    $realms = array('file' => array('table' => 'File', 'column' => 'id'), 'ipv4net' => array('table' => 'IPv4Network', 'column' => 'id'), 'ipv4rspool' => array('table' => 'IPv4RSPool', 'column' => 'id'), 'ipv4vs' => array('table' => 'IPv4VS', 'column' => 'id'), 'ipv6net' => array('table' => 'IPv6Network', 'column' => 'id'), 'ipvs' => array('table' => 'VS', 'column' => 'id'), 'location' => array('table' => 'Location', 'column' => 'id'), 'object' => array('table' => 'RackObject', 'column' => 'id'), 'rack' => array('table' => 'Rack', 'column' => 'id'), 'user' => array('table' => 'UserAccount', 'column' => 'user_id'), 'vst' => array('table' => 'VLANSwitchTemplate', 'column' => 'id'));
    $orphans = array();
    foreach ($realms as $realm => $details) {
        $result = usePreparedSelectBlade('SELECT TS.*, TT.tag FROM TagStorage TS ' . 'LEFT JOIN TagTree TT ON TS.tag_id = TT.id ' . "LEFT JOIN {$details['table']} ON TS.entity_id = {$details['table']}.{$details['column']} " . "WHERE TS.entity_realm = ? AND {$details['table']}.{$details['column']} IS NULL", array($realm));
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        unset($result);
        $orphans = array_merge($orphans, $rows);
    }
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('TagStorage: Missing Parents (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Tag</th><th>Parent Type</th><th>Parent ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            $realm_name = formatRealmName($orphan['entity_realm']);
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['tag']}</td>";
            echo "<td>{$realm_name}</td>";
            echo "<td>{$orphan['entity_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 7: FileLink rows referencing non-existent parents
    // re-use the realms list from the TagStorage check, with a few mods
    unset($realms['file'], $realms['vst']);
    $realms['row'] = array('table' => 'Row', 'column' => 'id');
    $orphans = array();
    foreach ($realms as $realm => $details) {
        $result = usePreparedSelectBlade('SELECT FL.*, F.name FROM FileLink FL ' . 'LEFT JOIN File F ON FL.file_id = F.id ' . "LEFT JOIN {$details['table']} ON FL.entity_id = {$details['table']}.{$details['column']} " . "WHERE FL.entity_type = ? AND {$details['table']}.{$details['column']} IS NULL", array($realm));
        $rows = $result->fetchAll(PDO::FETCH_ASSOC);
        unset($result);
        $orphans = array_merge($orphans, $rows);
    }
    if (count($orphans)) {
        $violations = TRUE;
        startPortlet('FileLink: Missing Parents (' . count($orphans) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>File</th><th>Parent Type</th><th>Parent ID</th></tr>\n";
        $order = 'odd';
        foreach ($orphans as $orphan) {
            $realm_name = formatRealmName($orphan['entity_type']);
            echo "<tr class=row_{$order}>";
            echo "<td>{$orphan['name']}</td>";
            echo "<td>{$realm_name}</td>";
            echo "<td>{$orphan['entity_id']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 8: missing triggers
    $triggers = array('Link-before-insert' => 'Link', 'Link-before-update' => 'Link');
    $result = usePreparedSelectBlade('SELECT TRIGGER_NAME, EVENT_OBJECT_TABLE ' . 'FROM information_schema.TRIGGERS WHERE TRIGGER_SCHEMA = SCHEMA()');
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    $existing_triggers = $missing_triggers = array();
    foreach ($rows as $row) {
        $existing_triggers[$row['TRIGGER_NAME']] = $row['EVENT_OBJECT_TABLE'];
    }
    foreach ($triggers as $trigger => $table) {
        if (!array_key_exists($trigger, $existing_triggers)) {
            $missing_triggers[$trigger] = $table;
        }
    }
    if (count($missing_triggers)) {
        $violations = TRUE;
        startPortlet('Missing Triggers (' . count($missing_triggers) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Table</th><th>Trigger</th></tr>\n";
        $order = 'odd';
        foreach ($missing_triggers as $trigger => $table) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$table}</td>";
            echo "<td>{$trigger}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 9: missing foreign keys
    $fkeys = array('Atom-FK-molecule_id' => 'Atom', 'Atom-FK-rack_id' => 'Atom', 'AttributeMap-FK-chapter_id' => 'AttributeMap', 'AttributeMap-FK-attr_id' => 'AttributeMap', 'AttributeValue-FK-map' => 'AttributeValue', 'AttributeValue-FK-object' => 'AttributeValue', 'CachedPAV-FK-object-port' => 'CachedPAV', 'CachedPAV-FK-vlan_id' => 'CachedPAV', 'CachedPNV-FK-compound' => 'CachedPNV', 'CachedPVM-FK-object_id' => 'CachedPVM', 'CactiGraph-FK-server_id' => 'CactiGraph', 'CactiGraph-FK-server_id' => 'CactiGraph', 'Dictionary-FK-chapter_id' => 'Dictionary', 'FileLink-File_fkey' => 'FileLink', 'IPv4Allocation-FK-object_id' => 'IPv4Allocation', 'IPv4LB-FK-vs_id' => 'IPv4LB', 'IPv4LB-FK-object_id' => 'IPv4LB', 'IPv4LB-FK-rspool_id' => 'IPv4LB', 'IPv4NAT-FK-object_id' => 'IPv4NAT', 'IPv4RS-FK' => 'IPv4RS', 'IPv6Allocation-FK-object_id' => 'IPv6Allocation', 'Link-FK-a' => 'Link', 'Link-FK-b' => 'Link', 'MountOperation-FK-object_id' => 'MountOperation', 'MountOperation-FK-old_molecule_id' => 'MountOperation', 'MountOperation-FK-new_molecule_id' => 'MountOperation', 'MuninGraph-FK-server_id' => 'MuninGraph', 'MuninGraph-FK-server_id' => 'MuninGraph', 'ObjectHistory-FK-object_id' => 'ObjectHistory', 'ObjectLog-FK-object_id' => 'ObjectLog', 'Port-FK-iif-oif' => 'Port', 'Port-FK-object_id' => 'Port', 'PortAllowedVLAN-FK-object-port' => 'PortAllowedVLAN', 'PortAllowedVLAN-FK-vlan_id' => 'PortAllowedVLAN', 'PortCompat-FK-oif_id1' => 'PortCompat', 'PortCompat-FK-oif_id2' => 'PortCompat', 'PortInterfaceCompat-FK-iif_id' => 'PortInterfaceCompat', 'PortInterfaceCompat-FK-oif_id' => 'PortInterfaceCompat', 'PortLog_ibfk_1' => 'PortLog', 'PortNativeVLAN-FK-compound' => 'PortNativeVLAN', 'PortVLANMode-FK-object-port' => 'PortVLANMode', 'RackSpace-FK-rack_id' => 'RackSpace', 'RackSpace-FK-object_id' => 'RackSpace', 'TagStorage-FK-TagTree' => 'TagStorage', 'TagTree-K-parent_id' => 'TagTree', 'UserConfig-FK-varname' => 'UserConfig', 'VLANDescription-FK-domain_id' => 'VLANDescription', 'VLANDescription-FK-vlan_id' => 'VLANDescription', 'VLANIPv4-FK-compound' => 'VLANIPv4', 'VLANIPv4-FK-ipv4net_id' => 'VLANIPv4', 'VLANIPv6-FK-compound' => 'VLANIPv6', 'VLANIPv6-FK-ipv6net_id' => 'VLANIPv6', 'VLANSTRule-FK-vst_id' => 'VLANSTRule', 'VLANSwitch-FK-domain_id' => 'VLANSwitch', 'VLANSwitch-FK-object_id' => 'VLANSwitch', 'VLANSwitch-FK-template_id' => 'VLANSwitch', 'VSEnabledIPs-FK-object_id' => 'VSEnabledIPs', 'VSEnabledIPs-FK-rspool_id' => 'VSEnabledIPs', 'VSEnabledIPs-FK-vs_id-vip' => 'VSEnabledIPs', 'VSEnabledPorts-FK-object_id' => 'VSEnabledPorts', 'VSEnabledPorts-FK-rspool_id' => 'VSEnabledPorts', 'VSEnabledPorts-FK-vs_id-proto-vport' => 'VSEnabledPorts', 'VSIPs-vs_id' => 'VSIPs', 'VS-vs_id' => 'VSPorts');
    $result = usePreparedSelectBlade('SELECT CONSTRAINT_NAME, TABLE_NAME ' . 'FROM information_schema.TABLE_CONSTRAINTS ' . "WHERE CONSTRAINT_SCHEMA = SCHEMA() AND CONSTRAINT_TYPE = 'FOREIGN KEY'");
    $rows = $result->fetchAll(PDO::FETCH_ASSOC);
    unset($result);
    $existing_fkeys = $missing_fkeys = array();
    foreach ($rows as $row) {
        $existing_fkeys[$row['CONSTRAINT_NAME']] = $row['TABLE_NAME'];
    }
    foreach ($fkeys as $fkey => $table) {
        if (!array_key_exists($fkey, $existing_fkeys)) {
            $missing_fkeys[$fkey] = $table;
        }
    }
    if (count($missing_fkeys)) {
        $violations = TRUE;
        startPortlet('Missing Foreign Keys (' . count($missing_fkeys) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Table</th><th>Key</th></tr>\n";
        $order = 'odd';
        foreach ($missing_fkeys as $fkey => $table) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$table}</td>";
            echo "<td>{$fkey}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 10: circular references
    //     - all affected members of the tree are displayed
    //     - it would be beneficial to only display the offending records
    // check 10.1: locations
    $invalids = array();
    $locations = listCells('location');
    foreach ($locations as $location) {
        try {
            $children = getLocationChildrenList($location['id']);
        } catch (RackTablesError $e) {
            $invalids[] = $location;
        }
    }
    if (count($invalids)) {
        $violations = TRUE;
        startPortlet('Locations: Tree Contains Circular References (' . count($invalids) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Child ID</th><th>Child Location</th><th>Parent ID</th><th>Parent Location</th></tr>\n";
        $order = 'odd';
        foreach ($invalids as $invalid) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$invalid['id']}</td>";
            echo "<td>{$invalid['name']}</td>";
            echo "<td>{$invalid['parent_id']}</td>";
            echo "<td>{$invalid['parent_name']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 10.2: objects
    $invalids = array();
    $objects = listCells('object');
    foreach ($objects as $object) {
        try {
            $children = getObjectContentsList($object['id']);
        } catch (RackTablesError $e) {
            $invalids[] = $object;
        }
    }
    if (count($invalids)) {
        $violations = TRUE;
        startPortlet('Objects: Tree Contains Circular References (' . count($invalids) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Contained ID</th><th>Contained Object</th><th>Container ID</th><th>Container Object</th></tr>\n";
        $order = 'odd';
        foreach ($invalids as $invalid) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$invalid['id']}</td>";
            echo "<td>{$invalid['name']}</td>";
            echo "<td>{$invalid['container_id']}</td>";
            echo "<td>{$invalid['container_name']}</td>";
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    // check 10.3: tags
    $invalids = array();
    $tags = getTagList();
    foreach ($tags as $tag) {
        try {
            $children = getTagChildrenList($tag['id']);
        } catch (RackTablesError $e) {
            $invalids[] = $tag;
        }
    }
    if (count($invalids)) {
        $violations = TRUE;
        startPortlet('Tags: Tree Contains Circular References (' . count($invalids) . ')');
        echo "<table cellpadding=5 cellspacing=0 align=center class=cooltable>\n";
        echo "<tr><th>Child ID</th><th>Child Tag</th><th>Parent ID</th><th>Parent Tag</th></tr>\n";
        $order = 'odd';
        foreach ($invalids as $invalid) {
            echo "<tr class=row_{$order}>";
            echo "<td>{$invalid['id']}</td>";
            echo "<td>{$invalid['tag']}</td>";
            echo "<td>{$invalid['parent_id']}</td>";
            printf('<td>%s</td>', $tags[$invalid['parent_id']]['tag']);
            echo "</tr>\n";
            $order = $nextorder[$order];
        }
        echo "</table>\n";
        finishPortLet();
    }
    if (!$violations) {
        echo '<h2>No integrity violations found</h2>';
    }
}
Пример #2
0
 public function testGetLocationChildrenList()
 {
     $children = getLocationChildrenList(self::$first_location_id);
     $this->assertCount(self::$num_children, $children);
 }