1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-28 17:52:43 +01:00
phorge-phorge/src/applications/ponder/editor/PonderAnswerEditor.php

100 lines
2.6 KiB
PHP
Raw Normal View History

<?php
final class PonderAnswerEditor extends PhabricatorEditor {
private $question;
private $answer;
private $shouldEmail = true;
public function setQuestion($question) {
$this->question = $question;
return $this;
}
public function setAnswer($answer) {
$this->answer = $answer;
return $this;
}
public function saveAnswer() {
$actor = $this->requireActor();
if (!$this->question) {
throw new Exception("Must set question before saving answer");
}
if (!$this->answer) {
throw new Exception("Must set answer before saving it");
}
$question = $this->question;
$answer = $this->answer;
$conn = $answer->establishConnection('w');
$trans = $conn->openTransaction();
$trans->beginReadLocking();
$question->reload();
queryfx($conn,
'UPDATE %T as t
SET t.`answerCount` = t.`answerCount` + 1
WHERE t.`PHID` = %s',
$question->getTableName(),
$question->getPHID());
$answer->setQuestionID($question->getID());
$answer->save();
$trans->endReadLocking();
$trans->saveTransaction();
$question->attachRelated();
Improve Search architecture Summary: The search indexing API has several problems right now: - Always runs in-process. - It would be nice to push this into the task queue for performance. However, the API currently passses an object all the way through (and some indexers depend on preloaded object attributes), so it can't be dumped into the task queue at any stage since we can't serialize it. - Being able to use the task queue will also make rebuilding indexes faster. - Instead, make the API phid-oriented. - No uniform indexing API. - Each "Editor" currently calls SomeCustomIndexer::indexThing(). This won't work with AbstractTransactions. The API is also just weird. - Instead, provide a uniform API. - No uniform CLI. - We have `scripts/search/reindex_everything.php`, but it doesn't actually index everything. Each new document type needs to be separately added to it, leading to stuff like D3839. Third-party applications can't provide indexers. - Instead, let indexers expose documents for indexing. - Not application-oriented. - All the indexers live in search/ right now, which isn't the right organization in an application-orietned view of the world. - Instead, move indexers to applications and load them with SymbolLoader. Test Plan: - `bin/search index` - Indexed one revision, one task. - Indexed `--type TASK`, `--type DREV`, etc., for all types. - Indexed `--all`. - Added the word "saboteur" to a revision, task, wiki page, and question and then searched for it. - Creating users is a pain; searched for a user after indexing. - Creating commits is a pain; searched for a commit after indexing. - Mocks aren't currently loadable in the result view, so their indexing is moot. Reviewers: btrahan, vrana Reviewed By: btrahan CC: 20after4, aran Maniphest Tasks: T1991, T2104 Differential Revision: https://secure.phabricator.com/D4261
2012-12-21 23:21:31 +01:00
id(new PhabricatorSearchIndexer())
->indexDocumentByPHID($question->getPHID());
// subscribe author and @mentions
$subeditor = id(new PhabricatorSubscriptionsEditor())
->setObject($question)
->setActor($actor);
$subeditor->subscribeExplicit(array($answer->getAuthorPHID()));
$content = $answer->getContent();
$at_mention_phids = PhabricatorMarkupEngine::extractPHIDsFromMentions(
array($content));
$subeditor->subscribeImplicit($at_mention_phids);
$subeditor->save();
if ($this->shouldEmail) {
// now load subscribers, including implicitly-added @mention victims
$subscribers = PhabricatorSubscribersQuery
::loadSubscribersForPHID($question->getPHID());
// @mention emails (but not for anyone who has explicitly unsubscribed)
if (array_intersect($at_mention_phids, $subscribers)) {
id(new PonderMentionMail(
$question,
$answer,
$actor))
->setToPHIDs($at_mention_phids)
->send();
}
$other_subs =
array_diff(
$subscribers,
$at_mention_phids);
// 'Answered' emails for subscribers who are not @mentiond (and excluding
// author depending on their MetaMTA settings).
if ($other_subs) {
id(new PonderAnsweredMail(
$question,
$answer,
$actor))
->setToPHIDs($other_subs)
->send();
}
}
}
}