EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/106466
Change subject: Utilize Post::getRootPost instead of TreeRepository
......................................................................
Utilize Post::getRootPost instead of TreeRepository
The addition of Post::getRootPost allows to not use
TreeRepository in a few instances.
Change-Id: I5a432a9c461ef0bcec8f78894edbd7cd31a1e042
---
M includes/Data/RecentChanges.php
M includes/Log/PostModerationLogger.php
M includes/Model/PostRevision.php
M includes/View/History/HistoryRenderer.php
4 files changed, 12 insertions(+), 30 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/66/106466/1
diff --git a/includes/Data/RecentChanges.php b/includes/Data/RecentChanges.php
index 5c43ee2..8b86223 100644
--- a/includes/Data/RecentChanges.php
+++ b/includes/Data/RecentChanges.php
@@ -158,12 +158,8 @@
}
public function onAfterInsert( $object, array $row ) {
- // There might be a more efficient way to get this workflow id
- $workflowId = $this->tree->findRoot( $object->getPostId() );
- if ( !$workflowId ) {
- wfWarn( __METHOD__ . ": could not locate root for post
" . $object->getPostId()->getHex() );
- return;
- }
+ // The workflow id is the same as the root's post id
+ $workflowId = $object->getRootPost()->getPostId();
// These are likely already in the in-process cache
$workflow = $this->storage->get( 'Workflow', $workflowId );
if ( !$workflow ) {
@@ -187,23 +183,7 @@
}
protected function getTopicTitle( PostRevision $rev ) {
- if ( $rev->isTopicTitle() ) {
- return $rev->getContent( 'wikitext' );
- }
- $topicTitleId = $this->tree->findRoot( $rev->getPostId() );
- if ( $topicTitleId === null ) {
- return null;
- }
- $found = $this->storage->find(
- 'PostRevision',
- array( 'tree_rev_descendant_id' => $topicTitleId ),
- array( 'sort' => 'rev_id', 'order' => 'DESC', 'limit'
=> 1 )
- );
- if ( !$found ) {
- return null;
- }
-
- $content = reset( $found )->getContent( 'wikitext' );
+ $content = $rev->getRootPost()->getContent( 'wikitext' );
if ( is_object( $content ) ) {
// moderated
return null;
diff --git a/includes/Log/PostModerationLogger.php
b/includes/Log/PostModerationLogger.php
index 29ffc89..4a56234 100644
--- a/includes/Log/PostModerationLogger.php
+++ b/includes/Log/PostModerationLogger.php
@@ -23,9 +23,8 @@
}
if ( $this->logger->canLog( $object, $object->getChangeType() )
) {
- // This is awful but it's all I can think of
- $rootPost = $this->treeRepo->findRoot(
$object->getPostId() );
- $workflow = $this->storage->get( 'Workflow', $rootPost
);
+ $rootPostId = $object->getRootPost()->getPostId();
+ $workflow = $this->storage->get( 'Workflow',
$rootPostId );
$logParams = array();
if ( $object->isTopicTitle() ) {
@@ -74,4 +73,4 @@
return $changeTypes;
}
-}
\ No newline at end of file
+}
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index 401cae9..3285172 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -170,9 +170,12 @@
}
public function getRootPost() {
- if ( $this->rootPost === null ) {
- throw new DataModelException( 'Depth not loaded for
post: ' . $this->postId->getHex(), 'process-data' );
+ if ( $this->isTopicTitle() ) {
+ return $this;
+ } elseif ( $this->rootPost === null ) {
+ throw new DataModelException( 'Root not loaded for
post: ' . $this->postId->getHex(), 'process-data' );
}
+
return $this->rootPost;
}
diff --git a/includes/View/History/HistoryRenderer.php
b/includes/View/History/HistoryRenderer.php
index c4b0804..b1a677e 100644
--- a/includes/View/History/HistoryRenderer.php
+++ b/includes/View/History/HistoryRenderer.php
@@ -156,7 +156,7 @@
// Board history
} else {
if ( $revision->getRevisionType() === 'post' ) {
- $workFlowId = \Flow\Container::get(
'repository.tree' )->findRoot( $revision->getPostId() );
+ $workflowId =
$revision->getRootPost()->getPostId();
} else {
$workFlowId =
$revision->getWorkflowId();
}
--
To view, visit https://gerrit.wikimedia.org/r/106466
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5a432a9c461ef0bcec8f78894edbd7cd31a1e042
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: EBernhardson <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits