Do not resolve moves when adding a tracking

This commit is contained in:
Florine W. Dekker 2022-12-16 23:30:54 +01:00
parent c3fd28afaf
commit 217ffa88de
Signed by: FWDekker
GPG Key ID: D3DCFAA8A4560BE0
7 changed files with 13 additions and 9 deletions

View File

@ -1,7 +1,7 @@
{
"name": "fwdekker/death-notifier",
"description": "Get notified when a famous person dies.",
"version": "0.19.11", "_comment_version": "Also update version in `package.json`!",
"version": "0.19.12", "_comment_version": "Also update version in `package.json`!",
"type": "project",
"license": "MIT",
"homepage": "https://git.fwdekker.com/tools/death-notifier",

BIN
composer.lock generated

Binary file not shown.

BIN
package-lock.json generated

Binary file not shown.

View File

@ -1,6 +1,6 @@
{
"name": "death-notifier",
"version": "0.19.11", "_comment_version": "Also update version in `composer.json`!",
"version": "0.19.12", "_comment_version": "Also update version in `composer.json`!",
"description": "Get notified when a famous person dies.",
"author": "Florine W. Dekker",
"browser": "dist/bundle.js",

View File

@ -94,7 +94,7 @@ class AddTrackingAction extends Action
private function get_and_validate_page_info(string $person_name): array
{
try {
$info = $this->wikipedia->query_person_info([$person_name]);
$info = $this->wikipedia->query_person_info([$person_name], resolve_moves: false);
$normalized_name = $info->redirects->resolve($person_name);
} catch (WikipediaException $exception) {

View File

@ -85,7 +85,7 @@ class UpdateTrackingsAction extends Action
return;
try {
$people_statuses = $this->wikipedia->query_person_info($names);
$people_statuses = $this->wikipedia->query_person_info($names, resolve_moves: true);
} catch (WikipediaException $exception) {
$this->logger->error("Failed to query page info.", ["cause" => $exception, "pages" => $names]);
throw new UnexpectedException("Could not reach Wikipedia. Maybe the website is down?");

View File

@ -189,18 +189,20 @@ class Wikipedia
/**
* Sends a query request to the Wikipedia API in batches of {@see Wikipedia::ARTICLES_PER_QUERY} titles at a time,
* and resolves articles that were deleted because of a move.
* and optionally resolves articles that were deleted because of a move.
*
* @param array<string, mixed> $params the parameters to include in each query
* @param string[] $titles the titles of the pages to query
* @param string|null $continue_name the name of the continue parameter to follow for this request
* @param bool $resolve_moves `true` if and only if deleted pages that were moved should be resolved
* @return QueryOutput<mixed> the API's responses merged into a single `QueryOutput`
* @throws WikipediaException if the query fails
*/
private function api_query_batched_resolve_moves(array $params, array $titles,
?string $continue_name = null): QueryOutput
private function api_query_batched_resolve_moves(array $params, array $titles, ?string $continue_name = null,
bool $resolve_moves = true): QueryOutput
{
$output_base = $this->api_query_batched($params, $titles, $continue_name);
if (!$resolve_moves) return $output_base;
$not_moved = [];
$moves = [];
@ -280,17 +282,19 @@ class Wikipedia
* Wikipedia.
*
* @param string[] $names the names of the people to retrieve the information of
* @param bool $resolve_moves `true` if and only if deleted pages that were moved should be resolved
* @return QueryOutput<array{"type": ArticleType, "status": PersonStatus|null}> a `QueryOutput` with its
* {@see QueryOutput::$results} mapping each normalized title to its `ArticleType` and, if the type is `Person`, the
* `PersonStatus`
* @throws WikipediaException if the query fails
*/
public function query_person_info(array $names): QueryOutput
public function query_person_info(array $names, bool $resolve_moves): QueryOutput
{
$output = $this->api_query_batched_resolve_moves(
params: ["prop" => "categories", "cllimit" => strval(self::CATS_PER_QUERY)],
titles: $names,
continue_name: "clcontinue"
continue_name: "clcontinue",
resolve_moves: $resolve_moves
);
$articles =