Correct Aphlict websocket URI construction after PHP8 compatibility changes
[phabricator.git] / src / applications / repository / xaction / PhabricatorRepositoryIdentityAssignTransaction.php
blobe81ecbe80ba8959c82495b9298ccc99ec7da7b8a
1 <?php
3 final class PhabricatorRepositoryIdentityAssignTransaction
4 extends PhabricatorRepositoryIdentityTransactionType {
6 const TRANSACTIONTYPE = 'repository:identity:assign';
8 public function generateOldValue($object) {
9 return nonempty($object->getManuallySetUserPHID(), null);
12 public function applyInternalEffects($object, $value) {
13 $object->setManuallySetUserPHID($value);
16 public function getTitle() {
17 $old = $this->getOldValue();
18 $new = $this->getNewValue();
20 if (!$old) {
21 return pht(
22 '%s assigned this identity to %s.',
23 $this->renderAuthor(),
24 $this->renderIdentityHandle($new));
25 } else if (!$new) {
26 return pht(
27 '%s removed %s as the assignee of this identity.',
28 $this->renderAuthor(),
29 $this->renderIdentityHandle($old));
30 } else {
31 return pht(
32 '%s changed the assigned user for this identity from %s to %s.',
33 $this->renderAuthor(),
34 $this->renderIdentityHandle($old),
35 $this->renderIdentityHandle($new));
39 private function renderIdentityHandle($handle) {
40 $unassigned_token = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN;
41 if ($handle === $unassigned_token) {
42 return phutil_tag('em', array(), pht('Explicitly Unassigned'));
43 } else {
44 return $this->renderHandle($handle);
48 public function validateTransactions($object, array $xactions) {
49 $errors = array();
50 $unassigned_token = DiffusionIdentityUnassignedDatasource::FUNCTION_TOKEN;
52 foreach ($xactions as $xaction) {
53 $old = $xaction->getOldValue();
54 $new = $xaction->getNewValue();
55 if (!strlen($new)) {
56 continue;
59 if ($new === $old) {
60 continue;
63 if ($new === $unassigned_token) {
64 continue;
67 $assignee_list = id(new PhabricatorPeopleQuery())
68 ->setViewer($this->getActor())
69 ->withPHIDs(array($new))
70 ->execute();
72 if (!$assignee_list) {
73 $errors[] = $this->newInvalidError(
74 pht('User "%s" is not a valid user.',
75 $new));
78 return $errors;