mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-23 14:00:56 +01:00
Update Macro for Modular Transactions
Summary: Overall, seems to work ok. Test Plan: - Add a Macro - Edit Macro - Use Macro - Disable Macro - Re-enable Macro - Attach Audio - Set Audio to loop - Annoy cats {F4932069} Reviewers: epriestley Reviewed By: epriestley Subscribers: Korvin Differential Revision: https://secure.phabricator.com/D17813
This commit is contained in:
parent
eaaba278a9
commit
a067040024
13 changed files with 295 additions and 381 deletions
|
@ -2972,26 +2972,32 @@ phutil_register_library_map(array(
|
|||
'PhabricatorLogoutController' => 'applications/auth/controller/PhabricatorLogoutController.php',
|
||||
'PhabricatorLunarPhasePolicyRule' => 'applications/policy/rule/PhabricatorLunarPhasePolicyRule.php',
|
||||
'PhabricatorMacroApplication' => 'applications/macro/application/PhabricatorMacroApplication.php',
|
||||
'PhabricatorMacroAudioBehaviorTransaction' => 'applications/macro/xaction/PhabricatorMacroAudioBehaviorTransaction.php',
|
||||
'PhabricatorMacroAudioController' => 'applications/macro/controller/PhabricatorMacroAudioController.php',
|
||||
'PhabricatorMacroAudioTransaction' => 'applications/macro/xaction/PhabricatorMacroAudioTransaction.php',
|
||||
'PhabricatorMacroCommentController' => 'applications/macro/controller/PhabricatorMacroCommentController.php',
|
||||
'PhabricatorMacroConfigOptions' => 'applications/macro/config/PhabricatorMacroConfigOptions.php',
|
||||
'PhabricatorMacroController' => 'applications/macro/controller/PhabricatorMacroController.php',
|
||||
'PhabricatorMacroDatasource' => 'applications/macro/typeahead/PhabricatorMacroDatasource.php',
|
||||
'PhabricatorMacroDisableController' => 'applications/macro/controller/PhabricatorMacroDisableController.php',
|
||||
'PhabricatorMacroDisabledTransaction' => 'applications/macro/xaction/PhabricatorMacroDisabledTransaction.php',
|
||||
'PhabricatorMacroEditController' => 'applications/macro/controller/PhabricatorMacroEditController.php',
|
||||
'PhabricatorMacroEditor' => 'applications/macro/editor/PhabricatorMacroEditor.php',
|
||||
'PhabricatorMacroFileTransaction' => 'applications/macro/xaction/PhabricatorMacroFileTransaction.php',
|
||||
'PhabricatorMacroListController' => 'applications/macro/controller/PhabricatorMacroListController.php',
|
||||
'PhabricatorMacroMacroPHIDType' => 'applications/macro/phid/PhabricatorMacroMacroPHIDType.php',
|
||||
'PhabricatorMacroMailReceiver' => 'applications/macro/mail/PhabricatorMacroMailReceiver.php',
|
||||
'PhabricatorMacroManageCapability' => 'applications/macro/capability/PhabricatorMacroManageCapability.php',
|
||||
'PhabricatorMacroMemeController' => 'applications/macro/controller/PhabricatorMacroMemeController.php',
|
||||
'PhabricatorMacroMemeDialogController' => 'applications/macro/controller/PhabricatorMacroMemeDialogController.php',
|
||||
'PhabricatorMacroNameTransaction' => 'applications/macro/xaction/PhabricatorMacroNameTransaction.php',
|
||||
'PhabricatorMacroQuery' => 'applications/macro/query/PhabricatorMacroQuery.php',
|
||||
'PhabricatorMacroReplyHandler' => 'applications/macro/mail/PhabricatorMacroReplyHandler.php',
|
||||
'PhabricatorMacroSearchEngine' => 'applications/macro/query/PhabricatorMacroSearchEngine.php',
|
||||
'PhabricatorMacroTransaction' => 'applications/macro/storage/PhabricatorMacroTransaction.php',
|
||||
'PhabricatorMacroTransactionComment' => 'applications/macro/storage/PhabricatorMacroTransactionComment.php',
|
||||
'PhabricatorMacroTransactionQuery' => 'applications/macro/query/PhabricatorMacroTransactionQuery.php',
|
||||
'PhabricatorMacroTransactionType' => 'applications/macro/xaction/PhabricatorMacroTransactionType.php',
|
||||
'PhabricatorMacroViewController' => 'applications/macro/controller/PhabricatorMacroViewController.php',
|
||||
'PhabricatorMailEmailHeraldField' => 'applications/metamta/herald/PhabricatorMailEmailHeraldField.php',
|
||||
'PhabricatorMailEmailHeraldFieldGroup' => 'applications/metamta/herald/PhabricatorMailEmailHeraldFieldGroup.php',
|
||||
|
@ -8162,26 +8168,32 @@ phutil_register_library_map(array(
|
|||
'PhabricatorLogoutController' => 'PhabricatorAuthController',
|
||||
'PhabricatorLunarPhasePolicyRule' => 'PhabricatorPolicyRule',
|
||||
'PhabricatorMacroApplication' => 'PhabricatorApplication',
|
||||
'PhabricatorMacroAudioBehaviorTransaction' => 'PhabricatorMacroTransactionType',
|
||||
'PhabricatorMacroAudioController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroAudioTransaction' => 'PhabricatorMacroTransactionType',
|
||||
'PhabricatorMacroCommentController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroConfigOptions' => 'PhabricatorApplicationConfigOptions',
|
||||
'PhabricatorMacroController' => 'PhabricatorController',
|
||||
'PhabricatorMacroDatasource' => 'PhabricatorTypeaheadDatasource',
|
||||
'PhabricatorMacroDisableController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroDisabledTransaction' => 'PhabricatorMacroTransactionType',
|
||||
'PhabricatorMacroEditController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroEditor' => 'PhabricatorApplicationTransactionEditor',
|
||||
'PhabricatorMacroFileTransaction' => 'PhabricatorMacroTransactionType',
|
||||
'PhabricatorMacroListController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroMacroPHIDType' => 'PhabricatorPHIDType',
|
||||
'PhabricatorMacroMailReceiver' => 'PhabricatorObjectMailReceiver',
|
||||
'PhabricatorMacroManageCapability' => 'PhabricatorPolicyCapability',
|
||||
'PhabricatorMacroMemeController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroMemeDialogController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMacroNameTransaction' => 'PhabricatorMacroTransactionType',
|
||||
'PhabricatorMacroQuery' => 'PhabricatorCursorPagedPolicyAwareQuery',
|
||||
'PhabricatorMacroReplyHandler' => 'PhabricatorApplicationTransactionReplyHandler',
|
||||
'PhabricatorMacroSearchEngine' => 'PhabricatorApplicationSearchEngine',
|
||||
'PhabricatorMacroTransaction' => 'PhabricatorApplicationTransaction',
|
||||
'PhabricatorMacroTransaction' => 'PhabricatorModularTransaction',
|
||||
'PhabricatorMacroTransactionComment' => 'PhabricatorApplicationTransactionComment',
|
||||
'PhabricatorMacroTransactionQuery' => 'PhabricatorApplicationTransactionQuery',
|
||||
'PhabricatorMacroTransactionType' => 'PhabricatorModularTransactionType',
|
||||
'PhabricatorMacroViewController' => 'PhabricatorMacroController',
|
||||
'PhabricatorMailEmailHeraldField' => 'HeraldField',
|
||||
'PhabricatorMailEmailHeraldFieldGroup' => 'HeraldFieldGroup',
|
||||
|
|
|
@ -34,7 +34,7 @@ final class PhabricatorMacroAudioController extends PhabricatorMacroController {
|
|||
if ($request->getBool('behaviorForm')) {
|
||||
$xactions[] = id(new PhabricatorMacroTransaction())
|
||||
->setTransactionType(
|
||||
PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR)
|
||||
PhabricatorMacroAudioBehaviorTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($request->getStr('audioBehavior'));
|
||||
} else {
|
||||
$file = null;
|
||||
|
@ -54,7 +54,8 @@ final class PhabricatorMacroAudioController extends PhabricatorMacroController {
|
|||
$e_file = pht('Invalid');
|
||||
} else {
|
||||
$xactions[] = id(new PhabricatorMacroTransaction())
|
||||
->setTransactionType(PhabricatorMacroTransaction::TYPE_AUDIO)
|
||||
->setTransactionType(
|
||||
PhabricatorMacroAudioTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($file->getPHID());
|
||||
}
|
||||
} else {
|
||||
|
|
|
@ -22,7 +22,8 @@ final class PhabricatorMacroDisableController
|
|||
|
||||
if ($request->isDialogFormPost() || $macro->getIsDisabled()) {
|
||||
$xaction = id(new PhabricatorMacroTransaction())
|
||||
->setTransactionType(PhabricatorMacroTransaction::TYPE_DISABLED)
|
||||
->setTransactionType(
|
||||
PhabricatorMacroDisabledTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($macro->getIsDisabled() ? 0 : 1);
|
||||
|
||||
$editor = id(new PhabricatorMacroEditor())
|
||||
|
|
|
@ -135,13 +135,15 @@ final class PhabricatorMacroEditController extends PhabricatorMacroController {
|
|||
|
||||
if ($new_name !== null) {
|
||||
$xactions[] = id(new PhabricatorMacroTransaction())
|
||||
->setTransactionType(PhabricatorMacroTransaction::TYPE_NAME)
|
||||
->setTransactionType(
|
||||
PhabricatorMacroNameTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($new_name);
|
||||
}
|
||||
|
||||
if ($file) {
|
||||
$xactions[] = id(new PhabricatorMacroTransaction())
|
||||
->setTransactionType(PhabricatorMacroTransaction::TYPE_FILE)
|
||||
->setTransactionType(
|
||||
PhabricatorMacroFileTransaction::TRANSACTIONTYPE)
|
||||
->setNewValue($file->getPHID());
|
||||
}
|
||||
|
||||
|
|
|
@ -45,7 +45,7 @@ final class PhabricatorMacroViewController
|
|||
if (!$macro->getIsDisabled()) {
|
||||
$header->setStatus('fa-check', 'bluegrey', pht('Active'));
|
||||
} else {
|
||||
$header->setStatus('fa-ban', 'red', pht('Archived'));
|
||||
$header->setStatus('fa-ban', 'indigo', pht('Archived'));
|
||||
}
|
||||
|
||||
$is_serious = PhabricatorEnv::getEnvConfig('phabricator.serious-business');
|
||||
|
|
|
@ -13,79 +13,18 @@ final class PhabricatorMacroEditor
|
|||
|
||||
public function getTransactionTypes() {
|
||||
$types = parent::getTransactionTypes();
|
||||
|
||||
$types[] = PhabricatorTransactions::TYPE_COMMENT;
|
||||
$types[] = PhabricatorMacroTransaction::TYPE_NAME;
|
||||
$types[] = PhabricatorMacroTransaction::TYPE_DISABLED;
|
||||
$types[] = PhabricatorMacroTransaction::TYPE_FILE;
|
||||
$types[] = PhabricatorMacroTransaction::TYPE_AUDIO;
|
||||
$types[] = PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR;
|
||||
|
||||
return $types;
|
||||
}
|
||||
|
||||
protected function getCustomTransactionOldValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransaction::TYPE_NAME:
|
||||
return $object->getName();
|
||||
case PhabricatorMacroTransaction::TYPE_DISABLED:
|
||||
return $object->getIsDisabled();
|
||||
case PhabricatorMacroTransaction::TYPE_FILE:
|
||||
return $object->getFilePHID();
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO:
|
||||
return $object->getAudioPHID();
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR:
|
||||
return $object->getAudioBehavior();
|
||||
}
|
||||
}
|
||||
|
||||
protected function getCustomTransactionNewValue(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransaction::TYPE_NAME:
|
||||
case PhabricatorMacroTransaction::TYPE_DISABLED:
|
||||
case PhabricatorMacroTransaction::TYPE_FILE:
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO:
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR:
|
||||
return $xaction->getNewValue();
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyCustomInternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransaction::TYPE_NAME:
|
||||
$object->setName($xaction->getNewValue());
|
||||
break;
|
||||
case PhabricatorMacroTransaction::TYPE_DISABLED:
|
||||
$object->setIsDisabled($xaction->getNewValue());
|
||||
break;
|
||||
case PhabricatorMacroTransaction::TYPE_FILE:
|
||||
$object->setFilePHID($xaction->getNewValue());
|
||||
break;
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO:
|
||||
$object->setAudioPHID($xaction->getNewValue());
|
||||
break;
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR:
|
||||
$object->setAudioBehavior($xaction->getNewValue());
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
protected function applyCustomExternalTransaction(
|
||||
PhabricatorLiskDAO $object,
|
||||
PhabricatorApplicationTransaction $xaction) {
|
||||
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransaction::TYPE_FILE:
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO:
|
||||
case PhabricatorMacroFileTransaction::TRANSACTIONTYPE:
|
||||
case PhabricatorMacroAudioTransaction::TRANSACTIONTYPE:
|
||||
// When changing a macro's image or audio, attach the underlying files
|
||||
// to the macro (and detach the old files).
|
||||
$old = $xaction->getOldValue();
|
||||
|
@ -117,34 +56,9 @@ final class PhabricatorMacroEditor
|
|||
}
|
||||
}
|
||||
|
||||
protected function mergeTransactions(
|
||||
PhabricatorApplicationTransaction $u,
|
||||
PhabricatorApplicationTransaction $v) {
|
||||
|
||||
$type = $u->getTransactionType();
|
||||
switch ($type) {
|
||||
case PhabricatorMacroTransaction::TYPE_NAME:
|
||||
case PhabricatorMacroTransaction::TYPE_DISABLED:
|
||||
case PhabricatorMacroTransaction::TYPE_FILE:
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO:
|
||||
case PhabricatorMacroTransaction::TYPE_AUDIO_BEHAVIOR:
|
||||
return $v;
|
||||
}
|
||||
|
||||
return parent::mergeTransactions($u, $v);
|
||||
}
|
||||
|
||||
protected function shouldSendMail(
|
||||
PhabricatorLiskDAO $object,
|
||||
array $xactions) {
|
||||
foreach ($xactions as $xaction) {
|
||||
switch ($xaction->getTransactionType()) {
|
||||
case PhabricatorMacroTransaction::TYPE_NAME;
|
||||
return ($xaction->getOldValue() !== null);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
|
|
|
@ -1,14 +1,7 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroTransaction
|
||||
extends PhabricatorApplicationTransaction {
|
||||
|
||||
const TYPE_NAME = 'macro:name';
|
||||
const TYPE_DISABLED = 'macro:disabled';
|
||||
const TYPE_FILE = 'macro:file';
|
||||
|
||||
const TYPE_AUDIO = 'macro:audio';
|
||||
const TYPE_AUDIO_BEHAVIOR = 'macro:audiobehavior';
|
||||
extends PhabricatorModularTransaction {
|
||||
|
||||
public function getApplicationName() {
|
||||
return 'file';
|
||||
|
@ -26,284 +19,8 @@ final class PhabricatorMacroTransaction
|
|||
return new PhabricatorMacroTransactionComment();
|
||||
}
|
||||
|
||||
public function getRequiredHandlePHIDs() {
|
||||
$phids = parent::getRequiredHandlePHIDs();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_FILE:
|
||||
case self::TYPE_AUDIO:
|
||||
if ($old !== null) {
|
||||
$phids[] = $old;
|
||||
}
|
||||
$phids[] = $new;
|
||||
break;
|
||||
}
|
||||
|
||||
return $phids;
|
||||
}
|
||||
|
||||
public function shouldHide() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
return ($old === null);
|
||||
}
|
||||
|
||||
return parent::shouldHide();
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
return pht(
|
||||
'%s renamed this macro from "%s" to "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$old,
|
||||
$new);
|
||||
break;
|
||||
case self::TYPE_DISABLED:
|
||||
if ($new) {
|
||||
return pht(
|
||||
'%s disabled this macro.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s restored this macro.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
}
|
||||
break;
|
||||
|
||||
case self::TYPE_AUDIO:
|
||||
if (!$old) {
|
||||
return pht(
|
||||
'%s attached audio: %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($new));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the audio for this macro from %s to %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($old),
|
||||
$this->renderHandleLink($new));
|
||||
}
|
||||
|
||||
case self::TYPE_AUDIO_BEHAVIOR:
|
||||
switch ($new) {
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
||||
return pht(
|
||||
'%s set the audio to play once.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
||||
return pht(
|
||||
'%s set the audio to loop.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
default:
|
||||
return pht(
|
||||
'%s disabled the audio for this macro.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
}
|
||||
|
||||
case self::TYPE_FILE:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created this macro.',
|
||||
$this->renderHandleLink($author_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the image for this macro from %s to %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($old),
|
||||
$this->renderHandleLink($new));
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
return parent::getTitle();
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$author_phid = $this->getAuthorPHID();
|
||||
$object_phid = $this->getObjectPHID();
|
||||
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
return pht(
|
||||
'%s renamed %s from "%s" to "%s".',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid),
|
||||
$old,
|
||||
$new);
|
||||
case self::TYPE_DISABLED:
|
||||
if ($new) {
|
||||
return pht(
|
||||
'%s disabled %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s restored %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
case self::TYPE_FILE:
|
||||
if ($old === null) {
|
||||
return pht(
|
||||
'%s created %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
} else {
|
||||
return pht(
|
||||
'%s updated the image for %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
|
||||
case self::TYPE_AUDIO:
|
||||
if (!$old) {
|
||||
return pht(
|
||||
'%s attached audio to %s: %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid),
|
||||
$this->renderHandleLink($new));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the audio for %s from %s to %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid),
|
||||
$this->renderHandleLink($old),
|
||||
$this->renderHandleLink($new));
|
||||
}
|
||||
|
||||
case self::TYPE_AUDIO_BEHAVIOR:
|
||||
switch ($new) {
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
||||
return pht(
|
||||
'%s set the audio for %s to play once.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
||||
return pht(
|
||||
'%s set the audio for %s to loop.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
default:
|
||||
return pht(
|
||||
'%s disabled the audio for %s.',
|
||||
$this->renderHandleLink($author_phid),
|
||||
$this->renderHandleLink($object_phid));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
return parent::getTitleForFeed();
|
||||
}
|
||||
|
||||
public function getActionName() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
if ($old === null) {
|
||||
return pht('Created');
|
||||
} else {
|
||||
return pht('Renamed');
|
||||
}
|
||||
case self::TYPE_DISABLED:
|
||||
if ($new) {
|
||||
return pht('Disabled');
|
||||
} else {
|
||||
return pht('Restored');
|
||||
}
|
||||
case self::TYPE_FILE:
|
||||
if ($old === null) {
|
||||
return pht('Created');
|
||||
} else {
|
||||
return pht('Edited Image');
|
||||
}
|
||||
|
||||
case self::TYPE_AUDIO:
|
||||
return pht('Audio');
|
||||
|
||||
case self::TYPE_AUDIO_BEHAVIOR:
|
||||
return pht('Audio Behavior');
|
||||
|
||||
}
|
||||
|
||||
return parent::getActionName();
|
||||
}
|
||||
|
||||
public function getActionStrength() {
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_DISABLED:
|
||||
return 2.0;
|
||||
case self::TYPE_FILE:
|
||||
return 1.5;
|
||||
}
|
||||
return parent::getActionStrength();
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
return 'fa-pencil';
|
||||
case self::TYPE_FILE:
|
||||
if ($old === null) {
|
||||
return 'fa-plus';
|
||||
} else {
|
||||
return 'fa-pencil';
|
||||
}
|
||||
case self::TYPE_DISABLED:
|
||||
if ($new) {
|
||||
return 'fa-times';
|
||||
} else {
|
||||
return 'fa-undo';
|
||||
}
|
||||
case self::TYPE_AUDIO:
|
||||
return 'fa-headphones';
|
||||
}
|
||||
|
||||
return parent::getIcon();
|
||||
}
|
||||
|
||||
public function getColor() {
|
||||
$old = $this->getOldValue();
|
||||
$new = $this->getNewValue();
|
||||
|
||||
switch ($this->getTransactionType()) {
|
||||
case self::TYPE_NAME:
|
||||
return PhabricatorTransactions::COLOR_BLUE;
|
||||
case self::TYPE_FILE:
|
||||
if ($old === null) {
|
||||
return PhabricatorTransactions::COLOR_GREEN;
|
||||
} else {
|
||||
return PhabricatorTransactions::COLOR_BLUE;
|
||||
}
|
||||
case self::TYPE_DISABLED:
|
||||
if ($new) {
|
||||
return PhabricatorTransactions::COLOR_RED;
|
||||
} else {
|
||||
return PhabricatorTransactions::COLOR_SKY;
|
||||
}
|
||||
}
|
||||
|
||||
return parent::getColor();
|
||||
public function getBaseTransactionClass() {
|
||||
return 'PhabricatorMacroTransactionType';
|
||||
}
|
||||
|
||||
|
||||
|
|
|
@ -0,0 +1,69 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroAudioBehaviorTransaction
|
||||
extends PhabricatorMacroTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'macro:audiobehavior';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getAudioBehavior();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setAudioBehavior($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$new = $this->getNewValue();
|
||||
$old = $this->getOldValue();
|
||||
switch ($new) {
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
||||
return pht(
|
||||
'%s set the audio to play once.',
|
||||
$this->renderAuthor());
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
||||
return pht(
|
||||
'%s set the audio to loop.',
|
||||
$this->renderAuthor());
|
||||
default:
|
||||
return pht(
|
||||
'%s disabled the audio for this macro.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
$old = $this->getOldValue();
|
||||
switch ($new) {
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
||||
return pht(
|
||||
'%s set the audio for %s to play once.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
||||
return pht(
|
||||
'%s set the audio for %s to loop.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
default:
|
||||
return pht(
|
||||
'%s disabled the audio for %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
$new = $this->getNewValue();
|
||||
switch ($new) {
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_ONCE:
|
||||
return 'fa-play-circle';
|
||||
case PhabricatorFileImageMacro::AUDIO_BEHAVIOR_LOOP:
|
||||
return 'fa-repeat';
|
||||
default:
|
||||
return 'fa-pause-circle';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,56 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroAudioTransaction
|
||||
extends PhabricatorMacroTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'macro:audio';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getAudioPHID();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setAudioPHID($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
$new = $this->getNewValue();
|
||||
$old = $this->getOldValue();
|
||||
if (!$old) {
|
||||
return pht(
|
||||
'%s attached audio: %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderHandle($new));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the audio for this macro from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderHandle($old),
|
||||
$this->renderHandle($new));
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
$new = $this->getNewValue();
|
||||
$old = $this->getOldValue();
|
||||
if (!$old) {
|
||||
return pht(
|
||||
'%s attached audio to %s: %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderHandle($new));
|
||||
} else {
|
||||
return pht(
|
||||
'%s changed the audio for %s from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderHandle($old),
|
||||
$this->renderHandle($new));
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return 'fa-music';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,50 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroDisabledTransaction
|
||||
extends PhabricatorMacroTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'macro:disabled';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getIsDisabled();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setIsDisabled($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
if ($this->getNewValue()) {
|
||||
return pht(
|
||||
'%s disabled this macro.',
|
||||
$this->renderAuthor());
|
||||
} else {
|
||||
return pht(
|
||||
'%s restored this macro.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
if ($this->getNewValue()) {
|
||||
return pht(
|
||||
'%s disabled %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
} else {
|
||||
return pht(
|
||||
'%s restored %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
if ($this->getNewValue()) {
|
||||
return 'fa-ban';
|
||||
} else {
|
||||
return 'fa-check';
|
||||
}
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,33 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroFileTransaction
|
||||
extends PhabricatorMacroTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'macro:file';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getFilePHID();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setFilePHID($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s changed the image for this macro.',
|
||||
$this->renderAuthor());
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
return pht(
|
||||
'%s changed the image for macro %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject());
|
||||
}
|
||||
|
||||
public function getIcon() {
|
||||
return 'fa-file-image-o';
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,55 @@
|
|||
<?php
|
||||
|
||||
final class PhabricatorMacroNameTransaction
|
||||
extends PhabricatorMacroTransactionType {
|
||||
|
||||
const TRANSACTIONTYPE = 'macro:name';
|
||||
|
||||
public function generateOldValue($object) {
|
||||
return $object->getName();
|
||||
}
|
||||
|
||||
public function applyInternalEffects($object, $value) {
|
||||
$object->setName($value);
|
||||
}
|
||||
|
||||
public function getTitle() {
|
||||
return pht(
|
||||
'%s renamed this macro from %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderOldValue(),
|
||||
$this->renderNewValue());
|
||||
}
|
||||
|
||||
public function getTitleForFeed() {
|
||||
return pht(
|
||||
'%s renamed %s macro %s to %s.',
|
||||
$this->renderAuthor(),
|
||||
$this->renderObject(),
|
||||
$this->renderOldValue(),
|
||||
$this->renderNewValue());
|
||||
}
|
||||
|
||||
public function validateTransactions($object, array $xactions) {
|
||||
$errors = array();
|
||||
|
||||
if ($this->isEmptyTextTransaction($object->getName(), $xactions)) {
|
||||
$errors[] = $this->newRequiredError(
|
||||
pht('Macros must have a name.'));
|
||||
}
|
||||
|
||||
$max_length = $object->getColumnMaximumByteLength('name');
|
||||
foreach ($xactions as $xaction) {
|
||||
$new_value = $xaction->getNewValue();
|
||||
$new_length = strlen($new_value);
|
||||
if ($new_length > $max_length) {
|
||||
$errors[] = $this->newInvalidError(
|
||||
pht('The name can be no longer than %s characters.',
|
||||
new PhutilNumber($max_length)));
|
||||
}
|
||||
}
|
||||
|
||||
return $errors;
|
||||
}
|
||||
|
||||
}
|
|
@ -0,0 +1,4 @@
|
|||
<?php
|
||||
|
||||
abstract class PhabricatorMacroTransactionType
|
||||
extends PhabricatorModularTransactionType {}
|
Loading…
Reference in a new issue