Path: blob/master/src/applications/chatlog/conduit/ChatLogRecordConduitAPIMethod.php
12241 views
<?php12final class ChatLogRecordConduitAPIMethod extends ChatLogConduitAPIMethod {34public function getAPIMethodName() {5return 'chatlog.record';6}78public function getMethodStatus() {9return self::METHOD_STATUS_UNSTABLE;10}1112public function getMethodDescription() {13return pht('Record chatter.');14}1516protected function defineParamTypes() {17return array(18'logs' => 'required list<dict>',19);20}2122protected function defineReturnType() {23return 'list<id>';24}2526protected function execute(ConduitAPIRequest $request) {27$logs = $request->getValue('logs');28if (!is_array($logs)) {29$logs = array();30}3132$template = new PhabricatorChatLogEvent();33$template->setLoggedByPHID($request->getUser()->getPHID());3435$objs = array();36foreach ($logs as $log) {37$channel_name = idx($log, 'channel');38$service_name = idx($log, 'serviceName');39$service_type = idx($log, 'serviceType');4041$channel = id(new PhabricatorChatLogChannel())->loadOneWhere(42'channelName = %s AND serviceName = %s AND serviceType = %s',43$channel_name,44$service_name,45$service_type);4647if (!$channel) {48$channel = id(new PhabricatorChatLogChannel())49->setChannelName($channel_name)50->setserviceName($service_name)51->setServiceType($service_type)52->setViewPolicy(PhabricatorPolicies::POLICY_USER)53->setEditPolicy(PhabricatorPolicies::POLICY_USER)54->save();55}5657$obj = clone $template;58$obj->setChannelID($channel->getID());59$obj->setType(idx($log, 'type'));60$obj->setAuthor(idx($log, 'author'));61$obj->setEpoch(idx($log, 'epoch'));62$obj->setMessage(idx($log, 'message'));63$obj->save();6465$objs[] = $obj;66}6768return array_values(mpull($objs, 'getID'));69}7071}727374