Werdna has uploaded a new change for review.
https://gerrit.wikimedia.org/r/92480
Change subject: Fixes for recursive functions.
......................................................................
Fixes for recursive functions.
* Results were not being propagated from lower levels.
* Changed to use descriptive keys instead of integers.
Change-Id: Ic8fcaed00af03605125dee7c6aa83dc9b8fa52bb
---
M includes/Model/PostRevision.php
1 file changed, 21 insertions(+), 13 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/80/92480/1
diff --git a/includes/Model/PostRevision.php b/includes/Model/PostRevision.php
index 7e74c5d..35daa5d 100644
--- a/includes/Model/PostRevision.php
+++ b/includes/Model/PostRevision.php
@@ -181,6 +181,9 @@
* Used to defer going recursive more than once: if all recursive
* functionality is first registered, we can fetch all results in one
go.
*
+ * @param string $identifier A string identifier for this callback, to
be
+ * also passed to PostRevision::getRecursiveResult() to retrieve the
result
+ * of this callback.
* @param callable $callback The callback to call. 2 parameters:
* PostRevision (the post being iterated) & $result (the current result
at
* time of iteration). They must respond with [ $result, $continue ],
@@ -190,13 +193,11 @@
* @return int $i Identifier to pass to getRecursiveResult() to retrieve
* the callback's result
*/
- public function registerRecursive( $callback, $init ) {
- $i = count( $this->recursiveResults );
+ public function registerRecursive( $identifier, $callback, $init ) {
+ $this->recursiveCallbacks[$identifier] = $callback;
+ $this->recursiveResults[$identifier] = $init;
- $this->recursiveCallbacks[$i] = $callback;
- $this->recursiveResults[$i] = $init;
-
- return $i;
+ return $identifier;
}
/**
@@ -213,8 +214,8 @@
$this->recursiveResults
);
- // Once all callbacks have run, null the callbacks to make sure
they won't run again
- $this->recursiveCallbacks = array_fill( 0, count(
$this->recursiveResults ), null );
+ // Once all callbacks have run, empty out the callback list
+ $this->recursiveCallbacks = array();
return $this->recursiveResults[$registered];
}
@@ -244,6 +245,11 @@
if ( is_callable( $callback ) ) {
$return = $callback( $child,
$results[$i] );
+ if ( ! is_array( $return ) ) {
+ $continue = true;
+ continue;
+ }
+
// 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.
@@ -253,7 +259,7 @@
// If this specific callback has
responded it should no longer
// continue, get rid of it.
if ( $return[1] === false ) {
- $callbacks[$i] = null;
+ unset( $callbacks[$i] );
}
}
}
@@ -263,7 +269,7 @@
break;
}
- $results = $child->descendRecursive( $callbacks,
$results, $maxDepth - 1 );
+ $results = $child->descendRecursive( $callbacks,
$results, $maxDepth - 1 ) + $results;
}
return $results;
@@ -287,7 +293,7 @@
return array( $result + 1, true );
};
- return $this->registerRecursive( $callback, 0 );
+ return $this->registerRecursive( 'count', $callback, 0 );
}
/**
@@ -330,7 +336,7 @@
return array( $result, true );
};
- return $this->registerRecursive( $callback, array() );
+ return $this->registerRecursive( 'participants', $callback,
array() );
}
/**
@@ -356,9 +362,11 @@
if ( $post->getPostId()->equals( $postId ) ) {
return array( $post, false );
}
+
+ return array( null, true );
};
- return $this->registerRecursive( $callback, false );
+ return $this->registerRecursive(
'descendant:'.$postId->getHex(), $callback, false );
}
/**
--
To view, visit https://gerrit.wikimedia.org/r/92480
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: Ic8fcaed00af03605125dee7c6aa83dc9b8fa52bb
Gerrit-PatchSet: 1
Gerrit-Project: mediawiki/extensions/Flow
Gerrit-Branch: master
Gerrit-Owner: Werdna <[email protected]>
_______________________________________________
MediaWiki-commits mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/mediawiki-commits