Correct a parameter order swap in "diffusion.historyquery" for Mercurial
[phabricator.git] / src / applications / almanac / xaction / AlmanacInterfaceDeviceTransaction.php
blobed2c7b77de406e6aae40c1b9dfe54eda573dc95c
1 <?php
3 final class AlmanacInterfaceDeviceTransaction
4 extends AlmanacInterfaceTransactionType {
6 const TRANSACTIONTYPE = 'almanac:interface:device';
8 public function generateOldValue($object) {
9 return $object->getDevicePHID();
12 public function applyInternalEffects($object, $value) {
13 $object->setDevicePHID($value);
16 public function getTitle() {
17 return pht(
18 '%s changed the device for this interface from %s to %s.',
19 $this->renderAuthor(),
20 $this->renderOldHandle(),
21 $this->renderNewHandle());
24 public function validateTransactions($object, array $xactions) {
25 $errors = array();
27 $device_phid = $object->getDevicePHID();
28 if ($this->isEmptyTextTransaction($device_phid, $xactions)) {
29 $errors[] = $this->newRequiredError(
30 pht('Interfaces must have a device.'));
33 foreach ($xactions as $xaction) {
34 if (!$this->isNewObject()) {
35 $errors[] = $this->newInvalidError(
36 pht(
37 'The device for an interface can not be changed once it has '.
38 'been created.'),
39 $xaction);
40 continue;
43 $device_phid = $xaction->getNewValue();
44 $devices = id(new AlmanacDeviceQuery())
45 ->setViewer($this->getActor())
46 ->withPHIDs(array($device_phid))
47 ->execute();
48 if (!$devices) {
49 $errors[] = $this->newInvalidError(
50 pht(
51 'You can not attach an interface to a nonexistent or restricted '.
52 'device.'),
53 $xaction);
54 continue;
57 $device = head($devices);
58 $can_edit = PhabricatorPolicyFilter::hasCapability(
59 $this->getActor(),
60 $device,
61 PhabricatorPolicyCapability::CAN_EDIT);
62 if (!$can_edit) {
63 $errors[] = $this->newInvalidError(
64 pht(
65 'You can not attach an interface to a device which you do not '.
66 'have permission to edit.'));
67 continue;
71 return $errors;