Page Menu
Home
Phorge
Search
Configure Global Search
Log In
Files
F3281705
No One
Temporary
Actions
View File
Edit File
Delete File
View Transforms
Subscribe
Award Token
Flag For Later
Advanced/Developer...
View Handle
View Hovercard
Size
18 KB
Referenced Files
None
Subscribers
None
View Options
diff --git a/src/applications/badges/editor/PhabricatorBadgesEditor.php b/src/applications/badges/editor/PhabricatorBadgesEditor.php
index e71dd622c8..45a42a3362 100644
--- a/src/applications/badges/editor/PhabricatorBadgesEditor.php
+++ b/src/applications/badges/editor/PhabricatorBadgesEditor.php
@@ -1,257 +1,257 @@
<?php
final class PhabricatorBadgesEditor
extends PhabricatorApplicationTransactionEditor {
public function getEditorApplicationClass() {
return 'PhabricatorBadgesApplication';
}
public function getEditorObjectsDescription() {
return pht('Badges');
}
protected function supportsSearch() {
return true;
}
public function getTransactionTypes() {
$types = parent::getTransactionTypes();
$types[] = PhabricatorBadgesTransaction::TYPE_NAME;
$types[] = PhabricatorBadgesTransaction::TYPE_FLAVOR;
$types[] = PhabricatorBadgesTransaction::TYPE_DESCRIPTION;
$types[] = PhabricatorBadgesTransaction::TYPE_ICON;
$types[] = PhabricatorBadgesTransaction::TYPE_STATUS;
$types[] = PhabricatorBadgesTransaction::TYPE_QUALITY;
$types[] = PhabricatorBadgesTransaction::TYPE_AWARD;
$types[] = PhabricatorBadgesTransaction::TYPE_REVOKE;
$types[] = PhabricatorTransactions::TYPE_COMMENT;
$types[] = PhabricatorTransactions::TYPE_EDGE;
$types[] = PhabricatorTransactions::TYPE_EDIT_POLICY;
return $types;
}
protected function getCustomTransactionOldValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorBadgesTransaction::TYPE_NAME:
return $object->getName();
case PhabricatorBadgesTransaction::TYPE_FLAVOR:
return $object->getFlavor();
case PhabricatorBadgesTransaction::TYPE_DESCRIPTION:
return $object->getDescription();
case PhabricatorBadgesTransaction::TYPE_ICON:
return $object->getIcon();
case PhabricatorBadgesTransaction::TYPE_QUALITY:
- return $object->getQuality();
+ return (int)$object->getQuality();
case PhabricatorBadgesTransaction::TYPE_STATUS:
return $object->getStatus();
case PhabricatorBadgesTransaction::TYPE_AWARD:
$award_phids = mpull($object->getAwards(), 'getRecipientPHID');
return $award_phids;
case PhabricatorBadgesTransaction::TYPE_REVOKE:
return null;
}
return parent::getCustomTransactionOldValue($object, $xaction);
}
protected function getCustomTransactionNewValue(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
switch ($xaction->getTransactionType()) {
case PhabricatorBadgesTransaction::TYPE_NAME:
case PhabricatorBadgesTransaction::TYPE_FLAVOR:
case PhabricatorBadgesTransaction::TYPE_DESCRIPTION:
case PhabricatorBadgesTransaction::TYPE_ICON:
case PhabricatorBadgesTransaction::TYPE_STATUS:
case PhabricatorBadgesTransaction::TYPE_AWARD:
case PhabricatorBadgesTransaction::TYPE_REVOKE:
return $xaction->getNewValue();
case PhabricatorBadgesTransaction::TYPE_QUALITY:
return (int)$xaction->getNewValue();
}
return parent::getCustomTransactionNewValue($object, $xaction);
}
protected function applyCustomInternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$type = $xaction->getTransactionType();
switch ($type) {
case PhabricatorBadgesTransaction::TYPE_NAME:
$object->setName($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_FLAVOR:
$object->setFlavor($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_DESCRIPTION:
$object->setDescription($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_ICON:
$object->setIcon($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_QUALITY:
$object->setQuality($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_STATUS:
$object->setStatus($xaction->getNewValue());
return;
case PhabricatorBadgesTransaction::TYPE_AWARD:
case PhabricatorBadgesTransaction::TYPE_REVOKE:
return;
}
return parent::applyCustomInternalTransaction($object, $xaction);
}
protected function applyCustomExternalTransaction(
PhabricatorLiskDAO $object,
PhabricatorApplicationTransaction $xaction) {
$type = $xaction->getTransactionType();
switch ($type) {
case PhabricatorBadgesTransaction::TYPE_NAME:
case PhabricatorBadgesTransaction::TYPE_FLAVOR:
case PhabricatorBadgesTransaction::TYPE_DESCRIPTION:
case PhabricatorBadgesTransaction::TYPE_ICON:
case PhabricatorBadgesTransaction::TYPE_STATUS:
case PhabricatorBadgesTransaction::TYPE_QUALITY:
return;
case PhabricatorBadgesTransaction::TYPE_REVOKE:
$revoked_recipient_phids = $xaction->getNewValue();
$awards = $object->getAwards();
$awards = mpull($awards, null, 'getRecipientPHID');
foreach ($revoked_recipient_phids as $phid) {
$awards[$phid]->delete();
}
$object->attachAwards($awards);
return;
case PhabricatorBadgesTransaction::TYPE_AWARD:
$recipient_phids = $xaction->getNewValue();
$awards = $object->getAwards();
$awards = mpull($awards, null, 'getRecipientPHID');
foreach ($recipient_phids as $phid) {
$award = idx($awards, $phid);
if (!$award) {
$award = PhabricatorBadgesAward::initializeNewBadgesAward(
$this->getActor(),
$object,
$phid);
$award->save();
$awards[] = $award;
}
}
$object->attachAwards($awards);
return;
}
return parent::applyCustomExternalTransaction($object, $xaction);
}
protected function validateTransaction(
PhabricatorLiskDAO $object,
$type,
array $xactions) {
$errors = parent::validateTransaction($object, $type, $xactions);
switch ($type) {
case PhabricatorBadgesTransaction::TYPE_NAME:
$missing = $this->validateIsEmptyTextField(
$object->getName(),
$xactions);
if ($missing) {
$error = new PhabricatorApplicationTransactionValidationError(
$type,
pht('Required'),
pht('Badge name is required.'),
nonempty(last($xactions), null));
$error->setIsMissingFieldError(true);
$errors[] = $error;
}
break;
}
return $errors;
}
protected function shouldSendMail(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
public function getMailTagsMap() {
return array(
PhabricatorBadgesTransaction::MAILTAG_DETAILS =>
pht('Someone changes the badge\'s details.'),
PhabricatorBadgesTransaction::MAILTAG_COMMENT =>
pht('Someone comments on a badge.'),
PhabricatorBadgesTransaction::MAILTAG_OTHER =>
pht('Other badge activity not listed above occurs.'),
);
}
protected function shouldPublishFeedStory(
PhabricatorLiskDAO $object,
array $xactions) {
return true;
}
protected function buildReplyHandler(PhabricatorLiskDAO $object) {
return id(new PhabricatorBadgesReplyHandler())
->setMailReceiver($object);
}
protected function buildMailTemplate(PhabricatorLiskDAO $object) {
$name = $object->getName();
$id = $object->getID();
$name = pht('Badge %d', $id);
return id(new PhabricatorMetaMTAMail())
->setSubject($name)
->addHeader('Thread-Topic', $name);
}
protected function getMailTo(PhabricatorLiskDAO $object) {
return array(
$object->getCreatorPHID(),
$this->requireActor()->getPHID(),
);
}
protected function buildMailBody(
PhabricatorLiskDAO $object,
array $xactions) {
$description = $object->getDescription();
$body = parent::buildMailBody($object, $xactions);
if (strlen($description)) {
$body->addRemarkupSection(
pht('BADGE DESCRIPTION'),
$object->getDescription());
}
$body->addLinkSection(
pht('BADGE DETAIL'),
PhabricatorEnv::getProductionURI('/badges/view/'.$object->getID().'/'));
return $body;
}
protected function getMailSubjectPrefix() {
return pht('[Badge]');
}
}
diff --git a/src/applications/badges/storage/PhabricatorBadgesTransaction.php b/src/applications/badges/storage/PhabricatorBadgesTransaction.php
index f088c2d973..22505b247e 100644
--- a/src/applications/badges/storage/PhabricatorBadgesTransaction.php
+++ b/src/applications/badges/storage/PhabricatorBadgesTransaction.php
@@ -1,299 +1,299 @@
<?php
final class PhabricatorBadgesTransaction
extends PhabricatorApplicationTransaction {
const TYPE_NAME = 'badges:name';
const TYPE_DESCRIPTION = 'badges:description';
const TYPE_QUALITY = 'badges:quality';
const TYPE_ICON = 'badges:icon';
const TYPE_STATUS = 'badges:status';
const TYPE_FLAVOR = 'badges:flavor';
const TYPE_AWARD = 'badges:award';
const TYPE_REVOKE = 'badges:revoke';
const MAILTAG_DETAILS = 'badges:details';
const MAILTAG_COMMENT = 'badges:comment';
const MAILTAG_OTHER = 'badges:other';
public function getApplicationName() {
return 'badges';
}
public function getApplicationTransactionType() {
return PhabricatorBadgesPHIDType::TYPECONST;
}
public function getApplicationTransactionCommentObject() {
return new PhabricatorBadgesTransactionComment();
}
public function getTitle() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if ($old === null) {
return pht(
'%s created this badge.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s renamed this badge from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$old,
$new);
}
break;
case self::TYPE_FLAVOR:
if ($old === null) {
return pht(
'%s set the flavor text for this badge.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s updated the flavor text for this badge.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_DESCRIPTION:
if ($old === null) {
return pht(
'%s set the description for this badge.',
$this->renderHandleLink($author_phid));
} else {
return pht(
'%s updated the description for this badge.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_STATUS:
switch ($new) {
case PhabricatorBadgesBadge::STATUS_ACTIVE:
return pht(
'%s activated this badge.',
$this->renderHandleLink($author_phid));
case PhabricatorBadgesBadge::STATUS_ARCHIVED:
return pht(
'%s archived this badge.',
$this->renderHandleLink($author_phid));
}
break;
case self::TYPE_ICON:
if ($old === null) {
return pht(
'%s set the icon for this badge as "%s".',
$this->renderHandleLink($author_phid),
$new);
} else {
$set = new PhabricatorBadgesIconSet();
$icon_old = $set->getIconLabel($old);
$icon_new = $set->getIconLabel($new);
return pht(
'%s updated the icon for this badge from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$icon_old,
$icon_new);
}
break;
case self::TYPE_QUALITY:
+ $qual_new = PhabricatorBadgesQuality::getQualityName($new);
+ $qual_old = PhabricatorBadgesQuality::getQualityName($old);
if ($old === null) {
return pht(
'%s set the quality for this badge as "%s".',
$this->renderHandleLink($author_phid),
- $new);
+ $qual_new);
} else {
- $qual_new = PhabricatorBadgesQuality::getQualityName($new);
- $qual_old = PhabricatorBadgesQuality::getQualityName($old);
return pht(
'%s updated the quality for this badge from "%s" to "%s".',
$this->renderHandleLink($author_phid),
$qual_old,
$qual_new);
}
break;
case self::TYPE_AWARD:
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s awarded this badge to %s recipient(s): %s.',
$this->renderHandleLink($author_phid),
new PhutilNumber(count($new)),
$handles);
case self::TYPE_REVOKE:
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s revoked this badge from %s recipient(s): %s.',
$this->renderHandleLink($author_phid),
new PhutilNumber(count($new)),
$handles);
}
return parent::getTitle();
}
public function getTitleForFeed() {
$author_phid = $this->getAuthorPHID();
$object_phid = $this->getObjectPHID();
$old = $this->getOldValue();
$new = $this->getNewValue();
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_NAME:
if ($old === null) {
return pht(
'%s created %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
} else {
return pht(
'%s renamed %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
break;
case self::TYPE_FLAVOR:
return pht(
'%s updated the flavor text for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_ICON:
return pht(
'%s updated the icon for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_QUALITY:
return pht(
'%s updated the quality level for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_DESCRIPTION:
return pht(
'%s updated the description for %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case self::TYPE_STATUS:
switch ($new) {
case PhabricatorBadgesBadge::STATUS_ACTIVE:
return pht(
'%s activated %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
case PhabricatorBadgesBadge::STATUS_ARCHIVED:
return pht(
'%s archived %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid));
}
break;
case self::TYPE_AWARD:
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s awarded %s to %s recipient(s): %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
new PhutilNumber(count($new)),
$handles);
case self::TYPE_REVOKE:
if (!is_array($new)) {
$new = array();
}
$handles = $this->renderHandleList($new);
return pht(
'%s revoked %s from %s recipient(s): %s.',
$this->renderHandleLink($author_phid),
$this->renderHandleLink($object_phid),
new PhutilNumber(count($new)),
$handles);
}
return parent::getTitleForFeed();
}
public function getMailTags() {
$tags = parent::getMailTags();
switch ($this->getTransactionType()) {
case PhabricatorTransactions::TYPE_COMMENT:
$tags[] = self::MAILTAG_COMMENT;
break;
case self::TYPE_NAME:
case self::TYPE_DESCRIPTION:
case self::TYPE_FLAVOR:
case self::TYPE_ICON:
case self::TYPE_STATUS:
case self::TYPE_QUALITY:
$tags[] = self::MAILTAG_DETAILS;
break;
default:
$tags[] = self::MAILTAG_OTHER;
break;
}
return $tags;
}
public function shouldHide() {
$old = $this->getOldValue();
switch ($this->getTransactionType()) {
case self::TYPE_DESCRIPTION:
return ($old === null);
}
return parent::shouldHide();
}
public function hasChangeDetails() {
switch ($this->getTransactionType()) {
case self::TYPE_DESCRIPTION:
return ($this->getOldValue() !== null);
}
return parent::hasChangeDetails();
}
public function renderChangeDetails(PhabricatorUser $viewer) {
return $this->renderTextCorpusChangeDetails(
$viewer,
$this->getOldValue(),
$this->getNewValue());
}
public function getRequiredHandlePHIDs() {
$phids = parent::getRequiredHandlePHIDs();
$type = $this->getTransactionType();
switch ($type) {
case self::TYPE_AWARD:
case self::TYPE_REVOKE:
$new = $this->getNewValue();
if (!is_array($new)) {
$new = array();
}
foreach ($new as $phid) {
$phids[] = $phid;
}
break;
}
return $phids;
}
}
File Metadata
Details
Attached
Mime Type
text/x-diff
Expires
Mon, Mar 24, 00:44 (13 h, 35 m)
Storage Engine
blob
Storage Format
Raw Data
Storage Handle
1259413
Default Alt Text
(18 KB)
Attached To
Mode
rP Phorge
Attached
Detach File
Event Timeline
Log In to Comment