Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/chatlog/conduit/ChatLogRecordConduitAPIMethod.php
12241 views
1
<?php
2
3
final class ChatLogRecordConduitAPIMethod extends ChatLogConduitAPIMethod {
4
5
public function getAPIMethodName() {
6
return 'chatlog.record';
7
}
8
9
public function getMethodStatus() {
10
return self::METHOD_STATUS_UNSTABLE;
11
}
12
13
public function getMethodDescription() {
14
return pht('Record chatter.');
15
}
16
17
protected function defineParamTypes() {
18
return array(
19
'logs' => 'required list<dict>',
20
);
21
}
22
23
protected function defineReturnType() {
24
return 'list<id>';
25
}
26
27
protected function execute(ConduitAPIRequest $request) {
28
$logs = $request->getValue('logs');
29
if (!is_array($logs)) {
30
$logs = array();
31
}
32
33
$template = new PhabricatorChatLogEvent();
34
$template->setLoggedByPHID($request->getUser()->getPHID());
35
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');
41
42
$channel = id(new PhabricatorChatLogChannel())->loadOneWhere(
43
'channelName = %s AND serviceName = %s AND serviceType = %s',
44
$channel_name,
45
$service_name,
46
$service_type);
47
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();
56
}
57
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();
65
66
$objs[] = $obj;
67
}
68
69
return array_values(mpull($objs, 'getID'));
70
}
71
72
}
73
74