jenkins-bot has submitted this change and it was merged. ( 
https://gerrit.wikimedia.org/r/388342 )

Change subject: Added an optional $maxdepth to CategoryFinder
......................................................................


Added an optional $maxdepth to CategoryFinder

Bug: T179065
Change-Id: I760bb75aa9f14d55456ea2d604a4c25234826403
---
M includes/CategoryFinder.php
1 file changed, 19 insertions(+), 2 deletions(-)

Approvals:
  Legoktm: Looks good to me, approved
  jenkins-bot: Verified



diff --git a/includes/CategoryFinder.php b/includes/CategoryFinder.php
index 2a70f5f..3561f7f 100644
--- a/includes/CategoryFinder.php
+++ b/includes/CategoryFinder.php
@@ -56,6 +56,9 @@
        /** @var array Array of article/category IDs */
        protected $next = [];
 
+       /** @var int Max layer depth **/
+       protected $maxdepth = -1;
+
        /** @var array Array of DBKEY category names */
        protected $targets = [];
 
@@ -73,12 +76,17 @@
         * @param array $articleIds Array of article IDs
         * @param array $categories FIXME
         * @param string $mode FIXME, default 'AND'.
+        * @param int $maxdepth Maximum layer depth. Where:
+        *      -1 means deep recursion (default);
+        *       0 means no-parents;
+        *       1 means one parent layer, etc.
         * @todo FIXME: $categories/$mode
         */
-       public function seed( $articleIds, $categories, $mode = 'AND' ) {
+       public function seed( $articleIds, $categories, $mode = 'AND', 
$maxdepth = -1 ) {
                $this->articles = $articleIds;
                $this->next = $articleIds;
                $this->mode = $mode;
+               $this->maxdepth = $maxdepth;
 
                # Set the list of target categories; convert them to DBKEY form 
first
                $this->targets = [];
@@ -98,8 +106,17 @@
         */
        public function run() {
                $this->dbr = wfGetDB( DB_REPLICA );
-               while ( count( $this->next ) > 0 ) {
+
+               $i = 0;
+               $dig = true;
+               while ( count( $this->next ) && $dig ) {
                        $this->scanNextLayer();
+
+                       // Is there any depth limit?
+                       if ( $this->maxdepth !== -1 ) {
+                               $dig = $i < $this->maxdepth;
+                               $i++;
+                       }
                }
 
                # Now check if this applies to the individual articles

-- 
To view, visit https://gerrit.wikimedia.org/r/388342
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings

Gerrit-MessageType: merged
Gerrit-Change-Id: I760bb75aa9f14d55456ea2d604a4c25234826403
Gerrit-PatchSet: 5
Gerrit-Project: mediawiki/core
Gerrit-Branch: master
Gerrit-Owner: Valerio Bozzolan <[email protected]>
Gerrit-Reviewer: Brian Wolff <[email protected]>
Gerrit-Reviewer: EddieGP <[email protected]>
Gerrit-Reviewer: Legoktm <[email protected]>
Gerrit-Reviewer: Paladox <[email protected]>
Gerrit-Reviewer: Reedy <[email protected]>
Gerrit-Reviewer: jenkins-bot <>

_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits

Reply via email to