- /**
- * @param Title $title
- */
- private function refreshCategoryIfEmpty( Title $title ) {
- $dbw = $this->getDB();
-
- $row = $dbw->selectRow(
- 'category',
- [ 'cat_id', 'cat_title', 'cat_pages', 'cat_subcats', 'cat_files' ],
- [ 'cat_title' => $title->getDBkey(), 'cat_pages <= 100' ],
- __METHOD__
- );
-
- if ( !$row ) {
- return; // nothing to delete
- }
-
- $cat = Category::newFromRow( $row, $title );
- $hasLink = $dbw->selectField(
- 'categorylinks',
- '1',
- [ 'cl_to' => $title->getDBkey() ],
- __METHOD__
- );
- if ( !$hasLink ) {
- $cat->refreshCounts(); // delete the category table entry
- }
- }
-
- private function batchDeleteByPK( $table, array $conds, array $pk, $bSize ) {
- $services = MediaWikiServices::getInstance();
- $lbFactory = $services->getDBLoadBalancerFactory();
- $dbw = $this->getDB(); // convenience
-
- $res = $dbw->select( $table, $pk, $conds, __METHOD__ );
-
- $pkDeleteConds = [];
- foreach ( $res as $row ) {
- $pkDeleteConds[] = $dbw->makeList( (array)$row, LIST_AND );
- if ( count( $pkDeleteConds ) >= $bSize ) {
- $dbw->delete( $table, $dbw->makeList( $pkDeleteConds, LIST_OR ), __METHOD__ );
- $lbFactory->commitAndWaitForReplication(
- __METHOD__, $this->ticket, [ 'domain' => $dbw->getDomainID() ]
- );
- $pkDeleteConds = [];
- }
- }
-
- if ( $pkDeleteConds ) {
- $dbw->delete( $table, $dbw->makeList( $pkDeleteConds, LIST_OR ), __METHOD__ );
- }
- }
-
- protected function getDB() {
- if ( !$this->db ) {
- $this->db = wfGetDB( DB_MASTER );
- }
-
- return $this->db;
- }
-