Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / chatlog / conduit / ChatLogRecordConduitAPIMethod.php
blobfe972222ae6ae19ffd537db690bc0017177fcca4
1 <?php
3 final class ChatLogRecordConduitAPIMethod extends ChatLogConduitAPIMethod {
5 public function getAPIMethodName() {
6 return 'chatlog.record';
9 public function getMethodStatus() {
10 return self::METHOD_STATUS_UNSTABLE;
13 public function getMethodDescription() {
14 return pht('Record chatter.');
17 protected function defineParamTypes() {
18 return array(
19 'logs' => 'required list<dict>',
23 protected function defineReturnType() {
24 return 'list<id>';
27 protected function execute(ConduitAPIRequest $request) {
28 $logs = $request->getValue('logs');
29 if (!is_array($logs)) {
30 $logs = array();
33 $template = new PhabricatorChatLogEvent();
34 $template->setLoggedByPHID($request->getUser()->getPHID());
36 $objs = array();
37 foreach ($logs as $log) {
38 $channel_name = idx($log, 'channel');
39 $service_name = idx($log, 'serviceName');
40 $service_type = idx($log, 'serviceType');
42 $channel = id(new PhabricatorChatLogChannel())->loadOneWhere(
43 'channelName = %s AND serviceName = %s AND serviceType = %s',
44 $channel_name,
45 $service_name,
46 $service_type);
48 if (!$channel) {
49 $channel = id(new PhabricatorChatLogChannel())
50 ->setChannelName($channel_name)
51 ->setserviceName($service_name)
52 ->setServiceType($service_type)
53 ->setViewPolicy(PhabricatorPolicies::POLICY_USER)
54 ->setEditPolicy(PhabricatorPolicies::POLICY_USER)
55 ->save();
58 $obj = clone $template;
59 $obj->setChannelID($channel->getID());
60 $obj->setType(idx($log, 'type'));
61 $obj->setAuthor(idx($log, 'author'));
62 $obj->setEpoch(idx($log, 'epoch'));
63 $obj->setMessage(idx($log, 'message'));
64 $obj->save();
66 $objs[] = $obj;
69 return array_values(mpull($objs, 'getID'));