Matthias Mullie has uploaded a new change for review.
https://gerrit.wikimedia.org/r/289663
Change subject: More reliable post sorting
......................................................................
More reliable post sorting
Children need to be deleted before parents are, because one of the
listeners need to be able to fetch ids from the parents (which would
fail if those had been deleted already)
It seemed pretty safe to assume that a higher UUID would mean it was
created later, but it turns out to not always be the case.
ptwikibooks, for example, has a parent 'rp6m2xaut4127f99' with
child 'rp6m2wy4h0fzr14t', both of which were created on 20140214053720
(probably caused by randomizing part of the UUID to ensure uniques
for the same timestamp)
Instead of the earlier naive sorting method, this will iterate the
tree, thus guaranteeing we know which is child & which is parent.
Bug: T119509
Change-Id: I8bb08215f9d502122e2704836563861cbc79c6e6
---
M includes/Data/Index/BoardHistoryIndex.php
M maintenance/FlowRemoveOldTopics.php
2 files changed, 29 insertions(+), 8 deletions(-)
git pull ssh://gerrit.wikimedia.org:29418/mediawiki/extensions/Flow
refs/changes/63/289663/1
diff --git a/includes/Data/Index/BoardHistoryIndex.php
b/includes/Data/Index/BoardHistoryIndex.php
index 9c1fc54..e96bb89 100644
--- a/includes/Data/Index/BoardHistoryIndex.php
+++ b/includes/Data/Index/BoardHistoryIndex.php
@@ -11,6 +11,7 @@
use Flow\Model\PostSummary;
use Flow\Model\PostRevision;
use Flow\Model\TopicListEntry;
+use Flow\Model\UUID;
use Flow\Model\Workflow;
/**
diff --git a/maintenance/FlowRemoveOldTopics.php
b/maintenance/FlowRemoveOldTopics.php
index 12b20c0..4d92be0 100644
--- a/maintenance/FlowRemoveOldTopics.php
+++ b/maintenance/FlowRemoveOldTopics.php
@@ -240,17 +240,37 @@
}
}
- protected function removePosts( Workflow $workflow ) {
- // fetch all children (posts) from a topic
- $subtree = $this->treeRepo->fetchSubtreeIdentityMap(
$workflow->getId() );
+ /**
+ * @param UUID $parentId
+ * @param array $subtree
+ * @return array
+ */
+ protected function sortSubtree( UUID $parentId, array $subtree ) {
+ $flat = array();
- // reverse-sort all nodes: that way we'll never delete a parent
before
- // having already deleted a child (which will always be more
recent)
- krsort( $subtree );
+ // first recursively process all children, so they come first
in $flat
+ foreach ( $subtree['children'] as $id => $data ) {
+ $flat = array_merge(
+ $flat,
+ $this->sortSubtree( UUID::create( $id ), $data )
+ );
+ }
+
+ // then add parent, which should come last in $flat
+ $flat[] = $parentId;
+
+ return $flat;
+ }
+
+ protected function removePosts( Workflow $workflow ) {
+ // fetch all children (posts) from a topic & reverse-sort all
the posts:
+ // deepest-nested children should come first, parents last
+ $subtree = $this->treeRepo->fetchSubtree( $workflow->getId() );
+ $uuids = $this->sortSubtree( $workflow->getId(), $subtree );
$conds = array();
- foreach ( $subtree as $id => $data ) {
- $conds[] = array( 'rev_type_id' => UUID::create( $id )
);
+ foreach ( $uuids as $id ) {
+ $conds[] = array( 'rev_type_id' => $id );
}
$posts = $this->storage->findMulti( 'PostRevision', $conds );
--
To view, visit https://gerrit.wikimedia.org/r/289663
To unsubscribe, visit https://gerrit.wikimedia.org/r/settings
Gerrit-MessageType: newchange
Gerrit-Change-Id: I8bb08215f9d502122e2704836563861cbc79c6e6
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