Add return codes to ProfilePollQueue->add
This commit is contained in:
parent
d231a9bc80
commit
2cabe10fa3
|
@ -9,28 +9,37 @@ use Friendica\Directory\Utils\Network;
|
||||||
*/
|
*/
|
||||||
class ProfilePollQueue extends \Friendica\Directory\Model
|
class ProfilePollQueue extends \Friendica\Directory\Model
|
||||||
{
|
{
|
||||||
public function add(string $profile_url): bool
|
const EMPTY_URL = 1;
|
||||||
|
const MISSING_HOST = 2;
|
||||||
|
const PRIVATE_HOST = 3;
|
||||||
|
const ALREADY_EXISTS = 4;
|
||||||
|
|
||||||
|
/**
|
||||||
|
* @param string $profile_url
|
||||||
|
* @return int 0 on success or error code
|
||||||
|
*/
|
||||||
|
public function add(string $profile_url): int
|
||||||
{
|
{
|
||||||
$url = trim($profile_url);
|
$url = trim($profile_url);
|
||||||
|
|
||||||
if (!$url) {
|
if (!$url) {
|
||||||
return false;
|
return self::EMPTY_URL;
|
||||||
}
|
}
|
||||||
|
|
||||||
$host = parse_url($url, PHP_URL_HOST);
|
$host = parse_url($url, PHP_URL_HOST);
|
||||||
if (!$host) {
|
if (!$host) {
|
||||||
return false;
|
return self::MISSING_HOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (Network::isPublicHost($host)) {
|
if (Network::isPublicHost($host)) {
|
||||||
return false;
|
return self::PRIVATE_HOST;
|
||||||
}
|
}
|
||||||
|
|
||||||
$this->atlas->perform(
|
$affected = $this->atlas->fetchAffected(
|
||||||
'INSERT IGNORE INTO `profile_poll_queue` SET `profile_url` = :profile_url',
|
'INSERT IGNORE INTO `profile_poll_queue` SET `profile_url` = :profile_url',
|
||||||
['profile_url' => $url]
|
['profile_url' => $url]
|
||||||
);
|
);
|
||||||
|
|
||||||
return true;
|
return ($affected == 1 ? 0 : self::ALREADY_EXISTS);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue