EBernhardson has uploaded a new change for review.
https://gerrit.wikimedia.org/r/190476
Change subject: Refactor import postprocessor interface
......................................................................
Refactor import postprocessor interface
This interface was not very truthful, the commit action was calling a method
that indicated a full talkpage was imported, but really it was just a piece
of the page.
This patch removes the talkpage level methods, and move the call site of the
regular events to be post-commit. Additionally documented the methods, and
switched the arguments to take the State objects. This is a for a followup
patch which logs about imported topics.
Change-Id: I78fd0fdbd7c2d592e7287fa7f521c9a499385bb9
---
M includes/Import/Importer.php
M includes/Import/Postprocessor/LqtRedirector.php
M includes/Import/Postprocessor/Postprocessor.php
M includes/Import/Postprocessor/ProcessorGroup.php
4 files changed, 83 insertions(+), 37 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/76/190476/1
diff --git a/includes/Import/Importer.php b/includes/Import/Importer.php
index 98863f9..d375124 100644
--- a/includes/Import/Importer.php
+++ b/includes/Import/Importer.php
@@ -382,7 +382,6 @@
$this->dbw->commit();
$this->cache->commit();
$this->sourceStore->save();
- $this->postprocessor->afterTalkpageImported();
$this->flushDeferredQueue();
}
@@ -391,7 +390,7 @@
$this->cache->rollback();
$this->sourceStore->rollback();
$this->clearDeferredQueue();
- $this->postprocessor->talkpageImportAborted();
+ $this->postprocessor->importAborted();
}
protected function flushDeferredQueue() {
@@ -511,6 +510,7 @@
$state->begin();
$this->importHeader( $state, $header );
$state->commit();
+ $state->postprocessor->afterHeaderImported(
$state, $header );
$imported++;
} catch ( ImportSourceStoreException $e ) {
// errors from the source store are more
serious and should
@@ -521,7 +521,7 @@
} catch ( \Exception $e ) {
$state->rollback();
\MWExceptionHandler::logException( $e );
- $state->logger->error( 'Failed importing
header' );
+ $state->logger->error( 'Failed importing
header: ' . $header->getObjectKey() );
$state->logger->error( (string)$e );
$failed++;
}
@@ -531,8 +531,10 @@
try {
// @todo this may be too large of a chunk for
one commit, unsure
$state->begin();
- $this->importTopic( $state, $topic );
+ $topicState = $this->getTopicState( $state,
$topic );
+ $this->importTopic( $topicState, $topic );
$state->commit();
+ $state->postprocessor->afterTopicImported(
$topicState, $topic );
$imported++;
} catch ( ImportSourceStoreException $e ) {
// errors from the source store are more
serious and shuld
@@ -543,7 +545,7 @@
} catch ( \Exception $e ) {
$state->rollback();
\MWExceptionHandler::logException( $e );
- $state->logger->error( 'Failed importing topic'
);
+ $state->logger->error( 'Failed importing topic:
' . $topic->getObjectKey() );
$state->logger->error( (string)$e );
$failed++;
}
@@ -598,13 +600,10 @@
}
/**
- * @param PageImportState $pageState
+ * @param TopicImportState $pageState
* @param IImportTopic $importTopic
*/
- public function importTopic( PageImportState $pageState, IImportTopic
$importTopic ) {
- // $database->begin();
- $topicState = $this->getTopicState( $pageState, $importTopic );
-
+ public function importTopic( TopicImportState $topicState, IImportTopic
$importTopic ) {
$summary = $importTopic->getTopicSummary();
if ( $summary ) {
$this->importSummary( $topicState, $summary );
@@ -616,7 +615,6 @@
$topicState->commitLastModified();
$topicId = $topicState->topicWorkflow->getId();
- $pageState->postprocessor->afterTopicImported( $importTopic,
$topicId );
}
/**
@@ -808,12 +806,10 @@
$post
);
$state->parent->logger->info( $logPrefix . "Finished
importing post with " . count( $replyRevisions ) . " revisions" );
+ $state->parent->postprocessor->afterPostImported(
$state, $post, $topRevision->getPostId() );
}
$state->recordModificationTime( $topRevision->getRevisionId() );
-
- $topicId = $state->topicWorkflow->getId();
- $state->parent->postprocessor->afterPostImported( $post,
$topicId, $topRevision->getPostId() );
foreach ( $post->getReplies() as $subReply ) {
$this->importPost( $state, $subReply, $topRevision,
$logPrefix . ' ' );
diff --git a/includes/Import/Postprocessor/LqtRedirector.php
b/includes/Import/Postprocessor/LqtRedirector.php
index 6553592..9057561 100644
--- a/includes/Import/Postprocessor/LqtRedirector.php
+++ b/includes/Import/Postprocessor/LqtRedirector.php
@@ -6,13 +6,14 @@
use Flow\Import\IImportTopic;
use Flow\Import\LiquidThreadsApi\ImportPost;
use Flow\Import\LiquidThreadsApi\ImportTopic;
+use Flow\Import\PostImportState;
+use Flow\Import\TopicImportState;
use Flow\Model\UUID;
use Flow\UrlGenerator;
use Title;
use User;
use WatchedItem;
use WikiPage;
-use WikitextContent;
class LqtRedirector implements Postprocessor {
/** @var UrlGenerator **/
@@ -28,19 +29,29 @@
$this->user = $user;
}
- public function afterTopicImported( IImportTopic $topic, UUID
$newTopicId ) {
- if ( $topic instanceof ImportTopic /* LQT */ ) {
- $this->redirectsToDo[] = array( $topic->getTitle(),
$newTopicId );
- }
+ public function afterHeaderImported( PageImportState $state,
IImportHeader $header ) {
+ // not a thing to do, yet
}
- public function afterPostImported( IImportPost $post, UUID $topicId,
UUID $newPostId ) {
+
+ public function afterPostImported( TopicImportState $state, IImportPost
$post, UUID $newPostId ) {
if ( $post instanceof ImportPost /* LQT */ ) {
- $this->redirectsToDo[] = array( $post->getTitle(),
$topicId, $newPostId );
+ $this->redirectsToDo[] = array(
+ $post->getTitle(),
+ $state->topicWorkflow->getId(),
+ $newPostId
+ );
}
}
- public function afterTalkpageImported() {
+ public function afterTopicImported( TopicImportState $state,
IImportTopic $topic ) {
+ if ( !$topic instanceof ImportTopic /* LQT */ ) {
+ return;
+ }
+ $this->doRedirect(
+ $topic->getTitle(),
+ $state->topicWorkflow->getId()
+ );
foreach( $this->redirectsToDo as $args ) {
call_user_func_array( array( $this, 'doRedirect' ),
$args );
}
@@ -48,7 +59,7 @@
$this->redirectsToDo = array();
}
- public function talkpageImportAborted() {
+ public function importAborted() {
$this->redirectsToDo = array();
}
diff --git a/includes/Import/Postprocessor/Postprocessor.php
b/includes/Import/Postprocessor/Postprocessor.php
index e511e48..de9be8e 100644
--- a/includes/Import/Postprocessor/Postprocessor.php
+++ b/includes/Import/Postprocessor/Postprocessor.php
@@ -3,12 +3,49 @@
namespace Flow\Import\Postprocessor;
use Flow\Model\UUID;
+use Flow\Import\IImportHeader;
use Flow\Import\IImportPost;
use Flow\Import\IImportTopic;
+use Flow\Import\PageImportState;
+use Flow\Import\TopicImportState;
interface Postprocessor {
- function afterTopicImported( IImportTopic $topic, UUID $newTopicId );
- function afterPostImported( IImportPost $post, UUID $topicId, UUID
$newPostId );
- function afterTalkpageImported();
- function talkpageImportAborted();
+ /**
+ * Called after the successfull commit of a header. This is
+ * currently called regardless of if any new content was imported.
+ *
+ * @param PageImportState $state
+ * @param IImportHeader $header
+ */
+ function afterHeaderImported( PageImportState $state, IImportHeader
$header );
+
+ /**
+ * Called after the import of a single post. This has not yet been
+ * commited, and serves to inform the postprocessor about topic
+ * import progress. Only posts that have not been previously
+ * imported are reported here.
+ *
+ * @param TopicImportState $state
+ * @param IImportPost $post
+ * @param UUID $newPostId
+ */
+ function afterPostImported( TopicImportState $state, IImportPost $post,
UUID $newPostId );
+
+ /**
+ * Called after the successful commit of a topic to the database.
+ * This may or may not have imported any actual posts, it is
+ * called on all topics run through the process regardless.
+ *
+ * @param TopicImportState $state
+ * @param IImportPost $post
+ */
+ function afterTopicImported( TopicImportState $state, IImportTopic
$topic );
+
+ /**
+ * Callled when there has been an error in the import process.
+ * Any information the postprocessor has received since the last
+ * commit operation should be discarded as it will not be written
+ * to permenant storage.
+ */
+ function importAborted();
}
diff --git a/includes/Import/Postprocessor/ProcessorGroup.php
b/includes/Import/Postprocessor/ProcessorGroup.php
index 1f5b3b5..3cffc37 100644
--- a/includes/Import/Postprocessor/ProcessorGroup.php
+++ b/includes/Import/Postprocessor/ProcessorGroup.php
@@ -3,8 +3,11 @@
namespace Flow\Import\Postprocessor;
use Flow\Model\UUID;
+use Flow\Import\IImportHeader;
use Flow\Import\IImportPost;
use Flow\Import\IImportTopic;
+use Flow\Import\TopicImportState;
+use Flow\Import\PageImportState;
class ProcessorGroup implements Postprocessor {
/** @var array<Postprocessor> **/
@@ -18,20 +21,19 @@
$this->processors[] = $proc;
}
- public function afterTopicImported( IImportTopic $topic, UUID
$newTopicId ) {
- $this->call( 'afterTopicImported', func_get_args() );
+ public function afterHeaderImported( PageImportState $state,
IImportHeader $header ) {
+ $this->call( __FUNCTION__, func_get_args() );
+ }
+ public function afterTopicImported( TopicImportState $state,
IImportTopic $topic ) {
+ $this->call( __FUNCTION__, func_get_args() );
}
- public function afterPostImported( IImportPost $post, UUID $topicId,
UUID $postId ) {
- $this->call( 'afterPostImported', func_get_args() );
+ public function afterPostImported( TopicImportState $state, IImportPost
$post, UUID $newPostId ) {
+ $this->call( __FUNCTION__, func_get_args() );
}
- public function afterTalkpageImported() {
- $this->call( 'afterTalkpageImported', func_get_args() );
- }
-
- public function talkpageImportAborted() {
- $this->call( 'talkpageImportAborted', func_get_args() );
+ public function importAborted() {
+ $this->call( __FUNCTION__, func_get_args() );
}
protected function call( $name, $args ) {
--
To view, visit https://gerrit.wikimedia.org/r/190476
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I78fd0fdbd7c2d592e7287fa7f521c9a499385bb9
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