Differential D21819 Diff 52027 src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Show First 20 Lines • Show All 1,294 Lines • ▼ Show 20 Lines | try { | ||||
if ($mark_as_create) { | if ($mark_as_create) { | ||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$xaction->setIsCreateTransaction(true); | $xaction->setIsCreateTransaction(true); | ||||
} | } | ||||
} | } | ||||
$xactions = $this->sortTransactions($xactions); | $xactions = $this->sortTransactions($xactions); | ||||
$file_phids = $this->extractFilePHIDs($object, $xactions); | |||||
if ($is_preview) { | if ($is_preview) { | ||||
$this->loadHandles($xactions); | $this->loadHandles($xactions); | ||||
return $xactions; | return $xactions; | ||||
} | } | ||||
$comment_editor = id(new PhabricatorApplicationTransactionCommentEditor()) | $comment_editor = id(new PhabricatorApplicationTransactionCommentEditor()) | ||||
->setActor($actor) | ->setActor($actor) | ||||
▲ Show 20 Lines • Show All 72 Lines • ▼ Show 20 Lines | try { | ||||
$xaction->setOldValue($bulky_old); | $xaction->setOldValue($bulky_old); | ||||
$xaction->setNewValue($bulky_new); | $xaction->setNewValue($bulky_new); | ||||
} else { | } else { | ||||
$xaction->save(); | $xaction->save(); | ||||
} | } | ||||
} | } | ||||
} | } | ||||
if ($file_phids) { | |||||
$this->attachFiles($object, $file_phids); | |||||
} | |||||
foreach ($xactions as $xaction) { | foreach ($xactions as $xaction) { | ||||
$this->applyExternalEffects($object, $xaction); | $this->applyExternalEffects($object, $xaction); | ||||
} | } | ||||
$xactions = $this->applyFinalEffects($object, $xactions); | $xactions = $this->applyFinalEffects($object, $xactions); | ||||
if ($read_locking) { | if ($read_locking) { | ||||
$object->endReadLocking(); | $object->endReadLocking(); | ||||
▲ Show 20 Lines • Show All 2,944 Lines • ▼ Show 20 Lines | foreach ($xactions as $xaction) { | ||||
} else { | } else { | ||||
$phids[] = $this->extractFilePHIDsFromCustomTransaction( | $phids[] = $this->extractFilePHIDsFromCustomTransaction( | ||||
$object, | $object, | ||||
$xaction); | $xaction); | ||||
} | } | ||||
} | } | ||||
$phids = array_unique(array_filter(array_mergev($phids))); | $phids = array_unique(array_filter(array_mergev($phids))); | ||||
if (!$phids) { | |||||
return array(); | |||||
} | |||||
// Only let a user attach files they can actually see, since this would | |||||
// otherwise let you access any file by attaching it to an object you have | |||||
// view permission on. | |||||
$files = id(new PhabricatorFileQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs($phids) | |||||
->execute(); | |||||
return mpull($files, 'getPHID'); | return $phids; | ||||
} | } | ||||
/** | /** | ||||
* @task files | * @task files | ||||
*/ | */ | ||||
protected function extractFilePHIDsFromCustomTransaction( | protected function extractFilePHIDsFromCustomTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction) { | PhabricatorApplicationTransaction $xaction) { | ||||
return array(); | return array(); | ||||
} | } | ||||
/** | |||||
* @task files | |||||
*/ | |||||
private function attachFiles( | |||||
PhabricatorLiskDAO $object, | |||||
array $file_phids) { | |||||
if (!$file_phids) { | |||||
return; | |||||
} | |||||
$editor = new PhabricatorEdgeEditor(); | |||||
$src = $object->getPHID(); | |||||
$type = PhabricatorObjectHasFileEdgeType::EDGECONST; | |||||
foreach ($file_phids as $dst) { | |||||
$editor->addEdge($src, $type, $dst); | |||||
} | |||||
$editor->save(); | |||||
} | |||||
private function applyInverseEdgeTransactions( | private function applyInverseEdgeTransactions( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
PhabricatorApplicationTransaction $xaction, | PhabricatorApplicationTransaction $xaction, | ||||
$inverse_type) { | $inverse_type) { | ||||
$old = $xaction->getOldValue(); | $old = $xaction->getOldValue(); | ||||
$new = $xaction->getNewValue(); | $new = $xaction->getNewValue(); | ||||
▲ Show 20 Lines • Show All 430 Lines • ▼ Show 20 Lines | private function scrambleFileSecrets($object) { | ||||
// If the object is a file itself, scramble it. | // If the object is a file itself, scramble it. | ||||
if ($object instanceof PhabricatorFile) { | if ($object instanceof PhabricatorFile) { | ||||
if ($this->shouldScramblePolicy($object->getViewPolicy())) { | if ($this->shouldScramblePolicy($object->getViewPolicy())) { | ||||
$object->scrambleSecret(); | $object->scrambleSecret(); | ||||
$object->save(); | $object->save(); | ||||
} | } | ||||
} | } | ||||
$phid = $object->getPHID(); | |||||
$attached_phids = PhabricatorEdgeQuery::loadDestinationPHIDs( | |||||
$phid, | |||||
PhabricatorObjectHasFileEdgeType::EDGECONST); | |||||
if (!$attached_phids) { | |||||
return; | |||||
} | |||||
$omnipotent_viewer = PhabricatorUser::getOmnipotentUser(); | $omnipotent_viewer = PhabricatorUser::getOmnipotentUser(); | ||||
$files = id(new PhabricatorFileQuery()) | $files = id(new PhabricatorFileQuery()) | ||||
->setViewer($omnipotent_viewer) | ->setViewer($omnipotent_viewer) | ||||
->withPHIDs($attached_phids) | ->withAttachedObjectPHIDs(array($object->getPHID())) | ||||
->execute(); | ->execute(); | ||||
foreach ($files as $file) { | foreach ($files as $file) { | ||||
$view_policy = $file->getViewPolicy(); | $view_policy = $file->getViewPolicy(); | ||||
if ($this->shouldScramblePolicy($view_policy)) { | if ($this->shouldScramblePolicy($view_policy)) { | ||||
$file->scrambleSecret(); | $file->scrambleSecret(); | ||||
$file->save(); | $file->save(); | ||||
} | } | ||||
} | } | ||||
▲ Show 20 Lines • Show All 845 Lines • Show Last 20 Lines |