Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/93481
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, 25 insertions(+), 26 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/81/93481/1
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index 553681e..caea822 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -242,36 +242,34 @@
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 );
+ }
+ }
+
return array( $callbacks, $results );
}
@@ -294,7 +292,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: newchange
Gerrit-Change-Id: I984387221eda04b007802c2f2312574f9368122c
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Matthias Mullie <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits