4 * @file src/Worker/UpdateGcontact.php
7 namespace Friendica\Worker;
9 use Friendica\Database\DBM;
10 use Friendica\Network\Probe;
11 use Friendica\Protocol\PortableContact;
12 use Friendica\Util\DateTimeFormat;
16 public static function execute($contact_id)
20 logger('update_gcontact: start');
22 if (empty($contact_id)) {
23 logger('update_gcontact: no contact');
27 $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
29 if (!DBM::is_result($r)) {
33 if (!in_array($r[0]["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
37 $data = Probe::uri($r[0]["url"]);
39 if (!in_array($data["network"], [NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS])) {
40 if ($r[0]["server_url"] != "") {
41 PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]);
44 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
45 dbesc(DateTimeFormat::utcNow()), intval($contact_id));
49 if (($data["name"] == "") && ($r[0]['name'] != "")) {
50 $data["name"] = $r[0]['name'];
53 if (($data["nick"] == "") && ($r[0]['nick'] != "")) {
54 $data["nick"] = $r[0]['nick'];
57 if (($data["addr"] == "") && ($r[0]['addr'] != "")) {
58 $data["addr"] = $r[0]['addr'];
61 if (($data["photo"] == "") && ($r[0]['photo'] != "")) {
62 $data["photo"] = $r[0]['photo'];
66 q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
71 dbesc($data["photo"]),
75 q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
76 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
80 dbesc($data["photo"]),
81 dbesc(normalise_link($data["url"]))
84 q("UPDATE `contact` SET `addr` = '%s'
85 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
87 dbesc(normalise_link($data["url"]))