1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2025-01-04 11:51:02 +01:00

Moving code off channel

Summary: Deleted code which used channel. Created PhabricatorChatLogChannelQuery.php

Test Plan: By manually checking in the chatlog application.

Reviewers: epriestley

CC: aran, Korvin

Differential Revision: https://secure.phabricator.com/D5010
This commit is contained in:
Afaque Hussain 2013-02-22 06:59:17 -08:00 committed by epriestley
parent 53f527f71f
commit 3b2aed16c9
9 changed files with 77 additions and 38 deletions

View file

@ -754,6 +754,7 @@ phutil_register_library_map(array(
'PhabricatorChatLogChannel' => 'applications/chatlog/storage/PhabricatorChatLogChannel.php', 'PhabricatorChatLogChannel' => 'applications/chatlog/storage/PhabricatorChatLogChannel.php',
'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/PhabricatorChatLogChannelListController.php', 'PhabricatorChatLogChannelListController' => 'applications/chatlog/controller/PhabricatorChatLogChannelListController.php',
'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/PhabricatorChatLogChannelLogController.php', 'PhabricatorChatLogChannelLogController' => 'applications/chatlog/controller/PhabricatorChatLogChannelLogController.php',
'PhabricatorChatLogChannelQuery' => 'applications/chatlog/PhabricatorChatLogChannelQuery.php',
'PhabricatorChatLogConstants' => 'applications/chatlog/constants/PhabricatorChatLogConstants.php', 'PhabricatorChatLogConstants' => 'applications/chatlog/constants/PhabricatorChatLogConstants.php',
'PhabricatorChatLogController' => 'applications/chatlog/controller/PhabricatorChatLogController.php', 'PhabricatorChatLogController' => 'applications/chatlog/controller/PhabricatorChatLogController.php',
'PhabricatorChatLogDAO' => 'applications/chatlog/storage/PhabricatorChatLogDAO.php', 'PhabricatorChatLogDAO' => 'applications/chatlog/storage/PhabricatorChatLogDAO.php',
@ -2253,6 +2254,7 @@ phutil_register_library_map(array(
), ),
'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelListController' => 'PhabricatorChatLogController',
'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController', 'PhabricatorChatLogChannelLogController' => 'PhabricatorChatLogController',
'PhabricatorChatLogChannelQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
'PhabricatorChatLogController' => 'PhabricatorController', 'PhabricatorChatLogController' => 'PhabricatorController',
'PhabricatorChatLogDAO' => 'PhabricatorLiskDAO', 'PhabricatorChatLogDAO' => 'PhabricatorLiskDAO',
'PhabricatorChatLogEvent' => 'PhabricatorChatLogEvent' =>

View file

@ -95,13 +95,6 @@ class AphrontDefaultApplicationConfiguration
'keyboardshortcut/' => 'PhabricatorHelpKeyboardShortcutController', 'keyboardshortcut/' => 'PhabricatorHelpKeyboardShortcutController',
), ),
'/chatlog/' => array(
'' =>
'PhabricatorChatLogChannelListController',
'channel/(?P<channel>[^/]+)/' =>
'PhabricatorChatLogChannelLogController',
),
'/notification/' => array( '/notification/' => array(
'(?:(?P<filter>all|unread)/)?' '(?:(?P<filter>all|unread)/)?'
=> 'PhabricatorNotificationListController', => 'PhabricatorNotificationListController',

View file

@ -0,0 +1,44 @@
<?php
final class PhabricatorChatLogChannelQuery
extends PhabricatorCursorPagedPolicyAwareQuery {
private $channels;
public function withChannelNames(array $channels) {
$this->channels = $channels;
return $this;
}
public function loadPage() {
$table = new PhabricatorChatLogChannel();
$conn_r = $table->establishConnection('r');
$data = queryfx_all(
$conn_r,
'SELECT * FROM %T c %Q %Q %Q',
$table->getTableName(),
$this->buildWhereClause($conn_r),
$this->buildOrderClause($conn_r),
$this->buildLimitClause($conn_r));
$logs = $table->loadAllFromArray($data);
return $logs;
}
private function buildWhereClause($conn_r) {
$where = array();
$where[] = $this->buildPagingClause($conn_r);
if ($this->channels) {
$where[] = qsprintf(
$conn_r,
'channelName IN (%Ls)',
$this->channels);
}
return $this->formatWhereClause($where);
}
}

View file

@ -3,11 +3,11 @@
final class PhabricatorChatLogQuery final class PhabricatorChatLogQuery
extends PhabricatorCursorPagedPolicyAwareQuery { extends PhabricatorCursorPagedPolicyAwareQuery {
private $channels; private $channelIDs;
private $maximumEpoch; private $maximumEpoch;
public function withChannels(array $channels) { public function withChannelIDs(array $channel_ids) {
$this->channels = $channels; $this->channelIDs = $channel_ids;
return $this; return $this;
} }
@ -45,11 +45,11 @@ final class PhabricatorChatLogQuery
$this->maximumEpoch); $this->maximumEpoch);
} }
if ($this->channels) { if ($this->channelIDs) {
$where[] = qsprintf( $where[] = qsprintf(
$conn_r, $conn_r,
'channel IN (%Ls)', 'channelID IN (%Ld)',
$this->channels); $this->channelIDs);
} }
return $this->formatWhereClause($where); return $this->formatWhereClause($where);

