]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/OnePoll.php
codeblock updates
[friendica.git] / src / Worker / OnePoll.php
index 4e0de487e1bbaadf82032570640fd6c1e8775731..2d36ee8f47c49efdb91b42e6545b1dc470f0b868 100644 (file)
@@ -28,13 +28,9 @@ class OnePoll
        {
                $a = BaseObject::getApp();
 
-               Logger::log('start');
+               Logger::log('Start for contact ' . $contact_id);
 
-               $manual_id  = 0;
-               $generation = 0;
-               $hub_update = false;
                $force      = false;
-               $restart    = false;
 
                if ($command == "force") {
                        $force = true;
@@ -45,7 +41,6 @@ class OnePoll
                        return;
                }
 
-               $d = DateTimeFormat::utcNow();
 
                $contact = DBA::selectFirst('contact', [], ['id' => $contact_id]);
                if (!DBA::isResult($contact)) {
@@ -69,6 +64,7 @@ class OnePoll
                        if (($contact['network'] === Protocol::ACTIVITYPUB) && empty($apcontact)) {
                                self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        } elseif (!empty($apcontact)) {
                                $fields = ['last-update' => $updated, 'success_update' => $updated];
@@ -96,6 +92,7 @@ class OnePoll
                        } else {
                                self::updateContact($contact, ['last-update' => $updated, 'failure_update' => $updated]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        }
                }
@@ -104,7 +101,7 @@ class OnePoll
                if (in_array($contact['network'], [Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::DIASPORA, Protocol::DFRN])) {
                        $updated = DateTimeFormat::utcNow();
                        // Currently we can't check every AP implementation, so we don't do it at all
-                       if (($contact['network' != Protocol::ACTIVITYPUB]) && !PortableContact::reachable($contact['url'])) {
+                       if (($contact['network'] != Protocol::ACTIVITYPUB) && !PortableContact::reachable($contact['url'])) {
                                Logger::log("Skipping probably dead contact ".$contact['url']);
 
                                // set the last-update so we don't keep polling
@@ -116,6 +113,7 @@ class OnePoll
                                // set the last-update so we don't keep polling
                                self::updateContact($contact, ['last-update' => $updated]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        } else {
                                $fields = ['last-update' => $updated, 'success_update' => $updated];
@@ -125,7 +123,7 @@ class OnePoll
                }
 
                // load current friends if possible.
-               if (!emoty($contact['poco']) && ($contact['success_update'] > $contact['failure_update'])) {
+               if (!empty($contact['poco']) && ($contact['success_update'] > $contact['failure_update'])) {
                        $r = q("SELECT count(*) AS total FROM glink
                                WHERE `cid` = %d AND updated > UTC_TIMESTAMP() - INTERVAL 1 DAY",
                                intval($contact['id'])
@@ -139,16 +137,19 @@ class OnePoll
 
                // We don't poll our followers
                if ($contact["rel"] == Contact::FOLLOWER) {
+                       Logger::log("Don't poll follower");
                        return;
                }
 
                // Don't poll if polling is deactivated (But we poll feeds and mails anyway)
                if (!in_array($contact['network'], [Protocol::FEED, Protocol::MAIL]) && Config::get('system', 'disable_polling')) {
+                       Logger::log('Polling is disabled');
                        return;
                }
 
                // We don't poll AP contacts by now
                if ($contact['network'] === Protocol::ACTIVITYPUB) {
+                       Logger::log("Don't poll AP contact");
                        return;
                }
 
@@ -225,6 +226,7 @@ class OnePoll
                                // set the last-update so we don't keep polling
                                self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        }
 
@@ -273,6 +275,7 @@ class OnePoll
                        if ((intval($res->status) != 0) || !strlen($res->challenge) || !strlen($res->dfrn_id)) {
                                // set the last-update so we don't keep polling
                                DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+                               Logger::log('Contact status is ' . $res->status);
                                return;
                        }
 
@@ -302,6 +305,13 @@ class OnePoll
                                $final_dfrn_id = substr($final_dfrn_id, 2);
                        }
 
+                       // There are issues with the legacy DFRN transport layer.
+                       // Since we mostly don't use it anyway, we won't dig into it deeper, but simply ignore it.
+                       if (empty($final_dfrn_id) || empty($orig_id)) {
+                               Logger::log('Contact has got no ID - quitting');
+                               return;
+                       }
+
                        if ($final_dfrn_id != $orig_id) {
                                // did not decode properly - cannot trust this site
                                Logger::log('ID did not decode: ' . $contact['id'] . ' orig: ' . $orig_id . ' final: ' . $final_dfrn_id);
@@ -342,6 +352,7 @@ class OnePoll
                        if ($contact['rel'] == Contact::FOLLOWER || $contact['blocked']) {
                                // set the last-update so we don't keep polling
                                DBA::update('contact', ['last-update' => DateTimeFormat::utcNow()], ['id' => $contact['id']]);
+                               Logger::log('Contact is blocked or only a follower');
                                return;
                        }
 
@@ -353,6 +364,7 @@ class OnePoll
                                // set the last-update so we don't keep polling
                                self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        }
 
@@ -366,6 +378,7 @@ class OnePoll
                                // set the last-update so we don't keep polling
                                self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
                                Contact::markForArchival($contact);
+                               Logger::log('Contact archived');
                                return;
                        }
 
@@ -562,7 +575,7 @@ class OnePoll
                                                                $datarray['allow_cid'] = '<' . $contact['id'] . '>';
                                                        }
 
-                                                       $stored_item = Item::insert($datarray);
+                                                       Item::insert($datarray);
 
                                                        switch ($mailconf['action']) {
                                                                case 0:
@@ -663,6 +676,7 @@ class OnePoll
                        self::updateContact($contact, ['last-update' => DateTimeFormat::utcNow()]);
                }
 
+               Logger::log('End');
                return;
        }
 
@@ -679,7 +693,8 @@ class OnePoll
         * @brief Updates a personal contact entry and the public contact entry
         *
         * @param array $contact The personal contact entry
-        * @param array $fields The fields that are updated
+        * @param array $fields  The fields that are updated
+        * @throws \Exception
         */
        private static function updateContact(array $contact, array $fields)
        {