question = $question; return $this; } public function setAnswer($answer) { $this->answer = $answer; return $this; } public function saveAnswer() { 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(); PhabricatorSearchPonderIndexer::indexQuestion($question); } }