Merge "RevisionStoreDbTestBase, remove redundant needsDB override"
[lhc/web/wiklou.git] / maintenance / refreshLinks.php
index 9d5d39f..8306243 100644 (file)
@@ -21,6 +21,7 @@
  * @ingroup Maintenance
  */
 
+use MediaWiki\MediaWikiServices;
 use Wikimedia\Rdbms\IDatabase;
 
 require_once __DIR__ . '/Maintenance.php';
@@ -170,8 +171,8 @@ class RefreshLinks extends Maintenance {
                        }
                } else {
                        if ( !$end ) {
-                               $maxPage = $dbr->selectField( 'page', 'max(page_id)', false );
-                               $maxRD = $dbr->selectField( 'redirect', 'max(rd_from)', false );
+                               $maxPage = $dbr->selectField( 'page', 'max(page_id)', '', __METHOD__ );
+                               $maxRD = $dbr->selectField( 'redirect', 'max(rd_from)', '', __METHOD__ );
                                $end = max( $maxPage, $maxRD );
                        }
                        $this->output( "Refreshing redirects table.\n" );
@@ -258,7 +259,7 @@ class RefreshLinks extends Maintenance {
        public static function fixLinksFromArticle( $id, $ns = false ) {
                $page = WikiPage::newFromID( $id );
 
-               LinkCache::singleton()->clear();
+               MediaWikiServices::getInstance()->getLinkCache()->clear();
 
                if ( $page === null ) {
                        return;
@@ -267,17 +268,14 @@ class RefreshLinks extends Maintenance {
                        return;
                }
 
-               $content = $page->getContent( Revision::RAW );
-               if ( $content === null ) {
-                       return;
-               }
-
-               $updates = $content->getSecondaryDataUpdates(
-                       $page->getTitle(), /* $old = */ null, /* $recursive = */ false );
-               foreach ( $updates as $update ) {
-                       DeferredUpdates::addUpdate( $update );
-                       DeferredUpdates::doUpdates();
-               }
+               // Defer updates to post-send but then immediately execute deferred updates;
+               // this is the simplest way to run all updates immediately (including updates
+               // scheduled by other updates).
+               $page->doSecondaryDataUpdates( [
+                       'defer' => DeferredUpdates::POSTSEND,
+                       'recursive' => false,
+               ] );
+               DeferredUpdates::doUpdates();
        }
 
        /**