Differential D10451 Diff 25146 src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/transactions/editor/PhabricatorApplicationTransactionEditor.php
Show All 15 Lines | abstract class PhabricatorApplicationTransactionEditor | ||||
private $isNewObject; | private $isNewObject; | ||||
private $mentionedPHIDs; | private $mentionedPHIDs; | ||||
private $continueOnNoEffect; | private $continueOnNoEffect; | ||||
private $continueOnMissingFields; | private $continueOnMissingFields; | ||||
private $parentMessageID; | private $parentMessageID; | ||||
private $heraldAdapter; | private $heraldAdapter; | ||||
private $heraldTranscript; | private $heraldTranscript; | ||||
private $subscribers; | private $subscribers; | ||||
private $unmentionablePHIDMap = array(); | |||||
private $isPreview; | private $isPreview; | ||||
private $isHeraldEditor; | private $isHeraldEditor; | ||||
private $isInverseEdgeEditor; | private $isInverseEdgeEditor; | ||||
private $actingAsPHID; | private $actingAsPHID; | ||||
private $disableEmail; | private $disableEmail; | ||||
▲ Show 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | public function setDisableEmail($disable_email) { | ||||
$this->disableEmail = $disable_email; | $this->disableEmail = $disable_email; | ||||
return $this; | return $this; | ||||
} | } | ||||
public function getDisableEmail() { | public function getDisableEmail() { | ||||
return $this->disableEmail; | return $this->disableEmail; | ||||
} | } | ||||
public function setUnmentionablePHIDMap(array $map) { | |||||
epriestley: Array typehint? | |||||
$this->unmentionablePHIDMap = $map; | |||||
return $this; | |||||
} | |||||
public function getUnmentionablePHIDMap() { | |||||
return $this->unmentionablePHIDMap; | |||||
} | |||||
public function getTransactionTypes() { | public function getTransactionTypes() { | ||||
$types = array(); | $types = array(); | ||||
if ($this->object instanceof PhabricatorSubscribableInterface) { | if ($this->object instanceof PhabricatorSubscribableInterface) { | ||||
$types[] = PhabricatorTransactions::TYPE_SUBSCRIBERS; | $types[] = PhabricatorTransactions::TYPE_SUBSCRIBERS; | ||||
} | } | ||||
if ($this->object instanceof PhabricatorCustomFieldInterface) { | if ($this->object instanceof PhabricatorCustomFieldInterface) { | ||||
▲ Show 20 Lines • Show All 822 Lines • ▼ Show 20 Lines | switch ($xaction->getTransactionType()) { | ||||
PhabricatorPolicyFilter::requireCapability( | PhabricatorPolicyFilter::requireCapability( | ||||
$actor, | $actor, | ||||
$object, | $object, | ||||
PhabricatorPolicyCapability::CAN_EDIT); | PhabricatorPolicyCapability::CAN_EDIT); | ||||
break; | break; | ||||
} | } | ||||
} | } | ||||
private function buildMentionTransaction( | private function buildSubscribeTransaction( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions, | array $xactions, | ||||
array $blocks) { | array $blocks) { | ||||
if (!($object instanceof PhabricatorSubscribableInterface)) { | if (!($object instanceof PhabricatorSubscribableInterface)) { | ||||
return null; | return null; | ||||
} | } | ||||
▲ Show 20 Lines • Show All 89 Lines • ▼ Show 20 Lines | private function expandSupportTransactions( | ||||
$xactions = $this->applyImplicitCC($object, $xactions); | $xactions = $this->applyImplicitCC($object, $xactions); | ||||
$blocks = array(); | $blocks = array(); | ||||
foreach ($xactions as $key => $xaction) { | foreach ($xactions as $key => $xaction) { | ||||
$blocks[$key] = $this->getRemarkupBlocksFromTransaction($xaction); | $blocks[$key] = $this->getRemarkupBlocksFromTransaction($xaction); | ||||
} | } | ||||
$mention_xaction = $this->buildMentionTransaction( | $subscribe_xaction = $this->buildSubscribeTransaction( | ||||
$object, | $object, | ||||
$xactions, | $xactions, | ||||
$blocks); | $blocks); | ||||
if ($mention_xaction) { | if ($subscribe_xaction) { | ||||
$xactions[] = $mention_xaction; | $xactions[] = $subscribe_xaction; | ||||
} | } | ||||
// TODO: For now, this is just a placeholder. | // TODO: For now, this is just a placeholder. | ||||
$engine = PhabricatorMarkupEngine::getEngine('extract'); | $engine = PhabricatorMarkupEngine::getEngine('extract'); | ||||
$engine->setConfig('viewer', $this->requireActor()); | $engine->setConfig('viewer', $this->requireActor()); | ||||
$block_xactions = $this->expandRemarkupBlockTransactions( | $block_xactions = $this->expandRemarkupBlockTransactions( | ||||
$object, | $object, | ||||
Show All 15 Lines | private function expandRemarkupBlockTransactions( | ||||
PhutilMarkupEngine $engine) { | PhutilMarkupEngine $engine) { | ||||
$block_xactions = $this->expandCustomRemarkupBlockTransactions( | $block_xactions = $this->expandCustomRemarkupBlockTransactions( | ||||
$object, | $object, | ||||
$xactions, | $xactions, | ||||
$blocks, | $blocks, | ||||
$engine); | $engine); | ||||
if ($object instanceof PhabricatorProjectInterface) { | $mentioned_phids = array(); | ||||
$phids = array(); | |||||
foreach ($blocks as $key => $xaction_blocks) { | foreach ($blocks as $key => $xaction_blocks) { | ||||
foreach ($xaction_blocks as $block) { | foreach ($xaction_blocks as $block) { | ||||
$engine->markupText($block); | $engine->markupText($block); | ||||
$phids += $engine->getTextMetadata( | $mentioned_phids += $engine->getTextMetadata( | ||||
PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS, | PhabricatorObjectRemarkupRule::KEY_MENTIONED_OBJECTS, | ||||
array()); | array()); | ||||
} | } | ||||
} | } | ||||
if (!$mentioned_phids) { | |||||
return $block_xactions; | |||||
} | |||||
if ($object instanceof PhabricatorProjectInterface) { | |||||
$phids = $mentioned_phids; | |||||
$project_type = PhabricatorProjectProjectPHIDType::TYPECONST; | $project_type = PhabricatorProjectProjectPHIDType::TYPECONST; | ||||
foreach ($phids as $key => $phid) { | foreach ($phids as $key => $phid) { | ||||
if (phid_get_type($phid) != $project_type) { | if (phid_get_type($phid) != $project_type) { | ||||
unset($phids[$key]); | unset($phids[$key]); | ||||
} | } | ||||
} | } | ||||
if ($phids) { | if ($phids) { | ||||
$edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; | $edge_type = PhabricatorProjectObjectHasProjectEdgeType::EDGECONST; | ||||
$block_xactions[] = newv(get_class(head($xactions)), array()) | $block_xactions[] = newv(get_class(head($xactions)), array()) | ||||
->setIgnoreOnNoEffect(true) | ->setIgnoreOnNoEffect(true) | ||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | ||||
->setMetadataValue('edge:type', $edge_type) | ->setMetadataValue('edge:type', $edge_type) | ||||
->setNewValue(array('+' => $phids)); | ->setNewValue(array('+' => $phids)); | ||||
} | } | ||||
} | } | ||||
$objects = id(new PhabricatorObjectQuery()) | |||||
->setViewer($this->getActor()) | |||||
->withPHIDs($mentioned_phids) | |||||
->execute(); | |||||
$mentionable_phids = array(); | |||||
foreach ($objects as $object) { | |||||
if ($object instanceof PhabricatorMentionableInterface) { | |||||
if (idx($this->getUnmentionablePHIDMap(), $object->getPHID())) { | |||||
continue; | |||||
} | |||||
$mentionable_phids[$object->getPHID()] = $object->getPHID(); | |||||
} | |||||
} | |||||
if ($mentionable_phids) { | |||||
$edge_type = PhabricatorObjectMentionsObject::EDGECONST; | |||||
$block_xactions[] = newv(get_class(head($xactions)), array()) | |||||
->setIgnoreOnNoEffect(true) | |||||
->setTransactionType(PhabricatorTransactions::TYPE_EDGE) | |||||
->setMetadataValue('edge:type', $edge_type) | |||||
->setNewValue(array('+' => $mentionable_phids)); | |||||
} | |||||
return $block_xactions; | return $block_xactions; | ||||
} | } | ||||
protected function expandCustomRemarkupBlockTransactions( | protected function expandCustomRemarkupBlockTransactions( | ||||
PhabricatorLiskDAO $object, | PhabricatorLiskDAO $object, | ||||
array $xactions, | array $xactions, | ||||
$blocks, | $blocks, | ||||
PhutilMarkupEngine $engine) { | PhutilMarkupEngine $engine) { | ||||
▲ Show 20 Lines • Show All 1,304 Lines • Show Last 20 Lines |
Array typehint?