Differential D20287 Diff 48426 src/applications/project/xaction/column/PhabricatorProjectColumnTriggerTransaction.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/project/xaction/column/PhabricatorProjectColumnTriggerTransaction.php
- This file was added.
<?php | |||||
final class PhabricatorProjectColumnTriggerTransaction | |||||
extends PhabricatorProjectColumnTransactionType { | |||||
const TRANSACTIONTYPE = 'trigger'; | |||||
amckinley: Just out of curiosity, what's the scope on these constants? Do they need to be globally unique? | |||||
epriestleyAuthorUnsubmitted Done Inline ActionsThey only have to be unique per object type. Some of the older stuff namespaces them heavily, but in practice all the transaction stuff is sharded into per-object tables anyway and there's no transaction.search mode which says "give me every subscription change to every object ever", nor is there likely to ever be, I think. I currently believe the handful of cases for this are probably better served by fact extraction in the Facts ETL pipeline, so we don't have to run 250 queries against every single whatever.transaction table. epriestley: They only have to be unique per object type.
Some of the older stuff namespaces them heavily… | |||||
public function generateOldValue($object) { | |||||
return $object->getTriggerPHID(); | |||||
} | |||||
public function applyInternalEffects($object, $value) { | |||||
$object->setTriggerPHID($value); | |||||
} | |||||
public function getTitle() { | |||||
$old = $this->getOldValue(); | |||||
$new = $this->getNewValue(); | |||||
if (!$old) { | |||||
return pht( | |||||
'%s set the column trigger to %s.', | |||||
$this->renderAuthor(), | |||||
$this->renderNewHandle()); | |||||
} else if (!$new) { | |||||
return pht( | |||||
'%s removed the trigger for this column (was %s).', | |||||
$this->renderAuthor(), | |||||
$this->renderOldHandle()); | |||||
} else { | |||||
return pht( | |||||
'%s changed the trigger for this column from %s to %s.', | |||||
$this->renderAuthor(), | |||||
$this->renderOldHandle(), | |||||
$this->renderNewHandle()); | |||||
} | |||||
} | |||||
public function validateTransactions($object, array $xactions) { | |||||
$actor = $this->getActor(); | |||||
$errors = array(); | |||||
foreach ($xactions as $xaction) { | |||||
$trigger_phid = $xaction->getNewValue(); | |||||
// You can always remove a trigger. | |||||
if (!$trigger_phid) { | |||||
continue; | |||||
} | |||||
// You can't put a trigger on a column that can't have triggers, like | |||||
// a backlog column or a proxy column. | |||||
if (!$object->canHaveTrigger()) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht('This column can not have a trigger.'), | |||||
$xaction); | |||||
continue; | |||||
} | |||||
$trigger = id(new PhabricatorProjectTriggerQuery()) | |||||
->setViewer($actor) | |||||
->withPHIDs(array($trigger_phid)) | |||||
->execute(); | |||||
if (!$trigger) { | |||||
$errors[] = $this->newInvalidError( | |||||
pht( | |||||
'Trigger "%s" is not a valid trigger, or you do not have '. | |||||
'permission to view it.', | |||||
$trigger_phid), | |||||
$xaction); | |||||
continue; | |||||
} | |||||
} | |||||
return $errors; | |||||
} | |||||
} |
Just out of curiosity, what's the scope on these constants? Do they need to be globally unique? Would we ever know if we reused one by accident? In practice I guess we scope transactions per-application since they have their own DBs anyway.