Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / almanac / xaction / AlmanacBindingServiceTransaction.php
blob4b9f802b2781d3fee8f3e7abd256aa6b9f5945e4
1 <?php
3 final class AlmanacBindingServiceTransaction
4 extends AlmanacBindingTransactionType {
6 const TRANSACTIONTYPE = 'almanac:binding:service';
8 public function generateOldValue($object) {
9 return $object->getServicePHID();
12 public function applyInternalEffects($object, $value) {
13 $object->setServicePHID($value);
16 public function validateTransactions($object, array $xactions) {
17 $errors = array();
19 $service_phid = $object->getServicePHID();
20 if ($this->isEmptyTextTransaction($service_phid, $xactions)) {
21 $errors[] = $this->newRequiredError(
22 pht('Bindings must have a service.'));
25 foreach ($xactions as $xaction) {
26 if (!$this->isNewObject()) {
27 $errors[] = $this->newInvalidError(
28 pht(
29 'The service for a binding can not be changed once it has '.
30 'been created.'),
31 $xaction);
32 continue;
35 $service_phid = $xaction->getNewValue();
36 $services = id(new AlmanacServiceQuery())
37 ->setViewer($this->getActor())
38 ->withPHIDs(array($service_phid))
39 ->execute();
40 if (!$services) {
41 $errors[] = $this->newInvalidError(
42 pht('You can not bind a nonexistent or restricted service.'),
43 $xaction);
44 continue;
47 $service = head($services);
48 $can_edit = PhabricatorPolicyFilter::hasCapability(
49 $this->getActor(),
50 $service,
51 PhabricatorPolicyCapability::CAN_EDIT);
52 if (!$can_edit) {
53 $errors[] = $this->newInvalidError(
54 pht(
55 'You can not bind a service which you do not have permission '.
56 'to edit.'));
57 continue;
61 return $errors;