Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
freebsd
GitHub Repository: freebsd/phabricator
Path: blob/master/src/applications/conpherence/conduit/ConpherenceUpdateThreadConduitAPIMethod.php
12256 views
1
<?php
2
3
final class ConpherenceUpdateThreadConduitAPIMethod
4
extends ConpherenceConduitAPIMethod {
5
6
public function getAPIMethodName() {
7
return 'conpherence.updatethread';
8
}
9
10
public function getMethodDescription() {
11
return pht('Update an existing conpherence room.');
12
}
13
14
public function getMethodStatus() {
15
return self::METHOD_STATUS_FROZEN;
16
}
17
18
public function getMethodStatusDescription() {
19
return pht(
20
'This method is frozen and will eventually be deprecated. New code '.
21
'should use "conpherence.edit" instead.');
22
}
23
24
protected function defineParamTypes() {
25
return array(
26
'id' => 'optional int',
27
'phid' => 'optional phid',
28
'title' => 'optional string',
29
'message' => 'optional string',
30
'addParticipantPHIDs' => 'optional list<phids>',
31
'removeParticipantPHID' => 'optional phid',
32
);
33
}
34
35
protected function defineReturnType() {
36
return 'bool';
37
}
38
39
protected function defineErrorTypes() {
40
return array(
41
'ERR_USAGE_NO_ROOM_ID' => pht(
42
'You must specify a room ID or room PHID to query transactions from.'),
43
'ERR_USAGE_ROOM_NOT_FOUND' => pht(
44
'Room does not exist or logged in user can not see it.'),
45
'ERR_USAGE_ONLY_SELF_REMOVE' => pht(
46
'Only a user can remove themselves from a room.'),
47
'ERR_USAGE_NO_UPDATES' => pht(
48
'You must specify data that actually updates the Conpherence.'),
49
);
50
}
51
52
protected function execute(ConduitAPIRequest $request) {
53
$user = $request->getUser();
54
$id = $request->getValue('id');
55
$phid = $request->getValue('phid');
56
$query = id(new ConpherenceThreadQuery())
57
->setViewer($user);
58
if ($id) {
59
$query->withIDs(array($id));
60
} else if ($phid) {
61
$query->withPHIDs(array($phid));
62
} else {
63
throw new ConduitException('ERR_USAGE_NO_ROOM_ID');
64
}
65
$conpherence = $query->executeOne();
66
if (!$conpherence) {
67
throw new ConduitException('ERR_USAGE_ROOM_NOT_FOUND');
68
}
69
70
$source = $request->newContentSource();
71
$editor = id(new ConpherenceEditor())
72
->setContentSource($source)
73
->setActor($user);
74
$xactions = array();
75
$add_participant_phids = $request->getValue('addParticipantPHIDs', array());
76
$remove_participant_phid = $request->getValue('removeParticipantPHID');
77
$message = $request->getValue('message');
78
$title = $request->getValue('title');
79
if ($add_participant_phids) {
80
$xactions[] = id(new ConpherenceTransaction())
81
->setTransactionType(
82
ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
83
->setNewValue(array('+' => $add_participant_phids));
84
}
85
if ($remove_participant_phid) {
86
if ($remove_participant_phid != $user->getPHID()) {
87
throw new ConduitException('ERR_USAGE_ONLY_SELF_REMOVE');
88
}
89
$xactions[] = id(new ConpherenceTransaction())
90
->setTransactionType(
91
ConpherenceThreadParticipantsTransaction::TRANSACTIONTYPE)
92
->setNewValue(array('-' => array($remove_participant_phid)));
93
}
94
if ($title) {
95
$xactions[] = id(new ConpherenceTransaction())
96
->setTransactionType(
97
ConpherenceThreadTitleTransaction::TRANSACTIONTYPE)
98
->setNewValue($title);
99
}
100
if ($message) {
101
$xactions = array_merge(
102
$xactions,
103
$editor->generateTransactionsFromText(
104
$user,
105
$conpherence,
106
$message));
107
}
108
109
try {
110
$xactions = $editor->applyTransactions($conpherence, $xactions);
111
} catch (PhabricatorApplicationTransactionNoEffectException $ex) {
112
throw new ConduitException('ERR_USAGE_NO_UPDATES');
113
}
114
115
return true;
116
}
117
118
}
119
120