Update feed URL after permanent redirect

This commit is contained in:
Matthew Exon 2024-07-01 18:50:13 +02:00
parent 918317fa49
commit 31f103a1f0
5 changed files with 63 additions and 2 deletions

View file

@ -167,12 +167,23 @@ class OnePoll
$cookiejar = tempnam(System::getTempPath(), 'cookiejar-onepoll-');
$curlResult = DI::httpClient()->get($contact['poll'], HttpClientAccept::FEED_XML, [HttpClientOptions::COOKIEJAR => $cookiejar, HttpClientOptions::REQUEST => HttpClientRequest::FEEDFETCHER]);
unlink($cookiejar);
Logger::debug('Polled feed', ['url' => $contact['poll'], 'http-code' => $curlResult->getReturnCode(), 'redirect-url' => $curlResult->getRedirectUrl()]);
if ($curlResult->isTimeout()) {
Logger::notice('Polling timed out', ['id' => $contact['id'], 'url' => $contact['poll']]);
return false;
}
if ($curlResult->redirectIsPermanent()) {
Logger::notice('Poll address permanently changed', [
'id' => $contact['id'],
'uid' => $contact['uid'],
'old' => $contact['poll'],
'new' => $curlResult->getRedirectUrl(),
]);
$success = Contact::updatePollUrl($contact['id'], $curlResult->getRedirectUrl());
}
$xml = $curlResult->getBodyString();
if (empty($xml)) {
Logger::notice('Empty content', ['id' => $contact['id'], 'url' => $contact['poll']]);