[MCR] Revision::newFromArchiveRow remove recently added $title param
authoraddshore <addshorewiki@gmail.com>
Thu, 28 Dec 2017 18:57:13 +0000 (18:57 +0000)
committeraddshore <addshorewiki@gmail.com>
Thu, 28 Dec 2017 19:58:20 +0000 (19:58 +0000)
The $title param was added as part of
Ieabca1cf157fb667c75fc907b9da2917f71c61b3 and is not yet used
by any code.

The underlying issue with title fetching in RevisionStore has been fixed
in commit 4de36baa63afc23398f5d1747f08fc47309c314c
I15e4663902e2cbfe15b0da2e46449330e313bd0d

This patch removes the param that is not needed, but adds duplicate
logic to fetch a Title object to pass into the Revision object that
is created.
This logic is pulled directly from
RevisionStore::newRevisionFromArchiveRow.

Change-Id: I60568b8ffd22d5e3f861c03b4b8ef14332e9015b

includes/Revision.php

index 7d38b4e..4058c63 100644 (file)
@@ -149,7 +149,7 @@ class Revision implements IDBAccessObject {
         * @throws MWException
         * @return Revision
         */
-       public static function newFromArchiveRow( $row, $overrides = [], Title $title = null ) {
+       public static function newFromArchiveRow( $row, $overrides = [] ) {
                /**
                 * MCR Migration: https://phabricator.wikimedia.org/T183564
                 * This method used to overwrite attributes, then passed to Revision::__construct
@@ -161,7 +161,30 @@ class Revision implements IDBAccessObject {
                        unset( $overrides['page'] );
                }
 
-               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, $title, $overrides );
+               /**
+                * We require a Title for both the Revision object and the RevisionRecord.
+                * Below is duplicated logic from RevisionStore::newRevisionFromArchiveRow
+                * to fetch a title in order pass it into the Revision object.
+                */
+               $title = null;
+               if ( isset( $overrides['title'] ) ) {
+                       if ( !( $overrides['title'] instanceof Title ) ) {
+                               throw new MWException( 'title field override must contain a Title object.' );
+                       }
+
+                       $title = $overrides['title'];
+               }
+               if ( $title !== null ) {
+                       if ( isset( $row->ar_namespace ) && isset( $row->ar_title ) ) {
+                               $title = Title::makeTitle( $row->ar_namespace, $row->ar_title );
+                       } else {
+                               throw new InvalidArgumentException(
+                                       'A Title or ar_namespace and ar_title must be given'
+                               );
+                       }
+               }
+
+               $rec = self::getRevisionStore()->newRevisionFromArchiveRow( $row, 0, null, $overrides );
                return new Revision( $rec, self::READ_NORMAL, $title );
        }