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

68 lines
1.7 KiB
PHP
Raw Normal View History

<?php
/*
* Copyright 2012 Facebook, Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
final class PonderAnswerEditor {
private $question;
private $answer;
public function setQuestion($question) {
$this->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);
}
}