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