X-Git-Url: https://git.heureux-cyclage.org/?a=blobdiff_plain;f=includes%2FCategory.php;h=3352c2c2b039dc0eeec6e6e8c55e37d9ab5b4424;hb=d819f37fbb459549c43e15ae44a9234ae3e485e9;hp=f8ac8aeb59d1ccdca3a90e75550a959a09dfaef5;hpb=5fc5d3cc5908a23bb59c924842d0087372877349;p=lhc%2Fweb%2Fwiklou.git diff --git a/includes/Category.php b/includes/Category.php index f8ac8aeb59..3352c2c2b0 100644 --- a/includes/Category.php +++ b/includes/Category.php @@ -420,4 +420,45 @@ class Category { return true; } + + /** + * Call refreshCounts() if there are no entries in the categorylinks table + * or if the category table has a row that states that there are no entries + * + * Due to lock errors or other failures, the precomputed counts can get out of sync, + * making it hard to know when to delete the category row without checking the + * categorylinks table. + * + * @return bool Whether links were refreshed + * @since 1.32 + */ + public function refreshCountsIfEmpty() { + $dbw = wfGetDB( DB_MASTER ); + + $hasLink = $dbw->selectField( + 'categorylinks', + '1', + [ 'cl_to' => $this->getName() ], + __METHOD__ + ); + if ( !$hasLink ) { + $this->refreshCounts(); // delete any category table entry + + return true; + } + + $hasBadRow = $dbw->selectField( + 'category', + '1', + [ 'cat_title' => $this->getName(), 'cat_pages <= 0' ], + __METHOD__ + ); + if ( $hasBadRow ) { + $this->refreshCounts(); // clean up this row + + return true; + } + + return false; + } }