From 33e98d6264af1234bd37717d8ced7fdb34732353 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 15 Nov 2017 20:59:42 +0000 Subject: [PATCH 1/2] Moved some workers in their new habitat --- include/checkversion.php => src/Worker/CheckVersion.php | 0 include/tagupdate.php => src/Worker/TagUpdate.php | 0 include/threadupdate.php => src/Worker/ThreadUpdate.php | 0 include/update_gcontact.php => src/Worker/UpdateGContact.php | 0 4 files changed, 0 insertions(+), 0 deletions(-) rename include/checkversion.php => src/Worker/CheckVersion.php (100%) rename include/tagupdate.php => src/Worker/TagUpdate.php (100%) rename include/threadupdate.php => src/Worker/ThreadUpdate.php (100%) rename include/update_gcontact.php => src/Worker/UpdateGContact.php (100%) diff --git a/include/checkversion.php b/src/Worker/CheckVersion.php similarity index 100% rename from include/checkversion.php rename to src/Worker/CheckVersion.php diff --git a/include/tagupdate.php b/src/Worker/TagUpdate.php similarity index 100% rename from include/tagupdate.php rename to src/Worker/TagUpdate.php diff --git a/include/threadupdate.php b/src/Worker/ThreadUpdate.php similarity index 100% rename from include/threadupdate.php rename to src/Worker/ThreadUpdate.php diff --git a/include/update_gcontact.php b/src/Worker/UpdateGContact.php similarity index 100% rename from include/update_gcontact.php rename to src/Worker/UpdateGContact.php From 0aee6d383a4b53535ec6bf40168ab917b03527b2 Mon Sep 17 00:00:00 2001 From: Michael Date: Wed, 15 Nov 2017 21:12:33 +0000 Subject: [PATCH 2/2] Now there are four more ... --- include/Contact.php | 2 +- src/Worker/CheckVersion.php | 55 +++++++------- src/Worker/Cron.php | 2 +- src/Worker/TagUpdate.php | 8 +- src/Worker/ThreadUpdate.php | 10 ++- src/Worker/UpdateGContact.php | 136 +++++++++++++++++----------------- update.php | 4 +- 7 files changed, 113 insertions(+), 104 deletions(-) diff --git a/include/Contact.php b/include/Contact.php index cd77bb3bb9..3fa2410fbf 100644 --- a/include/Contact.php +++ b/include/Contact.php @@ -308,7 +308,7 @@ function get_contact_details_by_url($url, $uid = -1, $default = array()) { if ((($profile["addr"] == "") || ($profile["name"] == "")) && ($profile["gid"] != 0) && in_array($profile["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { - Worker::add(PRIORITY_LOW, "update_gcontact", $profile["gid"]); + Worker::add(PRIORITY_LOW, "UpdateGContact", $profile["gid"]); } // Show contact details of Diaspora contacts only if connected diff --git a/src/Worker/CheckVersion.php b/src/Worker/CheckVersion.php index 7d3c2de6f7..b7e99cb67e 100644 --- a/src/Worker/CheckVersion.php +++ b/src/Worker/CheckVersion.php @@ -1,10 +1,11 @@ 1) && (intval($argv[1]))) { - $contact_id = intval($argv[1]); + if (empty($contact_id)) { + logger('update_gcontact: no contact'); + return; + } + + $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); + + if (!DBM::is_result($r)) { + return; + } + + if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { + return; + } + + $data = Probe::uri($r[0]["url"]); + + if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { + if ($r[0]["server_url"] != "") + PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]); + + q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d", + dbesc(datetime_convert()), intval($contact_id)); + return; + } + + if (($data["name"] == "") && ($r[0]['name'] != "")) + $data["name"] = $r[0]['name']; + + if (($data["nick"] == "") && ($r[0]['nick'] != "")) + $data["nick"] = $r[0]['nick']; + + if (($data["addr"] == "") && ($r[0]['addr'] != "")) + $data["addr"] = $r[0]['addr']; + + if (($data["photo"] == "") && ($r[0]['photo'] != "")) + $data["photo"] = $r[0]['photo']; + + + q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s' + WHERE `id` = %d", + dbesc($data["name"]), + dbesc($data["nick"]), + dbesc($data["addr"]), + dbesc($data["photo"]), + intval($contact_id) + ); + + q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s' + WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'", + dbesc($data["name"]), + dbesc($data["nick"]), + dbesc($data["addr"]), + dbesc($data["photo"]), + dbesc(normalise_link($data["url"])) + ); + + q("UPDATE `contact` SET `addr` = '%s' + WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'", + dbesc($data["addr"]), + dbesc(normalise_link($data["url"])) + ); } - - if (!$contact_id) { - logger('update_gcontact: no contact'); - return; - } - - $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id)); - - if (!DBM::is_result($r)) { - return; - } - - if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { - return; - } - - $data = Probe::uri($r[0]["url"]); - - if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) { - if ($r[0]["server_url"] != "") - PortableContact::checkServer($r[0]["server_url"], $r[0]["network"]); - - q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d", - dbesc(datetime_convert()), intval($contact_id)); - return; - } - - if (($data["name"] == "") && ($r[0]['name'] != "")) - $data["name"] = $r[0]['name']; - - if (($data["nick"] == "") && ($r[0]['nick'] != "")) - $data["nick"] = $r[0]['nick']; - - if (($data["addr"] == "") && ($r[0]['addr'] != "")) - $data["addr"] = $r[0]['addr']; - - if (($data["photo"] == "") && ($r[0]['photo'] != "")) - $data["photo"] = $r[0]['photo']; - - - q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s' - WHERE `id` = %d", - dbesc($data["name"]), - dbesc($data["nick"]), - dbesc($data["addr"]), - dbesc($data["photo"]), - intval($contact_id) - ); - - q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s' - WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'", - dbesc($data["name"]), - dbesc($data["nick"]), - dbesc($data["addr"]), - dbesc($data["photo"]), - dbesc(normalise_link($data["url"])) - ); - - q("UPDATE `contact` SET `addr` = '%s' - WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'", - dbesc($data["addr"]), - dbesc(normalise_link($data["url"])) - ); } diff --git a/update.php b/update.php index 0b482535df..5cf9bbc2d4 100644 --- a/update.php +++ b/update.php @@ -1601,7 +1601,7 @@ function update_1169() { if (!$r) return UPDATE_FAILED; - Worker::add(PRIORITY_LOW, "threadupdate"); + Worker::add(PRIORITY_LOW, "ThreadUpdate"); return UPDATE_SUCCESS; } @@ -1650,7 +1650,7 @@ function update_1178() { function update_1180() { // Fill the new fields in the term table. - Worker::add(PRIORITY_LOW, "tagupdate"); + Worker::add(PRIORITY_LOW, "TagUpdate"); return UPDATE_SUCCESS; }