persistRevisionThreadItems: Use SQL expression builder

Change-Id: I9dc94b9d3ad927eab81abf9d3aef782c20eaa482
This commit is contained in:
Bartosz Dziewoński 2023-10-21 23:22:34 +02:00
parent e5b44868f8
commit 2fc7f17bc0

View file

@ -47,12 +47,12 @@ class PersistRevisionThreadItems extends Maintenance {
public function execute() {
$services = MediaWikiServices::getInstance();
$this->dbr = $this->getDB( DB_REPLICA );
$this->dbr = $dbr = $this->getDB( DB_REPLICA );
$this->itemStore = $services->getService( 'DiscussionTools.ThreadItemStore' );
$this->revStore = $services->getRevisionStore();
$this->lang = $services->getLanguageFactory()->getLanguage( 'en' );
$qb = $this->dbr->newSelectQueryBuilder();
$qb = $dbr->newSelectQueryBuilder();
$qb->queryInfo( $this->revStore->getQueryInfo( [ 'page' ] ) );
@ -84,31 +84,32 @@ class PersistRevisionThreadItems extends Maintenance {
// Add conditions from HookUtils::isAvailableForTitle().
// Keep this in sync with that method.
$nsInfo = $services->getNamespaceInfo();
$signatureNamespaces = array_values( array_filter(
$nsInfo->getValidNamespaces(),
[ $nsInfo, 'wantSignatures' ]
) );
$qb->leftJoin( 'page_props', null, [
'pp_propname' => 'newsectionlink',
'pp_page = page_id',
] );
$qb->where( $this->dbr->makeList( [
'page_namespace' => array_values( array_filter(
$nsInfo->getValidNamespaces(),
[ $nsInfo, 'wantSignatures' ]
) ),
'pp_propname IS NOT NULL',
], IReadableDatabase::LIST_OR ) );
$qb->where(
$dbr->expr( 'page_namespace', '=', $signatureNamespaces )
->or( 'pp_propname', '!=', null )
);
if ( $this->getOption( 'current' ) ) {
$qb->where( 'rev_id = page_latest' );
$index = [ 'page_id' ];
if ( $this->getOption( 'touched-after' ) ) {
$qb->where( $this->dbr->buildComparison( '>', [
'page_touched' => $this->dbr->timestamp( $this->getOption( 'touched-after' ) )
] ) );
$qb->where( $dbr->expr(
'page_touched', '>', $dbr->timestamp( $this->getOption( 'touched-after' ) )
) );
}
if ( $this->getOption( 'touched-before' ) ) {
$qb->where( $this->dbr->buildComparison( '<', [
'page_touched' => $this->dbr->timestamp( $this->getOption( 'touched-before' ) )
] ) );
$qb->where( $dbr->expr(
'page_touched', '<', $dbr->timestamp( $this->getOption( 'touched-before' ) )
) );
}
} else {