]> git.mxchange.org Git - friendica.git/blobdiff - src/Worker/OnePoll.php
Centralize owner data fetch
[friendica.git] / src / Worker / OnePoll.php
index 0cf261a6e4b0b5794ce3ae8bcb25e7602c3775fa..fc819751bc8521a1057601f6579b2686c4d4a01f 100644 (file)
@@ -7,11 +7,12 @@ namespace Friendica\Worker;
 use Friendica\Core\Config;
 use Friendica\Core\PConfig;
 use Friendica\Database\DBM;
-use Friendica\Object\Contact;
+use Friendica\Model\Contact;
 use Friendica\Protocol\Email;
 use Friendica\Protocol\PortableContact;
 use dba;
 
+require_once 'include/dba.php';
 require_once 'include/follow.php';
 
 Class OnePoll
@@ -63,27 +64,25 @@ Class OnePoll
                        }
                }
 
-               // Diaspora users and followers we only check if they still exist.
-               if (($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
-                       if (PortableContact::updateNeeded($contact["created"], $contact["last-item"], $contact["failure_update"], $contact["success_update"])) {
-                               $last_updated = PortableContact::lastUpdated($contact["url"]);
-                               $updated = datetime_convert();
-                               if ($last_updated) {
-                                       logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);
-
-                                       // The last public item can be older than the last item we got
-                                       if ($last_updated < $contact['last-item']) {
-                                               $last_updated = $contact['last-item'];
-                                       }
+               // Diaspora users, archived users and followers are only checked if they still exist.
+               if ($contact['archive'] || ($contact["network"] == NETWORK_DIASPORA) || ($contact["rel"] == CONTACT_IS_FOLLOWER)) {
+                       $last_updated = PortableContact::lastUpdated($contact["url"]);
+                       $updated = datetime_convert();
+                       if ($last_updated) {
+                               logger('Contact '.$contact['id'].' had last update on '.$last_updated, LOGGER_DEBUG);
 
-                                       $fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
-                                       dba::update('contact', $fields, array('id' => $contact['id']));
-                                       Contact::unmarkForArchival($contact);
-                               } else {
-                                       dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id']));
-                                       Contact::markForArchival($contact);
-                                       logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
+                               // The last public item can be older than the last item we got
+                               if ($last_updated < $contact['last-item']) {
+                                       $last_updated = $contact['last-item'];
                                }
+
+                               $fields = array('last-item' => $last_updated, 'last-update' => $updated, 'success_update' => $updated);
+                               self::updateContact($contact, $fields);
+                               Contact::unmarkForArchival($contact);
+                       } else {
+                               self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
+                               Contact::markForArchival($contact);
+                               logger('Contact '.$contact['id'].' is marked for archival', LOGGER_DEBUG);
                        }
                        return;
                }
@@ -93,8 +92,8 @@ Class OnePoll
                $t = $contact['last-update'];
 
                if ($contact['subhub']) {
-                       $poll_interval = Config::get('system', 'pushpoll_frequency');
-                       $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
+                       $poll_interval = Config::get('system', 'pushpoll_frequency', 3);
+                       $contact['priority'] = intval($poll_interval);
                        $hub_update = false;
 
                        if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
@@ -206,7 +205,7 @@ Class OnePoll
 
                                // set the last-update so we don't keep polling
                                $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
-                               dba::update('contact', $fields, array('id' => $contact['id']));
+                               self::updateContact($contact, $fields);
                                return;
                        }
 
@@ -216,7 +215,7 @@ Class OnePoll
                                Contact::markForArchival($contact);
 
                                $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
-                               dba::update('contact', $fields, array('id' => $contact['id']));
+                               self::updateContact($contact, $fields);
                                return;
                        }
 
@@ -229,7 +228,7 @@ Class OnePoll
                                // we may not be friends anymore. Will keep trying for one month.
                                // set the last-update so we don't keep polling
                                $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
-                               dba::update('contact', $fields, array('id' => $contact['id']));
+                               self::updateContact($contact, $fields);
 
                                Contact::markForArchival($contact);
                        } elseif ($contact['term-date'] > NULL_DATE) {
@@ -577,7 +576,7 @@ Class OnePoll
                                logger('post_handshake: response from ' . $url . ' did not contain XML.');
 
                                $fields = array('last-update' => datetime_convert(), 'failure_update' => datetime_convert());
-                               dba::update('contact', $fields, array('id' => $contact['id']));
+                               self::updateContact($contact, $fields);
                                Contact::markForArchival($contact);
                                return;
                        }
@@ -622,16 +621,17 @@ Class OnePoll
 
                        $updated = datetime_convert();
 
-                       dba::update('contact', array('last-update' => $updated, 'success_update' => $updated), array('id' => $contact['id']));
+                       self::updateContact($contact, array('last-update' => $updated, 'success_update' => $updated));
                        dba::update('gcontact', array('last_contact' => $updated), array('nurl' => $contact['nurl']));
                        Contact::unmarkForArchival($contact);
                } elseif (in_array($contact["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS, NETWORK_FEED))) {
                        $updated = datetime_convert();
 
-                       dba::update('contact', array('last-update' => $updated, 'failure_update' => $updated), array('id' => $contact['id']));
+                       self::updateContact($contact, array('last-update' => $updated, 'failure_update' => $updated));
                        dba::update('gcontact', array('last_failure' => $updated), array('nurl' => $contact['nurl']));
                        Contact::markForArchival($contact);
                } else {
+                       $updated = datetime_convert();
                        dba::update('contact', array('last-update' => $updated), array('id' => $contact['id']));
                }
 
@@ -645,4 +645,15 @@ Class OnePoll
 
                return $subject;
        }
+
+       /**
+        * @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
+        */
+       private static function updateContact($contact, $fields) {
+               dba::update('contact', $fields, array('id' => $contact['id']));
+               dba::update('contact', $fields, array('uid' => 0, 'nurl' => $contact['nurl']));
+       }
 }