protected function execute(ConduitAPIRequest $request)
 {
     $logs = $request->getValue('logs');
     if (!is_array($logs)) {
         $logs = array();
     }
     $template = new PhabricatorChatLogEvent();
     $template->setLoggedByPHID($request->getUser()->getPHID());
     $objs = array();
     foreach ($logs as $log) {
         $channel_name = idx($log, 'channel');
         $service_name = idx($log, 'serviceName');
         $service_type = idx($log, 'serviceType');
         $channel = id(new PhabricatorChatLogChannel())->loadOneWhere('channelName = %s AND serviceName = %s AND serviceType = %s', $channel_name, $service_name, $service_type);
         if (!$channel) {
             $channel = id(new PhabricatorChatLogChannel())->setChannelName($channel_name)->setserviceName($service_name)->setServiceType($service_type)->setViewPolicy(PhabricatorPolicies::POLICY_USER)->setEditPolicy(PhabricatorPolicies::POLICY_USER)->save();
         }
         $obj = clone $template;
         $obj->setChannelID($channel->getID());
         $obj->setType(idx($log, 'type'));
         $obj->setAuthor(idx($log, 'author'));
         $obj->setEpoch(idx($log, 'epoch'));
         $obj->setMessage(idx($log, 'message'));
         $obj->save();
         $objs[] = $obj;
     }
     return array_values(mpull($objs, 'getID'));
 }
 public function loadPage()
 {
     $table = new PhabricatorChatLogEvent();
     $conn_r = $table->establishConnection('r');
     $data = queryfx_all($conn_r, 'SELECT * FROM %T e %Q %Q %Q', $table->getTableName(), $this->buildWhereClause($conn_r), $this->buildOrderClause($conn_r), $this->buildLimitClause($conn_r));
     $logs = $table->loadAllFromArray($data);
     return $this->processResults($logs);
 }
 public function execute()
 {
     $table = new PhabricatorChatLogEvent();
     $conn_r = $table->establishConnection('r');
     $where_clause = $this->buildWhereClause($conn_r);
     $limit_clause = $this->buildLimitClause($conn_r);
     $data = queryfx_all($conn_r, 'SELECT * FROM %T e %Q ORDER BY epoch ASC %Q', $table->getTableName(), $where_clause, $limit_clause);
     $logs = $table->loadAllFromArray($data);
     return $logs;
 }
 public function processRequest()
 {
     $table = new PhabricatorChatLogEvent();
     $channels = queryfx_all($table->establishConnection('r'), 'SELECT DISTINCT channel FROM %T', $table->getTableName());
     $rows = array();
     foreach ($channels as $channel) {
         $name = $channel['channel'];
         $rows[] = array(phutil_render_tag('a', array('href' => '/chatlog/channel/' . phutil_escape_uri($name) . '/'), phutil_escape_html($name)));
     }
     $table = new AphrontTableView($rows);
     $table->setHeaders(array('Channel'));
     $table->setColumnClasses(array('pri wide'));
     $panel = new AphrontPanelView();
     $panel->appendChild($table);
     return $this->buildStandardPageResponse($panel, array('title' => 'Channel List'));
 }
 protected function execute(ConduitAPIRequest $request)
 {
     $logs = $request->getValue('logs');
     if (!is_array($logs)) {
         $logs = array();
     }
     $template = new PhabricatorChatLogEvent();
     $template->setLoggedByPHID($request->getUser()->getPHID());
     $objs = array();
     foreach ($logs as $log) {
         $obj = clone $template;
         $obj->setChannel(idx($log, 'channel'));
         $obj->setType(idx($log, 'type'));
         $obj->setAuthor(idx($log, 'author'));
         $obj->setEpoch(idx($log, 'epoch'));
         $obj->setMessage(idx($log, 'message'));
         $obj->save();
         $objs[] = $obj;
     }
     return array_values(mpull($objs, 'getID'));
 }
<?php

echo pht('Updating channel IDs of previous chatlog events...') . "\n";
$event_table = new PhabricatorChatLogEvent();
$channel_table = new PhabricatorChatLogChannel();
$event_table->openTransaction();
$channel_table->openTransaction();
$event_table->beginReadLocking();
$channel_table->beginReadLocking();
$events = new LiskMigrationIterator($event_table);
$conn_w = $channel_table->establishConnection('w');
foreach ($events as $event) {
    if ($event->getChannelID()) {
        continue;
    }
    $event_row = queryfx_one($conn_w, 'SELECT channel FROM %T WHERE id = %d', $event->getTableName(), $event->getID());
    $event_channel = $event_row['channel'];
    $matched = queryfx_one($conn_w, 'SELECT * FROM %T WHERE
      channelName = %s AND serviceName = %s AND serviceType = %s', $channel_table->getTableName(), $event_channel, '', '');
    if (!$matched) {
        $matched = id(new PhabricatorChatLogChannel())->setChannelName($event_channel)->setServiceType('')->setServiceName('')->setViewPolicy(PhabricatorPolicies::POLICY_USER)->setEditPolicy(PhabricatorPolicies::POLICY_USER)->save();
        $matched_id = $matched->getID();
    } else {
        $matched_id = $matched['id'];
    }
    queryfx($event->establishConnection('w'), 'UPDATE %T SET channelID = %d WHERE id = %d', $event->getTableName(), $matched_id, $event->getID());
}
$event_table->endReadLocking();
$channel_table->endReadLocking();
$event_table->saveTransaction();
$channel_table->saveTransaction();