EBernhardson has uploaded a new change for review. https://gerrit.wikimedia.org/r/150256
Change subject: Hygine: Cleanup recent change listeners ...................................................................... Hygine: Cleanup recent change listeners Change-Id: I44dfbb7896464d9b34326fe452fa921633b873e6 --- M container.php M includes/Data/HeaderRecentChanges.php M includes/Data/PostRevisionRecentChanges.php M includes/Data/PostSummaryRecentChanges.php 4 files changed, 28 insertions(+), 63 deletions(-) git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow refs/changes/56/150256/1 diff --git a/container.php b/container.php index 4e56ae5..c9a9f1c 100644 --- a/container.php +++ b/container.php @@ -231,7 +231,6 @@ new Flow\Data\HeaderRecentChanges( $c['flow_actions'], $c['repository.username'], - $c['storage'], $wgContLang ), $c['storage.board_history.index'], @@ -291,7 +290,6 @@ new Flow\Data\PostSummaryRecentChanges( $c['flow_actions'], $c['repository.username'], - $c['storage'], $wgContLang ), new Flow\Data\UserNameListener( @@ -393,7 +391,11 @@ $user = $c['user']; $handlers = array( new Flow\Log\PostModerationLogger( $c['logger'] ), - new Flow\Data\PostRevisionRecentChanges( $c['flow_actions'], $c['repository.username'], $c['storage'], $c['repository.tree'], $wgContLang ), + new Flow\Data\PostRevisionRecentChanges( + $c['flow_actions'], + $c['repository.username'], + $wgContLang + ), $c['storage.board_history.index'], new Flow\Data\UserNameListener( $c['repository.username'], diff --git a/includes/Data/HeaderRecentChanges.php b/includes/Data/HeaderRecentChanges.php index a926ae4..ca4f9f9 100644 --- a/includes/Data/HeaderRecentChanges.php +++ b/includes/Data/HeaderRecentChanges.php @@ -2,6 +2,7 @@ namespace Flow\Data; +use Flow\Exception\FlowException; use Flow\FlowActions; use Flow\Model\Header; use Flow\Parsoid\Utils; @@ -9,18 +10,12 @@ class HeaderRecentChanges extends RecentChanges { /** - * @var ManagerGroup - */ - protected $storage; - - /** * @var Language Content Language */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, ManagerGroup $storage, Language $contLang ) { + public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { parent::__construct( $actions, $usernames ); - $this->storage = $storage; $this->contLang = $contLang; } @@ -31,10 +26,8 @@ public function onAfterInsert( $object, array $row, array $metadata ) { $workflowId = $object->getWorkflowId(); $workflow = $this->storage->get( 'Workflow', $workflowId ); - if ( !$workflow ) { - // unless in unit test, write to log - wfDebugLog( 'Flow', __METHOD__ . ": could not locate workflow for header " . $object->getRevisionId()->getAlphadecimal() ); - return; + if ( !isset( $metadata['workflow'] ) ) { + throw new FlowException( 'Missing required metadata: workflow' ); } $this->insert( @@ -42,7 +35,7 @@ 'header', 'Header', $row, - $workflow, + $metadata['workflow'], array( 'content' => Utils::htmlToPlaintext( $object->getContent(), diff --git a/includes/Data/PostRevisionRecentChanges.php b/includes/Data/PostRevisionRecentChanges.php index 5a78969..57a47f5 100644 --- a/includes/Data/PostRevisionRecentChanges.php +++ b/includes/Data/PostRevisionRecentChanges.php @@ -2,31 +2,19 @@ namespace Flow\Data; +use Flow\Exception\FlowException; use Flow\FlowActions; use Flow\Model\PostRevision; -use Flow\Repository\TreeRepository; use Language; class PostRevisionRecentChanges extends RecentChanges { - /** - * @var ManagerGroup - */ - protected $storage; - - /** - * @var TreeRepository - */ - protected $tree; - /** * @var Language */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, ManagerGroup $storage, TreeRepository $tree, Language $contLang ) { + public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { parent::__construct( $actions, $usernames ); - $this->storage = $storage; - $this->tree = $tree; $this->contLang = $contLang; } @@ -35,36 +23,28 @@ * @param string[] $row */ public function onAfterInsert( $object, array $row, array $metadata ) { - // 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 ) { - // unless in unit test, write to log - wfDebugLog( 'Flow', __METHOD__ . ": could not locate workflow " . $workflowId->getAlphadecimal() ); - return; + if ( !isset( $metadata['workflow'] ) ) { + throw new FlowException( 'Missing required metadata: workflow' ); } + if ( !isset( $metadata['topic-title'] ) ) { + throw new FlowException( 'Missing required metadata: topic-title' ); + } + + $topic = $this->contLang->truncate( + $metadata['topic-title']->getContent( 'wikitext' ), + self::TRUNCATE_LENGTH + ); $this->insert( $object, 'topic', 'PostRevision', $row, - $workflow, + $metadata['workflow'], array( 'post' => $object->getPostId()->getAlphadecimal(), - 'topic' => $this->getTopicTitle( $object ), + 'topic' => $topic, ) ); - } - - protected function getTopicTitle( PostRevision $rev ) { - $content = $rev->getRootPost()->getContent( 'wikitext' ); - if ( is_object( $content ) ) { - // moderated - return null; - } - - return $this->contLang->truncate( $content, self::TRUNCATE_LENGTH ); } } diff --git a/includes/Data/PostSummaryRecentChanges.php b/includes/Data/PostSummaryRecentChanges.php index 973d5f0..9b07618 100644 --- a/includes/Data/PostSummaryRecentChanges.php +++ b/includes/Data/PostSummaryRecentChanges.php @@ -8,18 +8,12 @@ class PostSummaryRecentChanges extends RecentChanges { /** - * @var ManagerGroup - */ - protected $storage; - - /** * @var Language Content Language */ protected $contLang; - public function __construct( FlowActions $actions, UserNameBatch $usernames, ManagerGroup $storage, Language $contLang ) { + public function __construct( FlowActions $actions, UserNameBatch $usernames, Language $contLang ) { parent::__construct( $actions, $usernames ); - $this->storage = $storage; $this->contLang = $contLang; } @@ -28,12 +22,8 @@ * @param string[] $row */ public function onAfterInsert( $object, array $row, array $metadata ) { - $workflowId = $object->getCollection()->getWorkflowId(); - $workflow = $this->storage->get( 'Workflow', $workflowId ); - if ( !$workflow ) { - // unless in unit test, write to log - wfDebugLog( 'Flow', __METHOD__ . ": could not locate workflow for post summary " . $object->getRevisionId()->getAlphadecimal() ); - return; + if ( !isset( $metadata['workflow'] ) ) { + throw new FlowException( 'Missing required metadata: workflow' ); } $this->insert( @@ -41,7 +31,7 @@ 'topicsummary', 'PostSummary', $row, - $workflow, + $metadata['workflow'], array( 'content' => $this->contLang->truncate( $object->getContent(), self::TRUNCATE_LENGTH ), 'rev_type_id' => $object->getCollectionId()->getAlphadecimal() -- To view, visit https://gerrit.wikimedia.org/r/150256 To unsubscribe, visit https://gerrit.wikimedia.org/r/settings Gerrit-MessageType: newchange Gerrit-Change-Id: I44dfbb7896464d9b34326fe452fa921633b873e6 Gerrit-PatchSet: 1 Gerrit-Project: mediawiki/extensions/Flow Gerrit-Branch: master Gerrit-Owner: EBernhardson <ebernhard...@wikimedia.org> _______________________________________________ MediaWiki-commits mailing list MediaWiki-commits@lists.wikimedia.org https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits