示例#1
0
function insertIntoCommentsIndex($parentPageId, $articleComment, $parentCommentId = 0, $lastChildCommentId = 0)
{
    global $isDryrun;
    $data = array('parentPageId' => $parentPageId, 'commentId' => $articleComment->getTitle()->getArticleID(), 'parentCommentId' => intval($parentCommentId), 'lastChildCommentId' => intval($lastChildCommentId), 'firstRevId' => $articleComment->mFirstRevId, 'createdAt' => $articleComment->mFirstRevision->getTimestamp(), 'lastTouched' => $articleComment->mLastRevision->getTimestamp(), 'lastRevId' => $articleComment->mLastRevId);
    $data = array_merge($data, getCommentProperties($articleComment));
    $commentsIndex = new CommentsIndex($data);
    if (!$isDryrun) {
        $commentsIndex->addToDatabase();
    }
    return true;
}
示例#2
0
 /**
  * @group Slow
  * @slowExecutionTime 0.01076 ms
  * The purpose of CommentsIndex cache is avoid database queries for CommentsIndex instances that were created
  * during the request. So here we simulate inserting the CommentsIndex to the table and then ask for that id and
  * make sure it's not fetched from the database
  */
 public function testCommentsIndexCacheIsUsedForNewObjects()
 {
     $rowMock = $this->getFakeCommentsIndexRow(2);
     $dbMock = $this->getMock('stdClass', ['selectRow', 'replace', 'tableExists', 'timestamp']);
     $dbMock->expects($this->exactly(0))->method('selectRow')->will($this->returnValue($rowMock));
     $dbMock->expects($this->any())->method('replace')->will($this->returnValue(true));
     $dbMock->expects($this->any())->method('timestamp')->will($this->returnValue('20130102030405'));
     $dbMock->expects($this->any())->method('tableExists')->will($this->returnValue(true));
     $ci = new CommentsIndex(['commentId' => 2, 'parentPageId' => 3, 'parentCommentId' => 4], $dbMock);
     $ci->addToDatabase();
     //we pass the same $db connection so it's easier to compare objects
     $ci2 = CommentsIndex::newFromId(2, 0, $dbMock);
     // make sure the cached object has the same properties
     $this->assertEquals($ci, $ci2);
     //make sure we don't inherit the database connection form the original object
     $ci2 = CommentsIndex::newFromId(3);
     $this->assertNotEquals($ci, $ci2);
 }
示例#3
0
 /**
  * Hook into MW transaction that creates new article comments and execute queries that create comments_index entries
  * @param $dbw database connetion
  * @param Title $title newly created article
  * @param Revision $revision revision containig the lastest version of article comment
  * @param $flags Integer bitfield, the same as in WikiPage::doEdit method
  */
 public static function onArticleDoEdit($dbw, Title $title, Revision $revision, $flags)
 {
     global $wgEnableWallEngine;
     if (!empty($wgEnableWallEngine) && WallHelper::isWallNamespace($title->getNamespace())) {
         if ($flags & EDIT_NEW) {
             $titleText = $title->getText();
             if (isset(self::$commentInfoData[$titleText])) {
                 $data = array('namespace' => self::$commentInfoData[$titleText]->userPageTitle->getNamespace(), 'parentPageId' => self::$commentInfoData[$titleText]->userPageTitle->getArticleID(), 'commentId' => $title->getArticleID(), 'parentCommentId' => intval(self::$commentInfoData[$titleText]->parentId), 'firstRevId' => $revision->getId(), 'lastRevId' => $revision->getId());
                 $commentsIndex = new CommentsIndex($data, $dbw);
                 $commentsIndex->addToDatabase();
                 $commentsIndex->updateParentLastCommentId($data['commentId']);
             }
         } else {
             $commentsIndex = CommentsIndex::newFromId($title->getArticleID(), 0, $dbw);
             if ($commentsIndex instanceof CommentsIndex) {
                 $commentsIndex->updateLastRevId($revision->getId());
             }
         }
     }
     return true;
 }