use Exception;
use Friendica\Content\Text\HTML;
use Friendica\Core\Config;
+use Friendica\Core\Logger;
use Friendica\Core\Protocol;
use Friendica\Core\Worker;
use Friendica\Database\DBA;
$url = $url . (($uid) ? '/@me/@all?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation' : '?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation') ;
- logger('load: ' . $url, LOGGER_DEBUG);
+ Logger::log('load: ' . $url, LOGGER_DEBUG);
- $s = Network::fetchUrl($url);
+ $fetchresult = Network::fetchUrlFull($url);
+ $s = $fetchresult->getBody();
- logger('load: returns ' . $s, LOGGER_DATA);
+ Logger::log('load: returns ' . $s, LOGGER_DATA);
- logger('load: return code: ' . Network::getCurl()->getCode(), LOGGER_DEBUG);
+ Logger::log('load: return code: ' . $fetchresult->getReturnCode(), LOGGER_DEBUG);
- if ((Network::getCurl()->getCode() > 299) || (! $s)) {
+ if (($fetchresult->getReturnCode() > 299) || (! $s)) {
return;
}
$j = json_decode($s, true);
- logger('load: json: ' . print_r($j, true), LOGGER_DATA);
+ Logger::log('load: json: ' . print_r($j, true), LOGGER_DATA);
if (!isset($j['entry'])) {
return;
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
GContact::link($gcid, $uid, $cid, $zcid);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
}
- logger("load: loaded $total entries", LOGGER_DEBUG);
+ Logger::log("load: loaded $total entries", LOGGER_DEBUG);
$condition = ["`cid` = ? AND `uid` = ? AND `zcid` = ? AND `updated` < UTC_TIMESTAMP - INTERVAL 2 DAY", $cid, $uid, $zcid];
DBA::delete('glink', $condition);
$contact = ["url" => $profile];
- if ($gcontacts[0]["created"] <= NULL_DATE) {
+ if ($gcontacts[0]["created"] <= DBA::NULL_DATETIME) {
$contact['created'] = DateTimeFormat::utcNow();
}
}
if (!in_array($gcontacts[0]["network"], [Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::FEED, Protocol::OSTATUS, ""])) {
- logger("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile.": Network type ".$gcontacts[0]["network"]." can't be checked", LOGGER_DEBUG);
return false;
}
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
}
- logger("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile.": Server ".$server_url." wasn't reachable.", LOGGER_DEBUG);
return false;
}
$contact['server_url'] = $server_url;
$fields = ['last_contact' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$noscrape["updated"]." (noscrape)", LOGGER_DEBUG);
return $noscrape["updated"];
}
// If we only can poll the feed, then we only do this once a while
if (!$force && !self::updateNeeded($gcontacts[0]["created"], $gcontacts[0]["updated"], $gcontacts[0]["last_failure"], $gcontacts[0]["last_contact"])) {
- logger("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$gcontacts[0]["updated"]." (cached)", LOGGER_DEBUG);
GContact::update($contact);
return $gcontacts[0]["updated"];
self::lastUpdated($data["url"], $force);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
- logger("Profile ".$profile." was deleted", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was deleted", LOGGER_DEBUG);
return false;
}
$fields = ['last_failure' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (profile)", LOGGER_DEBUG);
return false;
}
$fields = ['last_failure' => DateTimeFormat::utcNow()];
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
- logger("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." wasn't reachable (no feed)", LOGGER_DEBUG);
return false;
}
// Maybe there aren't any entries. Then check if it is a valid feed
if ($last_updated == "") {
if ($xpath->query('/atom:feed')->length > 0) {
- $last_updated = NULL_DATE;
+ $last_updated = DBA::NULL_DATETIME;
}
}
DBA::update('gcontact', $fields, ['nurl' => normalise_link($profile)]);
}
- logger("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
+ Logger::log("Profile ".$profile." was last updated at ".$last_updated, LOGGER_DEBUG);
return $last_updated;
}
foreach ($nodeinfo['links'] as $link) {
if (!is_array($link) || empty($link['rel'])) {
- logger('Invalid nodeinfo format for ' . $server_url, LOGGER_DEBUG);
+ Logger::log('Invalid nodeinfo format for ' . $server_url, LOGGER_DEBUG);
continue;
}
if ($link['rel'] == 'http://nodeinfo.diaspora.software/ns/schema/1.0') {
$gserver = DBA::selectFirst('gserver', [], ['nurl' => normalise_link($server_url)]);
if (DBA::isResult($gserver)) {
- if ($gserver["created"] <= NULL_DATE) {
+ if ($gserver["created"] <= DBA::NULL_DATETIME) {
$fields = ['created' => DateTimeFormat::utcNow()];
$condition = ['nurl' => normalise_link($server_url)];
DBA::update('gserver', $fields, $condition);
// See discussion under https://forum.friendi.ca/display/0b6b25a8135aabc37a5a0f5684081633
// It can happen that a zero date is in the database, but storing it again is forbidden.
- if ($last_contact < NULL_DATE) {
- $last_contact = NULL_DATE;
+ if ($last_contact < DBA::NULL_DATETIME) {
+ $last_contact = DBA::NULL_DATETIME;
}
- if ($last_failure < NULL_DATE) {
- $last_failure = NULL_DATE;
+ if ($last_failure < DBA::NULL_DATETIME) {
+ $last_failure = DBA::NULL_DATETIME;
}
if (!$force && !self::updateNeeded($gserver["created"], "", $last_failure, $last_contact)) {
- logger("Use cached data for server ".$server_url, LOGGER_DEBUG);
+ Logger::log("Use cached data for server ".$server_url, LOGGER_DEBUG);
return ($last_contact >= $last_failure);
}
} else {
$register_policy = -1;
$registered_users = 0;
- $last_contact = NULL_DATE;
- $last_failure = NULL_DATE;
+ $last_contact = DBA::NULL_DATETIME;
+ $last_failure = DBA::NULL_DATETIME;
}
- logger("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." is outdated or unknown. Start discovery. Force: ".$force." Created: ".$gserver["created"]." Failure: ".$last_failure." Contact: ".$last_contact, LOGGER_DEBUG);
$failure = false;
$possible_failure = false;
// But we want to make sure to only quit if we are mostly sure that this server url fits.
if (DBA::isResult($gserver) && ($orig_server_url == $server_url) &&
($curlResult->isTimeout())) {
- logger("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
+ Logger::log("Connection to server ".$server_url." timed out.", LOGGER_DEBUG);
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
return false;
}
// Quit if there is a timeout
if ($curlResult->isTimeout()) {
- logger("Connection to server " . $server_url . " timed out.", LOGGER_DEBUG);
+ Logger::log("Connection to server " . $server_url . " timed out.", LOGGER_DEBUG);
DBA::update('gserver', ['last_failure' => DateTimeFormat::utcNow()], ['nurl' => normalise_link($server_url)]);
return false;
}
}
if (($last_contact <= $last_failure) && !$failure) {
- logger("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be alive, but last contact wasn't set - could be a bug", LOGGER_DEBUG);
} elseif (($last_contact >= $last_failure) && $failure) {
- logger("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
+ Logger::log("Server ".$server_url." seems to be dead, but last failure wasn't set - could be a bug", LOGGER_DEBUG);
}
// Check again if the server exists
self::discoverRelay($server_url);
}
- logger("End discovery for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("End discovery for server " . $server_url, LOGGER_DEBUG);
return !$failure;
}
*/
private static function discoverRelay($server_url)
{
- logger("Discover relay data for server " . $server_url, LOGGER_DEBUG);
+ Logger::log("Discover relay data for server " . $server_url, LOGGER_DEBUG);
$curlResult = Network::curl($server_url . "/.well-known/x-social-relay");
$r = q("SELECT `nurl` FROM `gserver` WHERE `nurl` = '%s'", DBA::escape(normalise_link($server_url)));
if (!DBA::isResult($r)) {
- logger("Call server check for server ".$server_url, LOGGER_DEBUG);
+ Logger::log("Call server check for server ".$server_url, LOGGER_DEBUG);
Worker::add(PRIORITY_LOW, "DiscoverPoCo", "server", $server_url);
}
}
// Fetch all users from the other server
$url = $server["poco"] . "/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation";
- logger("Fetch all users from the server " . $server["url"], LOGGER_DEBUG);
+ Logger::log("Fetch all users from the server " . $server["url"], LOGGER_DEBUG);
$curlResult = Network::curl($url);
$curlResult = Network::curl($url);
if ($curlResult->isSuccess() && !empty($curlResult->getBody())) {
- logger("Fetch all global contacts from the server " . $server["nurl"], LOGGER_DEBUG);
+ Logger::log("Fetch all global contacts from the server " . $server["nurl"], LOGGER_DEBUG);
$data = json_decode($curlResult->getBody(), true);
if (!empty($data)) {
}
if (!$success && (Config::get('system', 'poco_discovery') > 2)) {
- logger("Fetch contacts from users of the server " . $server["nurl"], LOGGER_DEBUG);
+ Logger::log("Fetch contacts from users of the server " . $server["nurl"], LOGGER_DEBUG);
self::discoverServerUsers($data, $server);
}
}
continue;
}
- logger('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], LOGGER_DEBUG);
+ Logger::log('Update directory from server ' . $gserver['url'] . ' with ID ' . $gserver['id'], LOGGER_DEBUG);
Worker::add(PRIORITY_LOW, 'DiscoverPoCo', 'update_server_directory', (int) $gserver['id']);
if (!$complete && ( --$no_of_queries == 0)) {
}
if ($username != '') {
- logger('Fetch contacts for the user ' . $username . ' from the server ' . $server['nurl'], LOGGER_DEBUG);
+ Logger::log('Fetch contacts for the user ' . $username . ' from the server ' . $server['nurl'], LOGGER_DEBUG);
// Fetch all contacts from a given user from the other server
$url = $server['poco'] . '/' . $username . '/?fields=displayName,urls,photos,updated,network,aboutMe,currentLocation,tags,gender,contactType,generation';
$connect_url = '';
$name = '';
$network = '';
- $updated = NULL_DATE;
+ $updated = DBA::NULL_DATETIME;
$location = '';
$about = '';
$keywords = '';
if ($generation > 0) {
$success = true;
- logger("Store profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Store profile ".$profile_url, LOGGER_DEBUG);
$gcontact = ["url" => $profile_url,
"name" => $name,
$gcontact = GContact::sanitize($gcontact);
GContact::update($gcontact);
} catch (Exception $e) {
- logger($e->getMessage(), LOGGER_DEBUG);
+ Logger::log($e->getMessage(), LOGGER_DEBUG);
}
- logger("Done for profile ".$profile_url, LOGGER_DEBUG);
+ Logger::log("Done for profile ".$profile_url, LOGGER_DEBUG);
}
}
return $success;