Add return codes to ProfilePollQueue->add

This commit is contained in:
Hypolite Petovan 2018-11-13 22:00:07 -05:00
parent d231a9bc80
commit 2cabe10fa3
1 changed files with 15 additions and 6 deletions

View File

@ -9,28 +9,37 @@ use Friendica\Directory\Utils\Network;
*/
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);
if (!$url) {
return false;
return self::EMPTY_URL;
}
$host = parse_url($url, PHP_URL_HOST);
if (!$host) {
return false;
return self::MISSING_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',
['profile_url' => $url]
);
return true;
return ($affected == 1 ? 0 : self::ALREADY_EXISTS);
}
}