2011-03-08 00:13:36 +01:00
|
|
|
<?php
|
|
|
|
|
|
|
|
/*
|
|
|
|
* Copyright 2011 Facebook, Inc.
|
|
|
|
*
|
|
|
|
* Licensed under the Apache License, Version 2.0 (the "License");
|
|
|
|
* you may not use this file except in compliance with the License.
|
|
|
|
* You may obtain a copy of the License at
|
|
|
|
*
|
|
|
|
* http://www.apache.org/licenses/LICENSE-2.0
|
|
|
|
*
|
|
|
|
* Unless required by applicable law or agreed to in writing, software
|
|
|
|
* distributed under the License is distributed on an "AS IS" BASIS,
|
|
|
|
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
|
|
|
* See the License for the specific language governing permissions and
|
|
|
|
* limitations under the License.
|
|
|
|
*/
|
|
|
|
|
|
|
|
class DiffusionHomeController extends DiffusionController {
|
|
|
|
|
|
|
|
public function processRequest() {
|
|
|
|
|
|
|
|
// TODO: Restore "shortcuts" feature.
|
|
|
|
|
|
|
|
$repositories = id(new PhabricatorRepository())->loadAll();
|
|
|
|
|
|
|
|
$commit = new PhabricatorRepositoryCommit();
|
|
|
|
$conn_r = $commit->establishConnection('r');
|
|
|
|
|
2011-03-13 07:51:40 +01:00
|
|
|
// TODO: These queries are pretty bogus.
|
|
|
|
|
|
|
|
$commits = array();
|
|
|
|
$commit_counts = array();
|
|
|
|
|
|
|
|
$max_epoch = queryfx_all(
|
|
|
|
$commit->establishConnection('r'),
|
|
|
|
'SELECT repositoryID, MAX(epoch) maxEpoch FROM %T GROUP BY repositoryID',
|
2011-03-08 00:13:36 +01:00
|
|
|
$commit->getTableName());
|
2011-03-13 07:51:40 +01:00
|
|
|
|
|
|
|
if ($max_epoch) {
|
|
|
|
$sql = array();
|
|
|
|
foreach ($max_epoch as $head) {
|
|
|
|
$sql[] = '('.(int)$head['repositoryID'].', '.(int)$head['maxEpoch'].')';
|
|
|
|
}
|
|
|
|
|
|
|
|
// NOTE: It's possible we'll pull multiple commits for some repository
|
|
|
|
// here but it reduces query cost around 3x to unique them in PHP rather
|
|
|
|
// than apply GROUP BY in MySQL.
|
|
|
|
$commits = $commit->loadAllWhere(
|
|
|
|
'(repositoryID, epoch) IN (%Q)',
|
|
|
|
implode(', ', $sql));
|
|
|
|
$commits = mpull($commits, null, 'getRepositoryID');
|
|
|
|
|
|
|
|
$commit_counts = queryfx_all(
|
|
|
|
$conn_r,
|
|
|
|
'SELECT repositoryID, count(*) N FROM %T
|
|
|
|
GROUP BY repositoryID',
|
|
|
|
$commit->getTableName());
|
|
|
|
$commit_counts = ipull($commit_counts, 'N', 'repositoryID');
|
|
|
|
}
|
2011-03-08 00:13:36 +01:00
|
|
|
|
|
|
|
$rows = array();
|
|
|
|
foreach ($repositories as $repository) {
|
2011-03-13 07:51:40 +01:00
|
|
|
$id = $repository->getID();
|
|
|
|
$commit = idx($commits, $id);
|
|
|
|
$date = null;
|
|
|
|
$time = null;
|
|
|
|
if ($commit) {
|
|
|
|
$date = date('M j, Y', $commit->getEpoch());
|
|
|
|
$time = date('g:i A', $commit->getEpoch());
|
|
|
|
}
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
$rows[] = array(
|
|
|
|
phutil_render_tag(
|
|
|
|
'a',
|
|
|
|
array(
|
2011-03-13 01:17:34 +01:00
|
|
|
'href' => '/diffusion/'.$repository->getCallsign().'/',
|
2011-03-08 00:13:36 +01:00
|
|
|
),
|
|
|
|
phutil_escape_html($repository->getName())),
|
|
|
|
$repository->getVersionControlSystem(),
|
2011-03-13 07:51:40 +01:00
|
|
|
idx($commit_counts, $id, 0),
|
2011-03-08 00:13:36 +01:00
|
|
|
$commit
|
2011-03-13 07:51:40 +01:00
|
|
|
? DiffusionView::linkCommit(
|
|
|
|
$repository,
|
|
|
|
$commit->getCommitIdentifier())
|
2011-03-08 00:13:36 +01:00
|
|
|
: null,
|
2011-03-13 07:51:40 +01:00
|
|
|
$date,
|
|
|
|
$time,
|
2011-03-08 00:13:36 +01:00
|
|
|
);
|
|
|
|
}
|
|
|
|
|
|
|
|
$table = new AphrontTableView($rows);
|
|
|
|
$table->setHeaders(
|
|
|
|
array(
|
|
|
|
'Repository',
|
|
|
|
'VCS',
|
|
|
|
'Size',
|
|
|
|
'Last',
|
2011-03-13 07:51:40 +01:00
|
|
|
'Date',
|
|
|
|
'Time',
|
2011-03-08 00:13:36 +01:00
|
|
|
));
|
|
|
|
$table->setColumnClasses(
|
|
|
|
array(
|
|
|
|
'wide',
|
2011-03-13 07:51:40 +01:00
|
|
|
'',
|
|
|
|
'n',
|
|
|
|
'n',
|
|
|
|
'',
|
|
|
|
'right',
|
2011-03-08 00:13:36 +01:00
|
|
|
));
|
|
|
|
|
|
|
|
$panel = new AphrontPanelView();
|
|
|
|
$panel->setHeader('Browse Repositories');
|
|
|
|
$panel->appendChild($table);
|
|
|
|
|
2011-03-13 01:17:34 +01:00
|
|
|
$crumbs = $this->buildCrumbs();
|
|
|
|
|
2011-03-08 00:13:36 +01:00
|
|
|
return $this->buildStandardPageResponse(
|
2011-03-13 01:17:34 +01:00
|
|
|
array(
|
|
|
|
$crumbs,
|
|
|
|
$panel,
|
|
|
|
),
|
2011-03-08 00:13:36 +01:00
|
|
|
array(
|
|
|
|
'title' => 'Diffusion',
|
|
|
|
));
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|