]> git.mxchange.org Git - friendica.git/commitdiff
Try to repair OStatus subscriptions
authorMichael Vogel <icarus@dabo.de>
Thu, 3 Sep 2015 20:18:25 +0000 (22:18 +0200)
committerMichael Vogel <icarus@dabo.de>
Thu, 3 Sep 2015 20:18:25 +0000 (22:18 +0200)
include/follow.php
include/items.php
include/onepoll.php
mod/contacts.php
mod/repair_ostatus.php [new file with mode: 0755]

index 10ce4f667309252b90b9bb7bb14a9d148e9da8dd..217b9d07b7b37c22de81af99793c6cd968b1146f 100644 (file)
@@ -170,6 +170,11 @@ function new_contact($uid,$url,$interactive = false) {
                dbesc($ret['network'])
        );
 
+       if(!count($r))
+               $r = q("SELECT * FROM `contact` WHERE `uid` = %d AND `nurl` = '%s' AND `network` = '%s' LIMIT 1",
+                       intval($uid), dbesc(normalise_link($url)), dbesc($ret['network'])
+       );
+
        if(count($r)) {
                // update contact
                if($r[0]['rel'] == CONTACT_IS_FOLLOWER || ($network === NETWORK_DIASPORA && $r[0]['rel'] == CONTACT_IS_SHARING)) {
@@ -180,7 +185,6 @@ function new_contact($uid,$url,$interactive = false) {
                                intval($uid)
                        );
                }
-
        } else {
 
 
@@ -285,7 +289,7 @@ function new_contact($uid,$url,$interactive = false) {
 
        // pull feed and consume it, which should subscribe to the hub.
 
-       proc_run('php',"include/poller.php","$contact_id");
+       proc_run('php',"include/onepoll.php","$contact_id", "force");
 
        // create a follow slap
 
index cc03a776462d1165f83e1bbc512bc9d89a564858..5915e2ecee24691462c56959c0a2d68cf9fbfcb7 100644 (file)
@@ -4300,7 +4300,7 @@ function subscribe_to_hub($url,$importer,$contact,$hubmode = 'subscribe') {
 
        logger('subscribe_to_hub: ' . $hubmode . ' ' . $contact['name'] . ' to hub ' . $url . ' endpoint: '  . $push_url . ' with verifier ' . $verify_token);
 
-       if(! strlen($contact['hub-verify'])) {
+       if(!strlen($contact['hub-verify']) OR ($contact['hub-verify'] != $verify_token)) {
                $r = q("UPDATE `contact` SET `hub-verify` = '%s' WHERE `id` = %d",
                        dbesc($verify_token),
                        intval($contact['id'])
index 90d018524d13aae89bf653dc3cdfb81b9a3f04f2..1fc861afa2a4f2fa0648110cf197fc2cd2967ded 100644 (file)
@@ -53,6 +53,9 @@ function onepoll_run(&$argv, &$argc){
        if(($argc > 1) && (intval($argv[1])))
                $contact_id = intval($argv[1]);
 
+       if(($argc > 2) && ($argv[2] == "force"))
+               $force = true;
+
        if(! $contact_id) {
                logger('onepoll: no contact');
                return;
@@ -595,8 +598,10 @@ function onepoll_run(&$argv, &$argc){
                        return;
                }
 
-               consume_feed($xml,$importer,$contact,$hub,1,1);
 
+               logger("Consume feed of contact ".$contact['id']);
+
+               consume_feed($xml,$importer,$contact,$hub,1,1);
 
                // do it twice. Ensures that children of parents which may be later in the stream aren't tossed
 
@@ -609,6 +614,11 @@ function onepoll_run(&$argv, &$argc){
                if(($contact['network'] === NETWORK_OSTATUS ||  $contact['network'] == NETWORK_FEED) && (! $contact['hub-verify']))
                        $hub_update = true;
 
+               if ($force)
+                       $hub_update = true;
+
+               logger("Contact ".$contact['id']." returned hub: ".$hub." Network: ".$contact['network']." Relation: ".$contact['rel']." Update: ".$hub_update);
+
                if((strlen($hub)) && ($hub_update) && (($contact['rel'] != CONTACT_IS_FOLLOWER) || $contact['network'] == NETWORK_FEED) ) {
                        logger('poller: hub ' . $hubmode . ' : ' . $hub . ' contact name : ' . $contact['name'] . ' local user : ' . $importer['name']);
                        $hubs = explode(',', $hub);
index 826630d30565fb24de4404f8db3a3424db1b3b79..89154eded9ce0437177db0546a2ef515022c401e 100644 (file)
@@ -206,15 +206,36 @@ function contacts_post(&$a) {
 
 /*contact actions*/
 function _contact_update($contact_id) {
-       // pull feed and consume it, which should subscribe to the hub.
-       proc_run('php',"include/poller.php","$contact_id");
+       $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
+       if (!$r)
+               return;
+
+       $uid = $r[0]["uid"];
+
+       if ($uid != local_user())
+               return;
+
+       if ($r[0]["network"] == NETWORK_OSTATUS) {
+               $result = new_contact($uid, $r[0]["url"], false);
+
+               if ($result['success'])
+                       $r = q("UPDATE `contact` SET `subhub` = 1 WHERE `id` = %d",
+                               intval($contact_id));
+       } else
+               // pull feed and consume it, which should subscribe to the hub.
+               proc_run('php',"include/onepoll.php","$contact_id", "force");
 }
 
 function _contact_update_profile($contact_id) {
-       $r = q("SELECT `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
+       $r = q("SELECT `uid`, `url`, `network` FROM `contact` WHERE `id` = %d", intval($contact_id));
        if (!$r)
                return;
 
+       $uid = $r[0]["uid"];
+
+       if ($uid != local_user())
+               return;
+
        $data = probe_url($r[0]["url"]);
 
        // "Feed" is mostly a sign of communication problems
@@ -225,6 +246,13 @@ function _contact_update_profile($contact_id) {
                                "poco", "network", "alias", "pubkey");
        $update = array();
 
+       if ($data["network"] == NETWORK_OSTATUS) {
+               $result = new_contact($uid, $data["url"], false);
+
+               if ($result['success'])
+                       $update["subhub"] = true;
+       }
+
        foreach($updatefields AS $field)
                if (isset($data[$field]) AND ($data[$field] != ""))
                        $update[$field] = $data[$field];
diff --git a/mod/repair_ostatus.php b/mod/repair_ostatus.php
new file mode 100755 (executable)
index 0000000..5a8554d
--- /dev/null
@@ -0,0 +1,57 @@
+<?php
+
+require_once('include/Scrape.php');
+require_once('include/follow.php');
+
+function repair_ostatus_content(&$a) {
+
+       if(! local_user()) {
+               notice( t('Permission denied.') . EOL);
+               goaway($_SESSION['return_url']);
+               // NOTREACHED
+       }
+
+       $o = "<h2>".t("Resubsribing to OStatus contacts")."</h2>";
+
+       $uid = local_user();
+
+       $a = get_app();
+
+       $counter = intval($_REQUEST['counter']);
+
+        $r = q("SELECT COUNT(*) AS `total` FROM `contact` WHERE
+                `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)",
+                intval($uid),
+                dbesc(NETWORK_OSTATUS),
+                intval(CONTACT_IS_FRIEND),
+                intval(CONTACT_IS_SHARING));
+
+       if (!$r)
+               return($o.t("Error"));
+
+       $total = $r[0]["total"];
+
+        $r = q("SELECT `url` FROM `contact` WHERE
+                `uid` = %d AND `network` = '%s' AND `rel` IN (%d, %d)
+               ORDER BY `url`
+               LIMIT %d, 1",
+                intval($uid),
+                dbesc(NETWORK_OSTATUS),
+                intval(CONTACT_IS_FRIEND),
+                intval(CONTACT_IS_SHARING), ++$counter);
+
+       if (!$r) {
+               $o .= t("Done");
+               return $o;
+       }
+
+       $o .= "<p>".$counter."/".$total.": ".$r[0]["url"]."</p>";
+
+       $o .= "<p>".t("Keep this window open until done.")."</p>";
+
+       $result = new_contact($uid,$r[0]["url"],true);
+
+       $a->page['htmlhead'] = '<meta http-equiv="refresh" content="1; URL='.$a->get_baseurl().'/repair_ostatus?counter='.$counter.'">';
+
+       return $o;
+}