Differential D21837 Diff 52049 src/applications/transactions/storage/PhabricatorApplicationTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/storage/PhabricatorApplicationTransaction.php
Show First 20 Lines • Show All 335 Lines • ▼ Show 20 Lines | switch ($this->getTransactionType()) { | ||||
$phids[] = $field->getApplicationTransactionRequiredHandlePHIDs( | $phids[] = $field->getApplicationTransactionRequiredHandlePHIDs( | ||||
$this); | $this); | ||||
} | } | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_SUBSCRIBERS: | case PhabricatorTransactions::TYPE_SUBSCRIBERS: | ||||
$phids[] = $old; | $phids[] = $old; | ||||
$phids[] = $new; | $phids[] = $new; | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_FILE: | |||||
$phids[] = array_keys($old + $new); | |||||
break; | |||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this); | $record = PhabricatorEdgeChangeRecord::newFromTransaction($this); | ||||
$phids[] = $record->getChangedPHIDs(); | $phids[] = $record->getChangedPHIDs(); | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_COLUMNS: | case PhabricatorTransactions::TYPE_COLUMNS: | ||||
foreach ($new as $move) { | foreach ($new as $move) { | ||||
$phids[] = array( | $phids[] = array( | ||||
$move['columnPHID'], | $move['columnPHID'], | ||||
▲ Show 20 Lines • Show All 235 Lines • ▼ Show 20 Lines | public function shouldHide() { | ||||
// Always hide requests for object history. | // Always hide requests for object history. | ||||
if ($xaction_type === PhabricatorTransactions::TYPE_HISTORY) { | if ($xaction_type === PhabricatorTransactions::TYPE_HISTORY) { | ||||
return true; | return true; | ||||
} | } | ||||
// Always hide file attach/detach transactions. | // Always hide file attach/detach transactions. | ||||
if ($xaction_type === PhabricatorTransactions::TYPE_FILE) { | if ($xaction_type === PhabricatorTransactions::TYPE_FILE) { | ||||
if ($this->getMetadataValue('attach.implicit')) { | |||||
return true; | return true; | ||||
} | } | ||||
} | |||||
// Hide creation transactions if the old value is empty. These are | // Hide creation transactions if the old value is empty. These are | ||||
// transactions like "alice set the task title to: ...", which are | // transactions like "alice set the task title to: ...", which are | ||||
// essentially never interesting. | // essentially never interesting. | ||||
if ($this->getIsCreateTransaction()) { | if ($this->getIsCreateTransaction()) { | ||||
switch ($xaction_type) { | switch ($xaction_type) { | ||||
case PhabricatorTransactions::TYPE_CREATE: | case PhabricatorTransactions::TYPE_CREATE: | ||||
case PhabricatorTransactions::TYPE_VIEW_POLICY: | case PhabricatorTransactions::TYPE_VIEW_POLICY: | ||||
▲ Show 20 Lines • Show All 432 Lines • ▼ Show 20 Lines | switch ($this->getTransactionType()) { | ||||
} else { | } else { | ||||
// This is used when rendering previews, before the user actually | // This is used when rendering previews, before the user actually | ||||
// selects any CCs. | // selects any CCs. | ||||
return pht( | return pht( | ||||
'%s updated subscribers...', | '%s updated subscribers...', | ||||
$this->renderHandleLink($author_phid)); | $this->renderHandleLink($author_phid)); | ||||
} | } | ||||
break; | break; | ||||
case PhabricatorTransactions::TYPE_FILE: | |||||
$add = array_diff_key($new, $old); | |||||
$add = array_keys($add); | |||||
$rem = array_diff_key($old, $new); | |||||
$rem = array_keys($rem); | |||||
$mod = array(); | |||||
foreach ($old + $new as $key => $ignored) { | |||||
if (!isset($old[$key])) { | |||||
continue; | |||||
} | |||||
if (!isset($new[$key])) { | |||||
continue; | |||||
} | |||||
if ($old[$key] === $new[$key]) { | |||||
continue; | |||||
} | |||||
$mod[] = $key; | |||||
} | |||||
// Specialize the specific case of only modifying files and upgrading | |||||
// references to attachments. This is accessible via the UI and can | |||||
// be shown more clearly than the generic default transaction shows | |||||
// it. | |||||
$mode_reference = PhabricatorFileAttachment::MODE_REFERENCE; | |||||
$mode_attach = PhabricatorFileAttachment::MODE_ATTACH; | |||||
$is_refattach = false; | |||||
if ($mod && !$add && !$rem) { | |||||
$all_refattach = true; | |||||
foreach ($mod as $phid) { | |||||
if (idx($old, $phid) !== $mode_reference) { | |||||
$all_refattach = false; | |||||
break; | |||||
} | |||||
if (idx($new, $phid) !== $mode_attach) { | |||||
$all_refattach = false; | |||||
break; | |||||
} | |||||
} | |||||
$is_refattach = $all_refattach; | |||||
} | |||||
if ($is_refattach) { | |||||
return pht( | |||||
'%s attached %s referenced file(s): %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
phutil_count($mod), | |||||
$this->renderHandleList($mod)); | |||||
} else if ($add && $rem && $mod) { | |||||
return pht( | |||||
'%s updated %s attached file(s), added %s: %s; removed %s: %s; '. | |||||
'modified %s: %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
new PhutilNumber(count($add) + count($rem)), | |||||
phutil_count($add), | |||||
$this->renderHandleList($add), | |||||
phutil_count($rem), | |||||
$this->renderHandleList($rem), | |||||
phutil_count($mod), | |||||
$this->renderHandleList($mod)); | |||||
} else if ($add && $rem) { | |||||
return pht( | |||||
'%s updated %s attached file(s), added %s: %s; removed %s: %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
new PhutilNumber(count($add) + count($rem)), | |||||
phutil_count($add), | |||||
$this->renderHandleList($add), | |||||
phutil_count($rem), | |||||
$this->renderHandleList($rem)); | |||||
} else if ($add && $mod) { | |||||
return pht( | |||||
'%s updated %s attached file(s), added %s: %s; modified %s: %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
new PhutilNumber(count($add) + count($mod)), | |||||
phutil_count($add), | |||||
$this->renderHandleList($add), | |||||
phutil_count($mod), | |||||
$this->renderHandleList($mod)); | |||||
} else if ($rem && $mod) { | |||||
return pht( | |||||
'%s updated %s attached file(s), removed %s: %s; modified %s: %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
new PhutilNumber(count($rem) + count($mod)), | |||||
phutil_count($rem), | |||||
$this->renderHandleList($rem), | |||||
phutil_count($mod), | |||||
$this->renderHandleList($mod)); | |||||
} else if ($add) { | |||||
return pht( | |||||
'%s attached %s file(s): %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
phutil_count($add), | |||||
$this->renderHandleList($add)); | |||||
} else if ($rem) { | |||||
return pht( | |||||
'%s removed %s attached file(s): %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
phutil_count($rem), | |||||
$this->renderHandleList($rem)); | |||||
} else if ($mod) { | |||||
return pht( | |||||
'%s modified %s attached file(s): %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
phutil_count($mod), | |||||
$this->renderHandleList($mod)); | |||||
} else { | |||||
return pht( | |||||
'%s attached files...', | |||||
$this->renderHandleLink($author_phid)); | |||||
} | |||||
break; | |||||
case PhabricatorTransactions::TYPE_EDGE: | case PhabricatorTransactions::TYPE_EDGE: | ||||
$record = PhabricatorEdgeChangeRecord::newFromTransaction($this); | $record = PhabricatorEdgeChangeRecord::newFromTransaction($this); | ||||
$add = $record->getAddedPHIDs(); | $add = $record->getAddedPHIDs(); | ||||
$rem = $record->getRemovedPHIDs(); | $rem = $record->getRemovedPHIDs(); | ||||
$type = $this->getMetadata('edge:type'); | $type = $this->getMetadata('edge:type'); | ||||
$type = head($type); | $type = head($type); | ||||
▲ Show 20 Lines • Show All 421 Lines • ▼ Show 20 Lines | |||||
} | } | ||||
public function getMailTags() { | public function getMailTags() { | ||||
return array(); | return array(); | ||||
} | } | ||||
public function hasChangeDetails() { | public function hasChangeDetails() { | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_FILE: | |||||
return true; | |||||
case PhabricatorTransactions::TYPE_CUSTOMFIELD: | case PhabricatorTransactions::TYPE_CUSTOMFIELD: | ||||
$field = $this->getTransactionCustomField(); | $field = $this->getTransactionCustomField(); | ||||
if ($field) { | if ($field) { | ||||
return $field->getApplicationTransactionHasChangeDetails($this); | return $field->getApplicationTransactionHasChangeDetails($this); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
return false; | return false; | ||||
} | } | ||||
public function hasChangeDetailsForMail() { | public function hasChangeDetailsForMail() { | ||||
return $this->hasChangeDetails(); | return $this->hasChangeDetails(); | ||||
} | } | ||||
public function renderChangeDetailsForMail(PhabricatorUser $viewer) { | public function renderChangeDetailsForMail(PhabricatorUser $viewer) { | ||||
switch ($this->getTransactionType()) { | |||||
case PhabricatorTransactions::TYPE_FILE: | |||||
return false; | |||||
} | |||||
$view = $this->renderChangeDetails($viewer); | $view = $this->renderChangeDetails($viewer); | ||||
if ($view instanceof PhabricatorApplicationTransactionTextDiffDetailView) { | if ($view instanceof PhabricatorApplicationTransactionTextDiffDetailView) { | ||||
return $view->renderForMail(); | return $view->renderForMail(); | ||||
} | } | ||||
return null; | return null; | ||||
} | } | ||||
public function renderChangeDetails(PhabricatorUser $viewer) { | public function renderChangeDetails(PhabricatorUser $viewer) { | ||||
switch ($this->getTransactionType()) { | switch ($this->getTransactionType()) { | ||||
case PhabricatorTransactions::TYPE_FILE: | |||||
return $this->newFileTransactionChangeDetails($viewer); | |||||
case PhabricatorTransactions::TYPE_CUSTOMFIELD: | case PhabricatorTransactions::TYPE_CUSTOMFIELD: | ||||
$field = $this->getTransactionCustomField(); | $field = $this->getTransactionCustomField(); | ||||
if ($field) { | if ($field) { | ||||
return $field->getApplicationTransactionChangeDetails($this, $viewer); | return $field->getApplicationTransactionChangeDetails($this, $viewer); | ||||
} | } | ||||
break; | break; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 250 Lines • ▼ Show 20 Lines | return id(new PhutilSortVector()) | ||||
->addString($this->getPHID()); | ->addString($this->getPHID()); | ||||
} | } | ||||
public function newActionStrengthSortVector() { | public function newActionStrengthSortVector() { | ||||
return id(new PhutilSortVector()) | return id(new PhutilSortVector()) | ||||
->addInt(-$this->getActionStrength()); | ->addInt(-$this->getActionStrength()); | ||||
} | } | ||||
private function newFileTransactionChangeDetails(PhabricatorUser $viewer) { | |||||
$old = $this->getOldValue(); | |||||
$new = $this->getNewValue(); | |||||
$phids = array_keys($old + $new); | |||||
$handles = $viewer->loadHandles($phids); | |||||
$names = array( | |||||
PhabricatorFileAttachment::MODE_REFERENCE => pht('Referenced'), | |||||
PhabricatorFileAttachment::MODE_ATTACH => pht('Attached'), | |||||
); | |||||
$rows = array(); | |||||
foreach ($old + $new as $phid => $ignored) { | |||||
$handle = $handles[$phid]; | |||||
$old_mode = idx($old, $phid); | |||||
$new_mode = idx($new, $phid); | |||||
if ($old_mode === null) { | |||||
$old_name = pht('None'); | |||||
} else if (isset($names[$old_mode])) { | |||||
$old_name = $names[$old_mode]; | |||||
} else { | |||||
$old_name = pht('Unknown ("%s")', $old_mode); | |||||
} | |||||
if ($new_mode === null) { | |||||
$new_name = pht('Detached'); | |||||
} else if (isset($names[$new_mode])) { | |||||
$new_name = $names[$new_mode]; | |||||
} else { | |||||
$new_name = pht('Unknown ("%s")', $new_mode); | |||||
} | |||||
$rows[] = array( | |||||
$handle->renderLink(), | |||||
$old_name, | |||||
$new_name, | |||||
); | |||||
} | |||||
$table = id(new AphrontTableView($rows)) | |||||
->setHeaders( | |||||
array( | |||||
pht('File'), | |||||
pht('Old Mode'), | |||||
pht('New Mode'), | |||||
)) | |||||
->setColumnClasses( | |||||
array( | |||||
'pri', | |||||
)); | |||||
return id(new PHUIBoxView()) | |||||
->addMargin(PHUI::MARGIN_SMALL) | |||||
->appendChild($table); | |||||
} | |||||
/* -( PhabricatorPolicyInterface Implementation )-------------------------- */ | /* -( PhabricatorPolicyInterface Implementation )-------------------------- */ | ||||
public function getCapabilities() { | public function getCapabilities() { | ||||
return array( | return array( | ||||
PhabricatorPolicyCapability::CAN_VIEW, | PhabricatorPolicyCapability::CAN_VIEW, | ||||
PhabricatorPolicyCapability::CAN_EDIT, | PhabricatorPolicyCapability::CAN_EDIT, | ||||
▲ Show 20 Lines • Show All 51 Lines • ▼ Show 20 Lines | $this->openTransaction(); | ||||
$engine->destroyObject($comment); | $engine->destroyObject($comment); | ||||
} | } | ||||
} | } | ||||
$this->delete(); | $this->delete(); | ||||
$this->saveTransaction(); | $this->saveTransaction(); | ||||
} | } | ||||
} | } |