mirror of
https://we.phorge.it/source/phorge.git
synced 2025-03-13 04:44:53 +01:00
Summary: Depends on D20115. See <https://discourse.phabricator-community.org/t/transaction-search-endpoint-does-not-work-on-differential-diffs/2369/>. Currently, `getApplicationTransactionCommentObject()` throws by default. Subclasses must override it to `return null` to indicate that they don't support comments. This is silly, and leads to a bunch of code that does a `try / catch` around it, and at least some code (here, `transaction.search`) which doesn't `try / catch` and gets the wrong behavior as a result. Just make it `return null` by default, meaning "no support for comments". Then remove the `try / catch` stuff and all the `return null` implementations. Test Plan: - Grepped for `getApplicationTransactionCommentObject()`, fixed each callsite / definition. - Called `transaction.search` on a diff with transactions (i.e., not a sourced-from-commit diff). Reviewers: amckinley Reviewed By: amckinley Subscribers: jbrownEP Differential Revision: https://secure.phabricator.com/D20121
152 lines
4 KiB
PHP
152 lines
4 KiB
PHP
<?php
|
|
|
|
final class PhabricatorConfigTransaction
|
|
extends PhabricatorApplicationTransaction {
|
|
|
|
const TYPE_EDIT = 'config:edit';
|
|
|
|
public function getApplicationName() {
|
|
return 'config';
|
|
}
|
|
|
|
public function getApplicationTransactionType() {
|
|
return PhabricatorConfigConfigPHIDType::TYPECONST;
|
|
}
|
|
|
|
public function getTitle() {
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$old = $this->getOldValue();
|
|
$new = $this->getNewValue();
|
|
|
|
switch ($this->getTransactionType()) {
|
|
case self::TYPE_EDIT:
|
|
|
|
// TODO: After T2213 show the actual values too; for now, we don't
|
|
// have the tools to do it without making a bit of a mess of it.
|
|
|
|
$old_del = idx($old, 'deleted');
|
|
$new_del = idx($new, 'deleted');
|
|
if ($old_del && !$new_del) {
|
|
return pht(
|
|
'%s created this configuration entry.',
|
|
$this->renderHandleLink($author_phid));
|
|
} else if (!$old_del && $new_del) {
|
|
return pht(
|
|
'%s deleted this configuration entry.',
|
|
$this->renderHandleLink($author_phid));
|
|
} else if ($old_del && $new_del) {
|
|
// This is a bug.
|
|
return pht(
|
|
'%s deleted this configuration entry (again?).',
|
|
$this->renderHandleLink($author_phid));
|
|
} else {
|
|
return pht(
|
|
'%s edited this configuration entry.',
|
|
$this->renderHandleLink($author_phid));
|
|
}
|
|
break;
|
|
}
|
|
|
|
return parent::getTitle();
|
|
}
|
|
|
|
public function getTitleForFeed() {
|
|
$author_phid = $this->getAuthorPHID();
|
|
|
|
$old = $this->getOldValue();
|
|
$new = $this->getNewValue();
|
|
|
|
switch ($this->getTransactionType()) {
|
|
case self::TYPE_EDIT:
|
|
$old_del = idx($old, 'deleted');
|
|
$new_del = idx($new, 'deleted');
|
|
if ($old_del && !$new_del) {
|
|
return pht(
|
|
'%s created %s.',
|
|
$this->renderHandleLink($author_phid),
|
|
$this->getObject()->getConfigKey());
|
|
} else if (!$old_del && $new_del) {
|
|
return pht(
|
|
'%s deleted %s.',
|
|
$this->renderHandleLink($author_phid),
|
|
$this->getObject()->getConfigKey());
|
|
} else if ($old_del && $new_del) {
|
|
// This is a bug.
|
|
return pht(
|
|
'%s deleted %s (again?).',
|
|
$this->renderHandleLink($author_phid),
|
|
$this->getObject()->getConfigKey());
|
|
} else {
|
|
return pht(
|
|
'%s edited %s.',
|
|
$this->renderHandleLink($author_phid),
|
|
$this->getObject()->getConfigKey());
|
|
}
|
|
break;
|
|
}
|
|
|
|
return parent::getTitle();
|
|
}
|
|
|
|
|
|
public function getIcon() {
|
|
switch ($this->getTransactionType()) {
|
|
case self::TYPE_EDIT:
|
|
return 'fa-pencil';
|
|
}
|
|
|
|
return parent::getIcon();
|
|
}
|
|
|
|
public function hasChangeDetails() {
|
|
switch ($this->getTransactionType()) {
|
|
case self::TYPE_EDIT:
|
|
return true;
|
|
}
|
|
return parent::hasChangeDetails();
|
|
}
|
|
|
|
public function renderChangeDetails(PhabricatorUser $viewer) {
|
|
$old = $this->getOldValue();
|
|
$new = $this->getNewValue();
|
|
|
|
if ($old['deleted']) {
|
|
$old_text = '';
|
|
} else {
|
|
$old_text = PhabricatorConfigJSON::prettyPrintJSON($old['value']);
|
|
}
|
|
|
|
if ($new['deleted']) {
|
|
$new_text = '';
|
|
} else {
|
|
$new_text = PhabricatorConfigJSON::prettyPrintJSON($new['value']);
|
|
}
|
|
|
|
return $this->renderTextCorpusChangeDetails(
|
|
$viewer,
|
|
$old_text,
|
|
$new_text);
|
|
}
|
|
|
|
public function getColor() {
|
|
$old = $this->getOldValue();
|
|
$new = $this->getNewValue();
|
|
|
|
switch ($this->getTransactionType()) {
|
|
case self::TYPE_EDIT:
|
|
$old_del = idx($old, 'deleted');
|
|
$new_del = idx($new, 'deleted');
|
|
|
|
if ($old_del && !$new_del) {
|
|
return PhabricatorTransactions::COLOR_GREEN;
|
|
} else if (!$old_del && $new_del) {
|
|
return PhabricatorTransactions::COLOR_RED;
|
|
} else {
|
|
return PhabricatorTransactions::COLOR_BLUE;
|
|
}
|
|
break;
|
|
}
|
|
}
|
|
|
|
}
|