mirror of
https://github.com/friendica/friendica
synced 2024-12-22 17:20:16 +00:00
Remove contact immediately on 410 response code
This commit is contained in:
parent
946337645d
commit
2b617fc5c2
4 changed files with 44 additions and 0 deletions
|
@ -84,6 +84,13 @@ interface ICanHandleHttpResponses
|
|||
*/
|
||||
public function isSuccess(): bool;
|
||||
|
||||
/**
|
||||
* Returns if the URL is permanently gone (return code 410)
|
||||
*
|
||||
* @return bool
|
||||
*/
|
||||
public function isGone(): bool;
|
||||
|
||||
/**
|
||||
* @return string
|
||||
*/
|
||||
|
|
|
@ -56,6 +56,11 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
*/
|
||||
private $isSuccess;
|
||||
|
||||
/**
|
||||
* @var boolean true (if HTTP 410 result) or false
|
||||
*/
|
||||
private $isGone;
|
||||
|
||||
/**
|
||||
* @var string the URL which was called
|
||||
*/
|
||||
|
@ -148,6 +153,7 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
|
||||
$this->parseBodyHeader($result);
|
||||
$this->checkSuccess();
|
||||
$this->checkGone();
|
||||
$this->checkRedirect();
|
||||
$this->checkInfo();
|
||||
}
|
||||
|
@ -194,6 +200,11 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
}
|
||||
}
|
||||
|
||||
private function checkGone()
|
||||
{
|
||||
$this->isGone = $this->returnCode == 410;
|
||||
}
|
||||
|
||||
private function checkRedirect()
|
||||
{
|
||||
if (!array_key_exists('url', $this->info)) {
|
||||
|
@ -322,6 +333,12 @@ class CurlResult implements ICanHandleHttpResponses
|
|||
return $this->isSuccess;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function isGone(): bool
|
||||
{
|
||||
return $this->isSuccess;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getUrl(): string
|
||||
{
|
||||
|
|
|
@ -38,6 +38,8 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
private $isTimeout;
|
||||
/** @var boolean */
|
||||
private $isSuccess;
|
||||
/** @var boolean */
|
||||
private $isGone;
|
||||
/**
|
||||
* @var int the error number or 0 (zero) if no error
|
||||
*/
|
||||
|
@ -63,6 +65,7 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
$this->errorNumber = $errorNumber;
|
||||
|
||||
$this->checkSuccess();
|
||||
$this->checkGone();
|
||||
$this->checkRedirect($response);
|
||||
}
|
||||
|
||||
|
@ -86,6 +89,11 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
}
|
||||
}
|
||||
|
||||
private function checkGone()
|
||||
{
|
||||
$this->isGone = $this->getStatusCode() == 410;
|
||||
}
|
||||
|
||||
private function checkRedirect(ResponseInterface $response)
|
||||
{
|
||||
$headersRedirect = $response->getHeader(RedirectMiddleware::HISTORY_HEADER) ?? [];
|
||||
|
@ -135,6 +143,12 @@ class GuzzleResponse extends Response implements ICanHandleHttpResponses, Respon
|
|||
return $this->isSuccess;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function isGone(): bool
|
||||
{
|
||||
return $this->isGone;
|
||||
}
|
||||
|
||||
/** {@inheritDoc} */
|
||||
public function getUrl(): string
|
||||
{
|
||||
|
|
|
@ -174,6 +174,12 @@ class OnePoll
|
|||
return false;
|
||||
}
|
||||
|
||||
if ($curlResult->isGone()) {
|
||||
Logger::notice('URL is permanently gone', ['id' => $contact['id'], 'url' => $contact['poll']]);
|
||||
Contact::remove($contact['id']);
|
||||
return false;
|
||||
}
|
||||
|
||||
if ($curlResult->redirectIsPermanent()) {
|
||||
Logger::notice('Poll address permanently changed', [
|
||||
'id' => $contact['id'],
|
||||
|
|
Loading…
Reference in a new issue