[MCR] Revision::newFromArchiveRow convert overrides for rows
authoraddshore <addshorewiki@gmail.com>
Fri, 22 Dec 2017 16:39:00 +0000 (16:39 +0000)
committeraddshore <addshorewiki@gmail.com>
Fri, 22 Dec 2017 16:39:00 +0000 (16:39 +0000)
This method used to overwrite attributes, then passed to
Revision::__construct
RevisionStore::newRevisionFromArchiveRow instead overrides row field
names

This patch adds a conversion for the one field that we need to care
about which is 'page' -> 'page_id'.

After looking through the usages in core and extensions it looks
like this will also fix a bug in the following classes which also
passes in 'page'.
 - RevDelArchivedRevisionItem
 - RevDelArchiveItem

Bug: T183564
Change-Id: I6a472b93663a0599abb55453c6939463ff56275d

includes/Revision.php
includes/Storage/RevisionStoreRecord.php

index f3307c6..ed0646a 100644 (file)
@@ -148,6 +148,17 @@ class Revision implements IDBAccessObject {
         * @return Revision
         */
        public static function newFromArchiveRow( $row, $overrides = [], Title $title = null ) {
+               /**
+                * MCR Migration: https://phabricator.wikimedia.org/T183564
+                * This method used to overwrite attributes, then passed to Revision::__construct
+                * RevisionStore::newRevisionFromArchiveRow instead overrides row field names
+                * So do a conversion here.
+                */
+               if ( array_key_exists( 'page', $overrides ) ) {
+                       $overrides['page_id'] = $overrides['page'];
+                       unset( $overrides['page'] );
+               }
+
                $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
                return new Revision( $rec, self::READ_NORMAL, $title );
        }
index 50ae8d5..341855d 100644 (file)
@@ -97,7 +97,8 @@ class RevisionStoreRecord extends RevisionRecord {
                        && $this->mPageId !== $this->mTitle->getArticleID()
                ) {
                        throw new InvalidArgumentException(
-                               'The given Title does not belong to page ID ' . $this->mPageId
+                               'The given Title does not belong to page ID ' . $this->mPageId .
+                               ' but actually belongs to ' . $this->mTitle->getArticleID()
                        );
                }
        }