Matthias Mullie has uploaded a new change for review.

  https://gerrit.wikimedia.org/r/239104

Change subject: Update Title & LinkCache article ids right after move
......................................................................

Update Title & LinkCache article ids right after move

I believe this should fix all cases that depend on the correct
article ID. $from & $to objects will have the correct values.
Any other Title objects that get created will get it from
LinkCache, which is now also fixed. Unless GAID_FOR_UPDATE
is used, but that case will also result in the correct data.

I pass $to by-ref so I can easily clear mArticleId without
affecting LinkCache, which should be fine.
Alternatives could be:
* using reflection to change mArticleID
* use resetArticleID & then repopulate LinkCache:

    /*
     * We'll reset $to's article ID to make sure it's the correct one,
     * but doing so will also clear LinkCache, so we'll have to re-add it.
     */
    $fields['id'] = $linkCache->getGoodLinkFieldObj( $to, 'id' );
    $fields['length'] = $linkCache->getGoodLinkFieldObj( $to, 'length' );
    $fields['redirect'] = $linkCache->getGoodLinkFieldObj( $to, 'redirect' );
    $fields['revision'] = $linkCache->getGoodLinkFieldObj( $to, 'revision' );
    $fields['model'] = $linkCache->getGoodLinkFieldObj( $to, 'model' );

    $to->resetArticleID( $fields['id'] );
    $linkCache->addGoodLinkObj(
        $fields['id'],
        $to,
        $fields['length'],
        $fields['redirect'],
        $fields['revision'],
        $fields['model']
    );

Bug: T112784
Change-Id: Ibbc09a10c9f8f5ccaec6f69011edc9c7089b217d
---
M includes/Import/OptInController.php
1 file changed, 27 insertions(+), 14 deletions(-)


  git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow 
refs/changes/04/239104/1

diff --git a/includes/Import/OptInController.php 
b/includes/Import/OptInController.php
index 1ec1334..2c28806 100644
--- a/includes/Import/OptInController.php
+++ b/includes/Import/OptInController.php
@@ -139,9 +139,35 @@
         * @param Title $from
         * @param Title $to
         */
-       private function movePage( Title $from, Title $to ) {
+       private function movePage( Title $from, Title &$to ) {
                $mp = new MovePage( $from, $to );
                $mp->move( $this->user, null, false );
+
+               /*
+                * Article IDs are cached inside title objects. Since we'll be
+                * reusing these objects, we have to make sure they reflect the
+                * correct IDs.
+                * We could just Title::GAID_FOR_UPDATE everywhere, but that 
would
+                * result in a lot of unneeded calls to master.
+                * If these IDs are wrong, we could end up associating workflows
+                * with an incorrect page (that was just moved)
+                *
+                * Anyway, the page has just been moved without redirect, so 
that
+                * page is no longer valid.
+                */
+               $from->resetArticleID( 0 );
+               $linkCache = \LinkCache::singleton();
+               $linkCache->addBadLinkObj( $from );
+
+               /*
+                * WikiPage::updateRevisionOn (called form 
MovePage::moveToInternal)
+                * updates LinkCache for $to. We're still stuck with the $to 
object,
+                * which has cached the article ID.
+                * We've accepted $to by-ref, so we'll just overwrite the object
+                * with one that's unaware of its article ID, so it'll go look 
in
+                * LinkCache once requested.
+                */
+               $to = Title::newFromDBkey( $to->getDBkey() );
        }
 
        /**
@@ -243,13 +269,6 @@
                        $this->fatal( 
'flow-special-enableflow-board-creation-not-allowed', $page );
                }
 
-               // $title was recently moved, but the article ID is cached 
inside
-               // the Title object. Let's make sure it accurately reflects that
-               // $title now doesn't exist by resetting the article ID.
-               // Otherwise, we run the risk of the Workflow we're creating 
being
-               // associated with the page we just moved.
-               $title->resetArticleID( 0 );
-
                $loader = $loaderFactory->createWorkflowLoader( $title );
                $blocks = $loader->getBlocks();
 
@@ -300,13 +319,7 @@
         * @param string|null $addToHeader
         */
        private function restoreExistingFlowBoard( Title $archivedFlowPage, 
Title $title, $addToHeader = null ) {
-               $pageId = $archivedFlowPage->getArticleID();
                $this->movePage( $archivedFlowPage, $title );
-
-               // $title was just moved, but the article ID is cached inside
-               // the Title object. Let's make sure it accurately reflects the
-               // new article id.
-               $title->resetArticleID( $pageId );
 
                if ( $addToHeader ) {
                        $this->editBoardDescription( $title, function( $oldDesc 
) use ( $addToHeader ) {

-- 
To view, visit https://gerrit.wikimedia.org/r/239104
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: Ibbc09a10c9f8f5ccaec6f69011edc9c7089b217d
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

Reply via email to