-
Notifications
You must be signed in to change notification settings - Fork 16
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a method to PagePurger for purging multiple pages at once #36
Conversation
The function iterates through each page and calls the purge method Bug: T145364
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks really great! I've just a couple of pedantic points to raise about documentation. :-)
The main thing missing I reckon is a mention of the multi-page purge feature (or the single one for that matter!) in docs/page_purger.rst
. Could you add that?
@@ -43,6 +44,24 @@ public function purge( Page $page ) { | |||
} | |||
|
|||
/** | |||
* @since 0.x |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It'd be good to add a brief description to this method and to the purge()
method, and perhaps also a longer description to both mentioning the existence of the other; makes it easier for people using autocomplete. (Brief descriptions are one-liners, and detailed descriptions are separated below these by a blank line; see http://www.stack.nl/~dimitri/doxygen/manual/docblocks.html for more.)
Also, I'd leave out the @since
, because it's not clear yet what it'll be released as (although, @addshore do you have any guidelines about this? Are you using Semantic Versioning? If so, this should be @since 0.7.0
as that's the next minor version number that we'll hit).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Adding @SInCE 0.7 should be fine for now (Before releases I review everything anyway).
Semver is indeed used, but I have only been doing 0.x as in theory nothing would be added in a 0.x.>1 release.
Either 0.7 or 0.7.0 are both fine for me!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will write a more detailed documentation for both functions
* @param Pages $pages | ||
* | ||
* @return bool | ||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There shouldn't be an empty line after the @return
tag. Also, it'd be good to explain the return value (however, see my comment below).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will remove the empty line
$this->purge( $page ); | ||
} | ||
|
||
return true; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What's the point of always returning true? I'd say either leave this out (and update the docblock to @return void
) or have explain when this will return true and when other things might happen.
I realise that this is just following the pattern set by the purge()
method, but I'd question that one too; perhaps we can make them both better?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I can return true/false if the request have succeed $this->api->postRequest(..)
returns an array and I can check for the response. It is a good idea to apply this logic at purge()
too.
Another idea is to return the response array, this idea gives more freedom but those who will use the library will have to do more check (if needed).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I would be against passing the raw result out of the method. But I don't feel too strongly really.
I think I prefer the true / false based on request success, although I guess to fit with everything else a request that fails would just throw an exception.
maybe void is the way to go?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah, I think checking the result of the request would be best (and, as you say, that won't matter if the request throws an exception). I guess it just means that if no pages were purged, false
will be returned? Actually, there are three results possible for each page: purged
, missing
, and invalid
. Perhaps the purge methods should return true only when all results are purged
and false if any are the other two?
* @return bool | ||
* | ||
*/ | ||
public function purgePages( Pages $pages ) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So, the more efficient way of implementing this method would be to do this in a single call.
See https://en.wikipedia.org/w/api.php?action=help&modules=purge
Multiple pages can be purged in a single request.
However I would be fine to merge this as is as an initial implementation.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, I will implement it and update the pull request
Add comments and brief on both purge and purgePages. purgePages function now purge all pages in a single request by sumbiting at the 'purge' action all the pages ids in a multi-value seperation
* | ||
* @return bool | ||
* Purges all the pages of the Pages object | ||
* by submitting a 'purge' action to the wikipedia |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mediawiki api
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
you are right 👍
} | ||
|
||
// convert an array to multiple-value format | ||
// because the wikipedia api require multiple |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
mediawiki api
* | ||
* @param Pages $pages the pages that are going to be purged | ||
* | ||
* @return bool |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Is it a good idea to return boolean true if SimpleRequest have been successful or return the SimpleRequest response object/array ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
One possibility would be to return a Pages object containing only the successfully purged pages (i.e. the ones with a purged
response). That way, people using this could check if the returned set of pages is the same as what they put in (and in some cases perhaps take other action for invalid
or missing
pages). This would make it hard to tell the difference between invalid
and missing
, though, which isn't so good. @addshore what do you think?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does the API response list the pages that were successfully purged?
If so then yes perhaps returning a Pages object here would make sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, it does (e.g.).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yep, I think returning a Pages object sounds like a nice idea then!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Should I do the same with the purge method ?
or is it better to implement the logic to return true/false ?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think for a single purge the boolean return may still make more sense?
But I don't have a strong opinion either way, returning a Page / null may also make sense!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I implemented the logic to return boolean, at the purge(...) function, it is easy to change to return Page object
* purge() implemented the logic to return true or false when the page was successfully purged * purgePages() return Pages object containing only the successfully purged pages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Testing error
new SimpleRequest( 'purge', [ 'pageids' => $page->getId() ] ) | ||
); | ||
|
||
return true; | ||
// the purge response for the page | ||
$purgeResponse = $responseArray['purge'][0]; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This and the other occurance at line 95 make tests to fail, is it a good idea to place the following workaround ?
// if the purge action failed unexpected
if ( !array_key_exists( 'purge' , $responseArray) ) {
return false; / return new Pages();
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change the test to return real response
* updated testPurgePage. Now the postRequest method return a "real" response * added positive test path for purgePages
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great! Just a couple of comments re testPurgePages.
), new Page( | ||
new PageIdentifier( | ||
new Title( 'Bar', 1 ), | ||
123 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The two test pages shouldn't have the same ID. And is it worth adding in a third page, that won't be returned as purged (or do some other sort of extra test) just to make sure that missing and invalid responses are handled as we expect?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Noted, I will change the ID. Also I will create a new test for the case that a page is not purged
new Title( 'Bar', 1 ), | ||
123 | ||
), | ||
new Revisions( [] ) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If no $revisions
parameter is passed, a new Revisions will be created in the Page constructor — so don't worry about passing this in.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the information
we test if a non existent page is not returned in the purged Pages object after we run the purgePages command
The only thing is missing now is the following document |
@BlackSpirit96 do you feel like writing that one? :) |
I will write it :) |
Bah, I should have / could have squashed that before merging, but oh well! it is in! :) |
The function iterates through each page and calls the purge method
Bug T145364