jenkins-bot has submitted this change and it was merged.

Change subject: Recursive function should also perform callback on initial 
element (usually topic title)
......................................................................


Recursive function should also perform callback on initial element (usually 
topic title)

Change-Id: I984387221eda04b007802c2f2312574f9368122c
---
M includes/Model/PostRevision.php
1 file changed, 32 insertions(+), 28 deletions(-)

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



diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index 553681e..7772838 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -225,8 +225,8 @@
        }
 
        /**
-        * Runs all registered callback on every descendant of this post & 
recursive
-        * from there on, until $maxDepth has been reached.
+        * Runs all registered callback on this post and all descendants to a
+        * maximum depth of $maxDepth
         *
         * @param array $callbacks Array of callbacks to execute. Callbacks are 
fed
         * 2 parameters: PostRevision (the post being iterated) & $result (the 
current
@@ -242,36 +242,39 @@
                        return;
                }
 
-               foreach ( $this->getChildren() as $child ) {
-                       $continue = false;
+               $continue = false;
+               foreach ( $callbacks as $i => $callback ) {
+                       if ( is_callable( $callback ) ) {
+                               $return = $callback( $this, $results[$i] );
 
-                       foreach ( $callbacks as $i => $callback ) {
-                               if ( is_callable( $callback ) ) {
-                                       $return = $callback( $child, 
$results[$i] );
+                               // Callbacks respond with: [ result, continue ]
+                               // Continue can be set to false if a callback 
has completed
+                               // what it set out to do, then we can stop 
running it.
+                               $results[$i] = $return[0];
+                               $continue |= $return[1];
 
-                                       // Callbacks respond with: [ result, 
continue ]
-                                       // Continue can be set to false if a 
callback has completed
-                                       // what it set out to do, then we can 
stop running it.
-                                       $results[$i] = $return[0];
-                                       $continue |= $return[1];
-
-                                       // If this specific callback has 
responded it should no longer
-                                       // continue, get rid of it.
-                                       if ( $return[1] === false ) {
-                                               $callbacks[$i] = null;
-                                       }
+                               // If this specific callback has responded it 
should no longer
+                               // continue, get rid of it.
+                               if ( $return[1] === false ) {
+                                       $callbacks[$i] = null;
                                }
                        }
-
-                       // All of the callbacks have completed what they set 
out to do = quit
-                       if ( !$continue ) {
-                               break;
-                       }
-
-                       // Also fetch callbacks from children, some may have 
been nulled to
-                       // prevent further execution.
-                       list( $callbacks, $results ) = 
$child->descendRecursive( $callbacks, $results, $maxDepth - 1 );
                }
+
+               // All of the callbacks have completed what they set out to do 
= quit
+               if ( $continue ) {
+                       foreach ( $this->getChildren() as $child ) {
+                               // Also fetch callbacks from children, some may 
have been nulled to
+                               // prevent further execution.
+                               list( $callbacks, $results ) = 
$child->descendRecursive( $callbacks, $results, $maxDepth - 1 );
+
+                               // Check to see if we should exit
+                               if ( ! count( array_filter( $callbacks ) ) ) {
+                                       break;
+                               }
+                       }
+               }
+
 
                return array( $callbacks, $results );
        }
@@ -294,7 +297,8 @@
                        return array( $result + 1, true );
                };
 
-               return $this->registerRecursive( $callback, 0, 'count' );
+               // Start at -1 because parent doesn't count as "descendant"
+               return $this->registerRecursive( $callback, -1, 'count' );
        }
 
        /**

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

Gerrit-MessageType: merged
Gerrit-Change-Id: I984387221eda04b007802c2f2312574f9368122c
Gerrit-PatchSet: 2
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
Gerrit-Reviewer: EBernhardson <[email protected]>
Gerrit-Reviewer: Matthias Mullie <[email protected]>
Gerrit-Reviewer: Werdna <[email protected]>
Gerrit-Reviewer: jenkins-bot

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

Reply via email to