2012-10-07 23:35:01 +02:00
|
|
|
<?php
|
|
|
|
|
2012-10-10 19:18:23 +02:00
|
|
|
final class PonderQuestionEditor extends PhabricatorEditor {
|
2012-10-07 23:35:01 +02:00
|
|
|
|
|
|
|
private $question;
|
2012-10-08 23:47:21 +02:00
|
|
|
private $shouldEmail = true;
|
2012-10-07 23:35:01 +02:00
|
|
|
|
|
|
|
public function setQuestion(PonderQuestion $question) {
|
|
|
|
$this->question = $question;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-08 23:47:21 +02:00
|
|
|
public function setShouldEmail($se) {
|
|
|
|
$this->shouldEmail = $se;
|
|
|
|
return $this;
|
|
|
|
}
|
|
|
|
|
2012-10-07 23:35:01 +02:00
|
|
|
public function save() {
|
2012-10-10 19:18:23 +02:00
|
|
|
$actor = $this->requireActor();
|
2012-10-07 23:35:01 +02:00
|
|
|
if (!$this->question) {
|
|
|
|
throw new Exception("Must set question before saving it");
|
|
|
|
}
|
|
|
|
|
|
|
|
$question = $this->question;
|
|
|
|
$question->save();
|
|
|
|
|
2012-10-08 23:47:21 +02:00
|
|
|
// search index
|
2012-10-07 23:35:01 +02:00
|
|
|
$question->attachRelated();
|
|
|
|
PhabricatorSearchPonderIndexer::indexQuestion($question);
|
2012-10-08 23:47:21 +02:00
|
|
|
|
|
|
|
// subscribe author and @mentions
|
|
|
|
$subeditor = id(new PhabricatorSubscriptionsEditor())
|
|
|
|
->setObject($question)
|
2012-10-10 19:18:23 +02:00
|
|
|
->setActor($actor);
|
2012-10-08 23:47:21 +02:00
|
|
|
|
|
|
|
$subeditor->subscribeExplicit(array($question->getAuthorPHID()));
|
|
|
|
|
|
|
|
$content = $question->getContent();
|
|
|
|
$at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(
|
|
|
|
array($content)
|
|
|
|
);
|
|
|
|
$subeditor->subscribeImplicit($at_mention_phids);
|
|
|
|
$subeditor->save();
|
|
|
|
|
|
|
|
if ($this->shouldEmail && $at_mention_phids) {
|
|
|
|
id(new PonderMentionMail(
|
|
|
|
$question,
|
|
|
|
$question,
|
2012-10-10 19:18:23 +02:00
|
|
|
$actor))
|
2012-10-08 23:47:21 +02:00
|
|
|
->setToPHIDs($at_mention_phids)
|
|
|
|
->send();
|
|
|
|
}
|
2012-10-07 23:35:01 +02:00
|
|
|
}
|
|
|
|
}
|