Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 3
CRAP
0.00% covered (danger)
0.00%
0 / 1
CargoTableDiagram
0.00% covered (danger)
0.00%
0 / 32
0.00% covered (danger)
0.00%
0 / 3
132
0.00% covered (danger)
0.00%
0 / 1
 __construct
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
 execute
0.00% covered (danger)
0.00%
0 / 30
0.00% covered (danger)
0.00%
0 / 1
90
 getGroupName
0.00% covered (danger)
0.00%
0 / 1
0.00% covered (danger)
0.00%
0 / 1
2
1<?php
2/**
3 * Displays a sort of "database diagram" showing the relationships between
4 * Cargo tables.
5 *
6 * @author Yaron Koren
7 * @ingroup Cargo
8 */
9
10class CargoTableDiagram extends IncludableSpecialPage {
11    public function __construct() {
12        parent::__construct( 'CargoTableDiagram' );
13    }
14
15    public function execute( $subpage = null ) {
16        $out = $this->getOutput();
17
18        $this->setHeaders();
19
20        $out->addModules( 'ext.cargo.diagram' );
21
22        $tableNames = CargoUtils::getTables();
23        $userDefinedTables = [];
24        foreach ( $tableNames as $tableName ) {
25            if ( substr( $tableName, 0, 1 ) !== '_' ) {
26                $userDefinedTables[] = $tableName;
27            }
28        }
29
30        // Create a minimal array of schema data, since we only need
31        // a small fraction of the overall schema information.
32        $tableSchemas = CargoUtils::getTableSchemas( $userDefinedTables );
33        $tableSchemaData = [];
34        foreach ( $tableSchemas as $tableName => $tableSchema ) {
35            $curTableSchemaData = [];
36            foreach ( $tableSchema->mFieldDescriptions as $fieldName => $fieldDesc ) {
37                $typeString = $fieldDesc->mType;
38                if ( $fieldDesc->mIsList ) {
39                    // @todo - i18n this?
40                    $typeString = "List of $typeString";
41                }
42                $curTableSchemaData[$fieldName] = [
43                    'type' => $typeString
44                ];
45            }
46            $tableSchemaData[$tableName] = $curTableSchemaData;
47        }
48        $tableSchemasJSON = json_encode( $tableSchemaData );
49
50        $allParentTables = [];
51        foreach ( $userDefinedTables as $tableName ) {
52            $parentTables = CargoUtils::getParentTables( $tableName );
53            if ( is_array( $parentTables ) && count( $parentTables ) > 0 ) {
54                $allParentTables[$tableName] = $parentTables;
55            }
56        }
57        $allParentTablesJSON = json_encode( $allParentTables );
58
59        $text = "<div class=\"cargo-table-diagram\" data-table-schemas='$tableSchemasJSON' data-parent-tables='$allParentTablesJSON'><svg class=\"cargo-table-svg\"></svg></div>";
60
61        $out->addHTML( $text );
62
63        return true;
64    }
65
66    protected function getGroupName() {
67        return 'cargo';
68    }
69}