Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/205613
Change subject: Fix workflow_page_id when board is restored
......................................................................
Fix workflow_page_id when board is restored
Re-use most of board-move code. It does pretty much
exactly what is needed to update page_id after restore,
but just can't use Title objects (because, for deleted
entries, getArticleId() is unreliable, as it would
return 0)
Bug: T95280
Change-Id: I5078611fb9fe9a59de128b06db397f604fe26fee
---
M Flow.php
M Hooks.php
M includes/BoardMover.php
M includes/Model/Workflow.php
4 files changed, 41 insertions(+), 27 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/13/205613/1
diff --git a/Flow.php b/Flow.php
index e5640d6..ebd81b7 100644
--- a/Flow.php
+++ b/Flow.php
@@ -142,6 +142,7 @@
$wgHooks['CategoryViewer::generateLink'][] =
'FlowHooks::onCategoryViewerGenerateLink';
$wgHooks['ArticleConfirmDelete'][] = 'FlowHooks::onArticleConfirmDelete';
$wgHooks['ArticleDelete'][] = 'FlowHooks::onArticleDelete';
+$wgHooks['ArticleUndelete'][] = 'FlowHooks::onArticleUndelete';
// Extension:UserMerge support
$wgHooks['UserMergeAccountFields'][] = 'FlowHooks::onUserMergeAccountFields';
diff --git a/Hooks.php b/Hooks.php
index 7e1daee..10d695a 100644
--- a/Hooks.php
+++ b/Hooks.php
@@ -1350,6 +1350,26 @@
}
/**
+ * @param Title $title Title corresponding to the article restored
+ * @param bool $create Whether or not the restoration caused the page
to be created (i.e. it didn't exist before).
+ * @param string $comment The comment associated with the undeletion.
+ * @param int $oldPageId ID of page previously deleted (from archive
table)
+ * @return bool
+ */
+ public static function onArticleUndelete( Title $title, $created,
$comment, $oldPageId ) {
+ if ( $title->getContentModel() === CONTENT_MODEL_FLOW_BOARD ) {
+ // complete hack to make sure that when the page is
saved to new
+ // location and rendered it doesn't throw an error
about the wrong title
+ Container::get( 'factory.loader.workflow'
)->pageMoveInProgress();
+ // open a database transaction and prepare everything
for the move & commit
+ Container::get( 'board_mover' )->prepareMove(
$oldPageId, $title->getArticleID() );
+ Container::get( 'board_mover' )->commit();
+ }
+
+ return true;
+ }
+
+ /**
* Occurs at the begining of the MovePage process. Perhaps ContentModel
should be
* extended to be notified about moves explicitly.
*/
@@ -1360,7 +1380,7 @@
Container::get( 'factory.loader.workflow'
)->pageMoveInProgress();
// open a database transaction and prepare everything
for the move, but
// don't commit yet. That is done below in
self::onTitleMoveComplete
- Container::get( 'board_mover' )->prepareMove(
$oldTitle, $newTitle );
+ Container::get( 'board_mover' )->prepareMove(
$oldTitle->getArticleID(), $newTitle->getArticleID() );
}
return true;
diff --git a/includes/BoardMover.php b/includes/BoardMover.php
index 58552d1..8e6d29a 100644
--- a/includes/BoardMover.php
+++ b/includes/BoardMover.php
@@ -45,20 +45,12 @@
/**
* Collects the workflow and header (if it exists) and puts them into
the database. Does
* not commit yet. It is intended for prepareMove to be called from the
TitleMove hook,
- * and commited from TitleMoveComplete hook. This ensures that if some
error prevents the
- * core transaction from commiting this transaction is also not
commited.
+ * and committed from TitleMoveComplete hook. This ensures that if some
error prevents the
+ * core transaction from committing this transaction is also not
committed.
*/
- public function prepareMove( Title $oldTitle, Title $newTitle ) {
+ public function prepareMove( $oldPageId, $newPageId ) {
if ( $this->dbw !== null ) {
- throw new FlowException( "Already prepared for move
from {$oldTitle} to {$newTitle}" );
- }
- if ( $oldTitle->getContentModel() !== CONTENT_MODEL_FLOW_BOARD
) {
- throw new FlowException( "$oldTitle is not a flow
board" );
- }
- // @todo someday NS_TOPIC should be made
CONTENT_MODEL_FLOW_TOPIC instead of approximating
- // like this.
- if ( $oldTitle->getNamespace() === NS_TOPIC ) {
- throw new FlowException( "$oldTitle is a topic, not a
board" );
+ throw new FlowException( "Already prepared for move
from {$oldPageId} to {$newPageId}" );
}
// All reads must go through master to help ensure consistency
@@ -75,10 +67,10 @@
// revisit this.
$found = $this->storage->find( 'Workflow', array(
'workflow_wiki' => wfWikiId(),
- 'workflow_page_id' => $oldTitle->getArticleID(),
+ 'workflow_page_id' => $oldPageId,
) );
if ( !$found ) {
- throw new FlowException( "Could not locate workflow for
$oldTitle" );
+ throw new FlowException( "Could not locate workflow for
$oldPageId" );
}
$discussionWorkflow = null;
@@ -86,11 +78,11 @@
if ( $workflow->getType() === 'discussion' ) {
$discussionWorkflow = $workflow;
}
- $workflow->updateFromTitle( $oldTitle, $newTitle );
+ $workflow->updateFromPageId( $oldPageId, $newPageId );
$this->storage->put( $workflow, array() );
}
if ( $discussionWorkflow === null ) {
- throw new FlowException( "Main discussion workflow for
$oldTitle not found" );
+ throw new FlowException( "Main discussion workflow for
$oldPageId not found" );
}
$found = $this->storage->find(
@@ -106,7 +98,7 @@
$this->header->getContentRaw(),
$this->header->getContentFormat(),
'edit-header',
- $newTitle
+ Title::newFromID( $newPageId )
);
$this->storage->put( $nextHeader, array(
'workflow' => $discussionWorkflow,
diff --git a/includes/Model/Workflow.php b/includes/Model/Workflow.php
index 4b8ebc0..fad0f7d 100644
--- a/includes/Model/Workflow.php
+++ b/includes/Model/Workflow.php
@@ -175,19 +175,20 @@
/**
* Update the workflow after a page move.
*
- * @param Title $oldTitle The title the workflow is currently located at
- * @param Title $newTitle The title the workflow is moving to. The way
the move process
- * works post-move we still have $oldTitles pageId, this $newTitle
will not have that
- * pageId yet.
+ * @param int $oldPageId The page_id the workflow is currently located
at
+ * @param int $newPageId The page_id the workflow is moving to
* @throws DataModelException
*/
- public function updateFromTitle( Title $oldTitle, Title $newTitle ) {
- if ( $oldTitle->getArticleID() !== $this->pageId ) {
- throw new DataModelException( 'Must update from title
with same page id. ' . $this->pageId . ' !== ' . $oldTitle->getArticleID() );
+ public function updateFromPageId( $oldPageId, $newPageId ) {
+ if ( $oldPageId !== $this->pageId ) {
+ throw new DataModelException( 'Must update from same
page id. ' . $this->pageId . ' !== ' . $oldPageId );
}
- $this->namespace = $newTitle->getNamespace();
- $this->titleText = $newTitle->getDBkey();
+ $this->pageId = $newPageId;
+
+ $title = Title::newFromID( $this->pageId );
+ $this->namespace = $title->getNamespace();
+ $this->titleText = $title->getDBkey();
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/205613
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I5078611fb9fe9a59de128b06db397f604fe26fee
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits