Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryBlueprintsTransaction.php
blobaae164d70678036e1ef08a6a75aeb31d8dc8290a
1 <?php
3 final class PhabricatorRepositoryBlueprintsTransaction
4 extends PhabricatorRepositoryTransactionType {
6 const TRANSACTIONTYPE = 'repo:automation-blueprints';
8 public function generateOldValue($object) {
9 return $object->getDetail('automation.blueprintPHIDs', array());
12 public function applyInternalEffects($object, $value) {
13 $object->setDetail('automation.blueprintPHIDs', $value);
16 public function applyExternalEffects($object, $value) {
17 DrydockAuthorization::applyAuthorizationChanges(
18 $this->getActor(),
19 $object->getPHID(),
20 $this->getOldValue(),
21 $this->getNewValue());
24 public function getTitle() {
25 $old = $this->getOldValue();
26 $new = $this->getNewValue();
28 $add = array_diff($new, $old);
29 $rem = array_diff($old, $new);
31 if ($add && $rem) {
32 return pht(
33 '%s changed %s automation blueprint(s), '.
34 'added %s: %s; removed %s: %s.',
35 $this->renderAuthor(),
36 new PhutilNumber(count($add) + count($rem)),
37 new PhutilNumber(count($add)),
38 $this->renderHandleList($add),
39 new PhutilNumber(count($rem)),
40 $this->renderHandleList($rem));
41 } else if ($add) {
42 return pht(
43 '%s added %s automation blueprint(s): %s.',
44 $this->renderAuthor(),
45 new PhutilNumber(count($add)),
46 $this->renderHandleList($add));
47 } else {
48 return pht(
49 '%s removed %s automation blueprint(s): %s.',
50 $this->renderAuthor(),
51 new PhutilNumber(count($rem)),
52 $this->renderHandleList($rem));
56 public function validateTransactions($object, array $xactions) {
57 $errors = array();
59 foreach ($xactions as $xaction) {
60 $old = nonempty($xaction->getOldValue(), array());
61 $new = nonempty($xaction->getNewValue(), array());
63 $add = array_diff($new, $old);
65 $invalid = PhabricatorObjectQuery::loadInvalidPHIDsForViewer(
66 $this->getActor(),
67 $add);
68 if ($invalid) {
69 $errors[] = $this->newInvalidError(
70 pht(
71 'Some of the selected automation blueprints are invalid '.
72 'or restricted: %s.',
73 implode(', ', $invalid)),
74 $xaction);
78 return $errors;