Changeset View
Changeset View
Standalone View
Standalone View
src/applications/tokens/storage/PhabricatorTokensTransaction.php
- This file was added.
<?php | |||||
final class PhabricatorTokensTransaction | |||||
extends PhabricatorApplicationTransaction { | |||||
epriestley: I think new applications like this should probably use ModularTransactions now -- they may run… | |||||
const TYPE_NAME = 'tokens.token.name'; | |||||
const TYPE_FLAVOR = 'tokens.token.flavor'; | |||||
const TYPE_IMAGE = 'tokens.token.image'; | |||||
const TYPE_STATUS = 'tokens.token.status'; | |||||
const MAILTAG_DETAILS = 'tokens.token.details'; | |||||
const MAILTAG_COMMENT = 'tokens.token.comment'; | |||||
const MAILTAG_OTHER = 'tokens.token.other'; | |||||
public function getApplicationName() { | |||||
return 'tokens'; | |||||
} | |||||
public function getApplicationTransactionType() { | |||||
return PhabricatorTokensTokenPHIDType::TYPECONST; | |||||
} | |||||
public function getApplicationTransactionCommentObject() { | |||||
return new PhabricatorTokensTransactionComment(); | |||||
} | |||||
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( | |||||
Not Done Inline ActionsThese null create cases are no longer possible in modern EditEngine code, and can be removed from new object types. epriestley: These `null` create cases are no longer possible in modern EditEngine code, and can be removed… | |||||
'%s created this token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
} else { | |||||
return pht( | |||||
'%s renamed this token 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 token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
} else { | |||||
return pht( | |||||
'%s updated the flavor text for this token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
} | |||||
break; | |||||
Not Done Inline ActionsThis should render a prose diff. epriestley: This should render a prose diff. | |||||
case self::TYPE_STATUS: | |||||
switch ($new) { | |||||
case PhabricatorTokensToken::STATUS_ACTIVE: | |||||
return pht( | |||||
'%s activated this token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
case PhabricatorTokensToken::STATUS_ARCHIVED: | |||||
return pht( | |||||
'%s archived this token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
} | |||||
break; | |||||
case self::TYPE_IMAGE: | |||||
return pht( | |||||
'%s updated the image for this token.', | |||||
$this->renderHandleLink($author_phid)); | |||||
break; | |||||
} | |||||
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), | |||||
Not Done Inline ActionsFor consistency, include "from X to Y"? epriestley: For consistency, include "from X to Y"? | |||||
$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_IMAGE: | |||||
return pht( | |||||
'%s updated the image for %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($object_phid)); | |||||
case self::TYPE_STATUS: | |||||
switch ($new) { | |||||
case PhabricatorTokensToken::STATUS_ACTIVE: | |||||
return pht( | |||||
'%s activated %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($object_phid)); | |||||
case PhabricatorTokensToken::STATUS_ARCHIVED: | |||||
return pht( | |||||
'%s archived %s.', | |||||
$this->renderHandleLink($author_phid), | |||||
$this->renderHandleLink($object_phid)); | |||||
} | |||||
break; | |||||
} | |||||
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_FLAVOR: | |||||
case self::TYPE_IMAGE: | |||||
$tags[] = self::MAILTAG_DETAILS; | |||||
break; | |||||
default: | |||||
$tags[] = self::MAILTAG_OTHER; | |||||
break; | |||||
} | |||||
return $tags; | |||||
} | |||||
} |
I think new applications like this should probably use ModularTransactions now -- they may run into some issues, but it seems like they're in good shape so far. D16111 has old/new for Paste, although it has a lot of other stuff too.