Changeset View
Changeset View
Standalone View
Standalone View
src/applications/macro/xaction/PhabricatorMacroFileTransaction.php
<?php | <?php | ||||
final class PhabricatorMacroFileTransaction | final class PhabricatorMacroFileTransaction | ||||
extends PhabricatorMacroTransactionType { | extends PhabricatorMacroTransactionType { | ||||
const TRANSACTIONTYPE = 'macro:file'; | const TRANSACTIONTYPE = 'macro:file'; | ||||
public function generateOldValue($object) { | public function generateOldValue($object) { | ||||
return $object->getFilePHID(); | return $object->getFilePHID(); | ||||
} | } | ||||
public function applyInternalEffects($object, $value) { | public function applyInternalEffects($object, $value) { | ||||
$object->setFilePHID($value); | $object->setFilePHID($value); | ||||
} | } | ||||
public function applyExternalEffects($object, $value) { | public function extractFilePHIDs($object, $value) { | ||||
$old = $this->generateOldValue($object); | return array($value); | ||||
$new = $value; | |||||
$all = array(); | |||||
if ($old) { | |||||
$all[] = $old; | |||||
} | |||||
if ($new) { | |||||
$all[] = $new; | |||||
} | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs($all) | |||||
->execute(); | |||||
$files = mpull($files, null, 'getPHID'); | |||||
$old_file = idx($files, $old); | |||||
if ($old_file) { | |||||
$old_file->detachFromObject($object->getPHID()); | |||||
} | |||||
$new_file = idx($files, $new); | |||||
if ($new_file) { | |||||
$new_file->attachToObject($object->getPHID()); | |||||
} | |||||
} | } | ||||
public function getTitle() { | public function getTitle() { | ||||
return pht( | return pht( | ||||
'%s changed the image for this macro.', | '%s changed the image for this macro.', | ||||
$this->renderAuthor()); | $this->renderAuthor()); | ||||
} | } | ||||
▲ Show 20 Lines • Show All 55 Lines • Show Last 20 Lines |