Path: blob/master/src/applications/almanac/xaction/AlmanacInterfaceDeviceTransaction.php
12256 views
<?php12final class AlmanacInterfaceDeviceTransaction3extends AlmanacInterfaceTransactionType {45const TRANSACTIONTYPE = 'almanac:interface:device';67public function generateOldValue($object) {8return $object->getDevicePHID();9}1011public function applyInternalEffects($object, $value) {12$object->setDevicePHID($value);13}1415public function getTitle() {16return pht(17'%s changed the device for this interface from %s to %s.',18$this->renderAuthor(),19$this->renderOldHandle(),20$this->renderNewHandle());21}2223public function validateTransactions($object, array $xactions) {24$errors = array();2526$device_phid = $object->getDevicePHID();27if ($this->isEmptyTextTransaction($device_phid, $xactions)) {28$errors[] = $this->newRequiredError(29pht('Interfaces must have a device.'));30}3132foreach ($xactions as $xaction) {33if (!$this->isNewObject()) {34$errors[] = $this->newInvalidError(35pht(36'The device for an interface can not be changed once it has '.37'been created.'),38$xaction);39continue;40}4142$device_phid = $xaction->getNewValue();43$devices = id(new AlmanacDeviceQuery())44->setViewer($this->getActor())45->withPHIDs(array($device_phid))46->execute();47if (!$devices) {48$errors[] = $this->newInvalidError(49pht(50'You can not attach an interface to a nonexistent or restricted '.51'device.'),52$xaction);53continue;54}5556$device = head($devices);57$can_edit = PhabricatorPolicyFilter::hasCapability(58$this->getActor(),59$device,60PhabricatorPolicyCapability::CAN_EDIT);61if (!$can_edit) {62$errors[] = $this->newInvalidError(63pht(64'You can not attach an interface to a device which you do not '.65'have permission to edit.'));66continue;67}68}6970return $errors;71}7273}747576