Merge "Migrate Api modules from tag_summary table to change_tag"
authorjenkins-bot <jenkins-bot@gerrit.wikimedia.org>
Fri, 30 Nov 2018 19:13:46 +0000 (19:13 +0000)
committerGerrit Code Review <gerrit@wikimedia.org>
Fri, 30 Nov 2018 19:13:46 +0000 (19:13 +0000)
1  2 
includes/api/ApiQueryAllDeletedRevisions.php
includes/api/ApiQueryDeletedRevisions.php
includes/api/ApiQueryDeletedrevs.php
includes/api/ApiQueryRecentChanges.php
includes/api/ApiQueryRevisions.php
includes/api/ApiQueryUserContribs.php

@@@ -43,6 -43,8 +43,6 @@@ class ApiQueryAllDeletedRevisions exten
         * @return void
         */
        protected function run( ApiPageSet $resultPageSet = null ) {
 -              global $wgChangeTagsSchemaMigrationStage;
 -
                // Before doing anything at all, let's check permissions
                $this->checkUserRightsAny( 'deletedhistory' );
  
                }
  
                if ( $this->fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ 'ar_rev_id=ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'archive' ) ] );
                }
  
                if ( !is_null( $params['tag'] ) ) {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
                        );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
  
@@@ -39,6 -39,8 +39,6 @@@ class ApiQueryDeletedRevisions extends 
        }
  
        protected function run( ApiPageSet $resultPageSet = null ) {
 -              global $wgChangeTagsSchemaMigrationStage;
 -
                $user = $this->getUser();
                // Before doing anything at all, let's check permissions
                $this->checkUserRightsAny( 'deletedhistory' );
                }
  
                if ( $this->fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ 'ar_rev_id=ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'archive' ) ] );
                }
  
                if ( !is_null( $params['tag'] ) ) {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
                        );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
  
@@@ -36,6 -36,8 +36,6 @@@ class ApiQueryDeletedrevs extends ApiQu
        }
  
        public function execute() {
 -              global $wgChangeTagsSchemaMigrationStage;
 -
                // Before doing anything at all, let's check permissions
                $this->checkUserRightsAny( 'deletedhistory' );
  
                }
  
                if ( $fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ 'ar_rev_id=ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'archive' ) ] );
                }
  
                if ( !is_null( $params['tag'] ) ) {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ 'ar_rev_id=ct_rev_id' ] ] ]
                        );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
  
@@@ -143,6 -143,8 +143,6 @@@ class ApiQueryRecentChanges extends Api
         * @param ApiPageSet|null $resultPageSet
         */
        public function run( $resultPageSet = null ) {
 -              global $wgChangeTagsSchemaMigrationStage;
 -
                $user = $this->getUser();
                /* Get the parameters of the request. */
                $params = $this->extractRequestParams();
                        $resultPageSet && $params['generaterevisions'] );
  
                if ( $this->fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds( [ 'tag_summary' => [ 'LEFT JOIN', [ 'rc_id=ts_rc_id' ] ] ] );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'recentchanges' ) ] );
                }
  
                if ( $this->fld_sha1 ) {
                if ( !is_null( $params['tag'] ) ) {
                        $this->addTables( 'change_tag' );
                        $this->addJoinConds( [ 'change_tag' => [ 'INNER JOIN', [ 'rc_id=ct_rc_id' ] ] ] );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
  
@@@ -84,7 -84,7 +84,7 @@@ class ApiQueryRevisions extends ApiQuer
        }
  
        protected function run( ApiPageSet $resultPageSet = null ) {
 -              global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage;
 +              global $wgActorTableSchemaMigrationStage;
  
                $params = $this->extractRequestParams( false );
                $revisionStore = MediaWikiServices::getInstance()->getRevisionStore();
                }
  
                if ( $this->fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ 'rev_id=ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
                }
  
                if ( $params['tag'] !== null ) {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ 'rev_id=ct_rev_id' ] ] ]
                        );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
  
@@@ -321,7 -321,7 +321,7 @@@ class ApiQueryUserContribs extends ApiQ
         * @param int $limit
         */
        private function prepareQuery( array $users, $limit ) {
 -              global $wgActorTableSchemaMigrationStage, $wgChangeTagsSchemaMigrationStage;
 +              global $wgActorTableSchemaMigrationStage;
  
                $this->resetQueryParams();
                $db = $this->getDB();
                $this->addFieldsIf( 'rc_patrolled', $this->fld_patrolled );
  
                if ( $this->fld_tags ) {
-                       $this->addTables( 'tag_summary' );
-                       $this->addJoinConds(
-                               [ 'tag_summary' => [ 'LEFT JOIN', [ $idField . ' = ts_rev_id' ] ] ]
-                       );
-                       $this->addFields( 'ts_tags' );
+                       $this->addFields( [ 'ts_tags' => ChangeTags::makeTagSummarySubquery( 'revision' ) ] );
                }
  
                if ( isset( $this->params['tag'] ) ) {
                        $this->addJoinConds(
                                [ 'change_tag' => [ 'INNER JOIN', [ $idField . ' = ct_rev_id' ] ] ]
                        );
 -                      if ( $wgChangeTagsSchemaMigrationStage > MIGRATION_WRITE_BOTH ) {
 -                              $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 -                              try {
 -                                      $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
 -                              } catch ( NameTableAccessException $exception ) {
 -                                      // Return nothing.
 -                                      $this->addWhere( '1=0' );
 -                              }
 -                      } else {
 -                              $this->addWhereFld( 'ct_tag', $this->params['tag'] );
 +                      $changeTagDefStore = MediaWikiServices::getInstance()->getChangeTagDefStore();
 +                      try {
 +                              $this->addWhereFld( 'ct_tag_id', $changeTagDefStore->getId( $this->params['tag'] ) );
 +                      } catch ( NameTableAccessException $exception ) {
 +                              // Return nothing.
 +                              $this->addWhere( '1=0' );
                        }
                }
        }