View file

@ -30,6 +30,8 @@ final class PhabricatorApplicationChatLog extends PhabricatorApplication {
return array( return array(
'/chatlog/' => array( '/chatlog/' => array(
'' => 'PhabricatorChatLogChannelListController', '' => 'PhabricatorChatLogChannelListController',
'channel/(?P<channelID>[^/]+)/' =>
'PhabricatorChatLogChannelLogController',
), ),
); );

View file

@ -33,9 +33,9 @@ final class ConduitAPI_chatlog_query_Method
$query = new PhabricatorChatLogQuery(); $query = new PhabricatorChatLogQuery();
$channels = $request->getValue('channels'); $channel_ids = $request->getValue('channelIDs');
if ($channels) { if ($channel_ids) {
$query->withChannels($channels); $query->withChannelIDs($channel_ids);
} }
$limit = $request->getValue('limit'); $limit = $request->getValue('limit');
@ -49,7 +49,7 @@ final class ConduitAPI_chatlog_query_Method
$results = array(); $results = array();
foreach ($logs as $log) { foreach ($logs as $log) {
$results[] = array( $results[] = array(
'channel' => $log->getChannel(), 'channelID' => $log->getChannelID(),
'epoch' => $log->getEpoch(), 'epoch' => $log->getEpoch(),
'author' => $log->getAuthor(), 'author' => $log->getAuthor(),
'type' => $log->getType(), 'type' => $log->getType(),

View file

@ -61,7 +61,6 @@ final class ConduitAPI_chatlog_record_Method
} }
$obj = clone $template; $obj = clone $template;
$obj->setChannel($channel_name);
$obj->setChannelID($channel->getID()); $obj->setChannelID($channel->getID());
$obj->setType(idx($log, 'type')); $obj->setType(idx($log, 'type'));
$obj->setAuthor(idx($log, 'author')); $obj->setAuthor(idx($log, 'author'));

View file

@ -4,24 +4,23 @@ final class PhabricatorChatLogChannelListController
extends PhabricatorChatLogController { extends PhabricatorChatLogController {
public function processRequest() { public function processRequest() {
$request = $this->getRequest();
$user = $request->getUser();
$table = new PhabricatorChatLogEvent(); $channels = id(new PhabricatorChatLogChannelQuery())
->setViewer($user)
$channels = queryfx_all( ->execute();
$table->establishConnection('r'),
'SELECT DISTINCT channel FROM %T',
$table->getTableName());
$rows = array(); $rows = array();
foreach ($channels as $channel) { foreach ($channels as $channel) {
$name = $channel['channel'];
$rows[] = array( $rows[] = array(
phutil_tag( phutil_tag(
'a', 'a',
array( array(
'href' => '/chatlog/channel/'.phutil_escape_uri($name).'/', 'href' =>
'/chatlog/channel/'.$channel->getID().'/',
), ),
$name)); $channel->getChannelName()));
} }
$table = new AphrontTableView($rows); $table = new AphrontTableView($rows);

View file

@ -3,10 +3,10 @@
final class PhabricatorChatLogChannelLogController final class PhabricatorChatLogChannelLogController
extends PhabricatorChatLogController { extends PhabricatorChatLogController {
private $channel; private $channelID;
public function willProcessRequest(array $data) { public function willProcessRequest(array $data) {
$this->channel = $data['channel']; $this->channelID = $data['channelID'];
} }
public function processRequest() { public function processRequest() {
@ -22,7 +22,7 @@ final class PhabricatorChatLogChannelLogController
$query = id(new PhabricatorChatLogQuery()) $query = id(new PhabricatorChatLogQuery())
->setViewer($user) ->setViewer($user)
->withChannels(array($this->channel)); ->withChannelIDs(array($this->channelID));
list($after, $before, $map) = $this->getPagingParameters($request, $query); list($after, $before, $map) = $this->getPagingParameters($request, $query);
@ -140,9 +140,9 @@ final class PhabricatorChatLogChannelLogController
array( array(
hsprintf( hsprintf(
'<div class="phabricator-chat-log-panel">%s<br />%s%s</div>', '<div class="phabricator-chat-log-panel">%s<br />%s%s</div>',
$form, $form->render(),
phutil_tag('table', array('class' => 'phabricator-chat-log'), $out), phutil_tag('table', array('class' => 'phabricator-chat-log'), $out),
$pager), $pager->render()),
), ),
array( array(
'title' => 'Channel Log', 'title' => 'Channel Log',