2014-09-19 20:46:30 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
final class PhabricatorConfigDatabaseIssueController
|
|
|
|
extends PhabricatorConfigDatabaseController {
|
|
|
|
|
2015-07-27 18:06:26 +02:00
|
|
|
public function handleRequest(AphrontRequest $request) {
|
|
|
|
$viewer = $request->getViewer();
|
2014-09-19 20:46:30 +02:00
|
|
|
|
|
|
|
$query = $this->buildSchemaQuery();
|
|
|
|
|
|
|
|
$actual = $query->loadActualSchema();
|
|
|
|
$expect = $query->loadExpectedSchema();
|
|
|
|
$comp = $query->buildComparisonSchema($expect, $actual);
|
|
|
|
|
|
|
|
$crumbs = $this->buildApplicationCrumbs();
|
|
|
|
$crumbs->addTextCrumb(pht('Database Issues'));
|
|
|
|
|
|
|
|
// Collect all open issues.
|
|
|
|
$issues = array();
|
|
|
|
foreach ($comp->getDatabases() as $database_name => $database) {
|
|
|
|
foreach ($database->getLocalIssues() as $issue) {
|
|
|
|
$issues[] = array(
|
|
|
|
$database_name,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
2014-10-07 15:01:04 +02:00
|
|
|
$issue,
|
|
|
|
);
|
2014-09-19 20:46:30 +02:00
|
|
|
}
|
|
|
|
foreach ($database->getTables() as $table_name => $table) {
|
|
|
|
foreach ($table->getLocalIssues() as $issue) {
|
|
|
|
$issues[] = array(
|
|
|
|
$database_name,
|
|
|
|
$table_name,
|
|
|
|
null,
|
|
|
|
null,
|
2014-10-07 15:01:04 +02:00
|
|
|
$issue,
|
|
|
|
);
|
2014-09-19 20:46:30 +02:00
|
|
|
}
|
|
|
|
foreach ($table->getColumns() as $column_name => $column) {
|
|
|
|
foreach ($column->getLocalIssues() as $issue) {
|
|
|
|
$issues[] = array(
|
|
|
|
$database_name,
|
|
|
|
$table_name,
|
|
|
|
'column',
|
|
|
|
$column_name,
|
2014-10-07 15:01:04 +02:00
|
|
|
$issue,
|
|
|
|
);
|
2014-09-19 20:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
foreach ($table->getKeys() as $key_name => $key) {
|
|
|
|
foreach ($key->getLocalIssues() as $issue) {
|
|
|
|
$issues[] = array(
|
|
|
|
$database_name,
|
|
|
|
$table_name,
|
|
|
|
'key',
|
|
|
|
$key_name,
|
2014-10-07 15:01:04 +02:00
|
|
|
$issue,
|
|
|
|
);
|
2014-09-19 20:46:30 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
// Sort all open issues so that the most severe issues appear first.
|
|
|
|
$order = array();
|
|
|
|
$counts = array();
|
|
|
|
foreach ($issues as $key => $issue) {
|
|
|
|
$const = $issue[4];
|
|
|
|
$status = PhabricatorConfigStorageSchema::getIssueStatus($const);
|
|
|
|
$severity = PhabricatorConfigStorageSchema::getStatusSeverity($status);
|
|
|
|
$order[$key] = sprintf(
|
|
|
|
'~%d~%s%s%s',
|
|
|
|
9 - $severity,
|
|
|
|
$issue[0],
|
|
|
|
$issue[1],
|
|
|
|
$issue[3]);
|
|
|
|
|
|
|
|
if (empty($counts[$status])) {
|
|
|
|
$counts[$status] = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
$counts[$status]++;
|
|
|
|
}
|
|
|
|
asort($order);
|
|
|
|
$issues = array_select_keys($issues, array_keys($order));
|
|
|
|
|
|
|
|
|
|
|
|
// Render the issues.
|
|
|
|
$rows = array();
|
|
|
|
foreach ($issues as $issue) {
|
|
|
|
$const = $issue[4];
|
|
|
|
|
2014-10-01 16:53:50 +02:00
|
|
|
$database_link = phutil_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
|
|
|
'href' => $this->getApplicationURI('/database/'.$issue[0].'/'),
|
|
|
|
),
|
|
|
|
$issue[0]);
|
|
|
|
|
2014-09-19 20:46:30 +02:00
|
|
|
$rows[] = array(
|
|
|
|
$this->renderIcon(
|
|
|
|
PhabricatorConfigStorageSchema::getIssueStatus($const)),
|
2014-10-01 16:53:50 +02:00
|
|
|
$database_link,
|
2014-09-19 20:46:30 +02:00
|
|
|
$issue[1],
|
|
|
|
$issue[2],
|
|
|
|
$issue[3],
|
|
|
|
PhabricatorConfigStorageSchema::getIssueDescription($const),
|
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = id(new AphrontTableView($rows))
|
|
|
|
->setHeaders(
|
|
|
|
array(
|
|
|
|
null,
|
|
|
|
pht('Database'),
|
|
|
|
pht('Table'),
|
|
|
|
pht('Type'),
|
|
|
|
pht('Column/Key'),
|
|
|
|
pht('Issue'),
|
|
|
|
))
|
|
|
|
->setColumnClasses(
|
|
|
|
array(
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
null,
|
|
|
|
'wide',
|
|
|
|
));
|
|
|
|
|
|
|
|
$errors = array();
|
|
|
|
|
|
|
|
if (isset($counts[PhabricatorConfigStorageSchema::STATUS_FAIL])) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'Detected %s serious issue(s) with the schemata.',
|
|
|
|
new PhutilNumber($counts[PhabricatorConfigStorageSchema::STATUS_FAIL]));
|
|
|
|
}
|
|
|
|
|
|
|
|
if (isset($counts[PhabricatorConfigStorageSchema::STATUS_WARN])) {
|
|
|
|
$errors[] = pht(
|
|
|
|
'Detected %s warning(s) with the schemata.',
|
|
|
|
new PhutilNumber($counts[PhabricatorConfigStorageSchema::STATUS_WARN]));
|
|
|
|
}
|
|
|
|
|
2014-10-01 16:37:14 +02:00
|
|
|
$title = pht('Database Issues');
|
|
|
|
|
2014-09-19 20:46:30 +02:00
|
|
|
$table_box = id(new PHUIObjectBoxView())
|
2014-11-01 16:25:05 +01:00
|
|
|
->setHeader($this->buildHeaderWithDocumentationLink($title))
|
2014-09-19 20:46:30 +02:00
|
|
|
->setFormErrors($errors)
|
[Redesign] Add Table, Collapse support to ObjectBox
Summary: Converts most all tables to be directly set via `setTable` to an ObjectBox. I think this path is more flexible design wise, as we can change the box based on children, and not just CSS. We also already do this with PropertyList, Forms, ObjectList, and Header. `setCollapsed` is added to ObjectBox to all children objects to bleed to the edges (like diffs).
Test Plan: I did a grep of `appendChild($table)` as well as searches for `PHUIObjectBoxView`, also with manual opening of hundreds of files. I'm sure I missed 5-8 places. If you just appendChild($table) nothing breaks, it just looks a little funny.
Reviewers: epriestley, btrahan
Subscribers: Korvin, epriestley
Differential Revision: https://secure.phabricator.com/D12955
2015-05-20 21:43:34 +02:00
|
|
|
->setTable($table);
|
2014-09-19 20:46:30 +02:00
|
|
|
|
|
|
|
$nav = $this->buildSideNavView();
|
|
|
|
$nav->selectFilter('dbissue/');
|
|
|
|
$nav->appendChild(
|
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$table_box,
|
|
|
|
));
|
|
|
|
|
|
|
|
return $this->buildApplicationPage(
|
|
|
|
$nav,
|
|
|
|
array(
|
2014-10-01 16:37:14 +02:00
|
|
|
'title' => $title,
|
2014-09-19 20:46:30 +02:00
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|