]> git.mxchange.org Git - friendica.git/blobdiff - include/discover_poco.php
Discovery for unchecked contacts
[friendica.git] / include / discover_poco.php
index 7dbafcafdef9375430c6385df0dfcdb928e43ecd..bc5ee5d3210c78fa849fd3999dae0550e029599c 100644 (file)
@@ -38,23 +38,26 @@ function discover_poco_run(&$argv, &$argc){
 
        if(($argc > 2) && ($argv[1] == "dirsearch")) {
                $search = urldecode($argv[2]);
-               $searchmode = 1;
+               $mode = 1;
+       } elseif(($argc == 2) && ($argv[1] == "checkcontact")) {
+               $mode = 2;
        } elseif ($argc == 1) {
                $search = "";
-               $searchmode = 0;
+               $mode = 0;
        } else
                die("Unknown or missing parameter ".$argv[1]."\n");
 
        $lockpath = get_lockpath();
        if ($lockpath != '') {
-               $pidfile = new pidfile($lockpath, 'discover_poco'.urlencode($search));
+               $pidfile = new pidfile($lockpath, 'discover_poco'.$mode.urlencode($search));
                if($pidfile->is_already_running()) {
                        logger("discover_poco: Already running");
                        if ($pidfile->running_time() > 19*60) {
                                 $pidfile->kill();
                                 logger("discover_poco: killed stale process");
                                // Calling a new instance
-                               proc_run('php','include/discover_poco.php');
+                               if ($mode == 0)
+                                       proc_run('php','include/discover_poco.php');
                         }
                        exit;
                }
@@ -66,9 +69,11 @@ function discover_poco_run(&$argv, &$argc){
 
        logger('start '.$search);
 
-       if (($search != "") and get_config('system','poco_local_search'))
+       if (($mode == 2) AND get_config('system','poco_completion'))
+               discover_users();
+       elseif (($mode == 1) AND ($search != "") and get_config('system','poco_local_search'))
                discover_directory($search);
-       elseif (($search == "") and get_config('system','poco_discovery') > 0)
+       elseif (($mode == 0) AND ($search == "") and (get_config('system','poco_discovery') > 0))
                poco_discover();
 
        logger('end '.$search);
@@ -76,6 +81,25 @@ function discover_poco_run(&$argv, &$argc){
        return;
 }
 
+function discover_users() {
+       // To-Do: Maybe we should check old contact as well.
+       $users = q("SELECT `url`, `created`, `updated`, `last_failure`, `last_contact` FROM `gcontact`
+                       WHERE `updated` = '0000-00-00 00:00:00' AND `last_contact` = '0000-00-00 00:00:00' AND
+                               `last_failure` = '0000-00-00 00:00:00' AND `network` IN ('%s', '%s', '%s')
+                               ORDER BY rand() LIMIT 100",
+                       dbesc(NETWORK_DFRN), dbesc(NETWORK_DIASPORA), dbesc(NETWORK_OSTATUS));
+
+       if (!$users)
+               return;
+
+       foreach ($users AS $user) {
+               if (poco_do_update($user["created"], $user["updated"], $user["last_failure"], $user["last_contact"])) {
+                       logger('Check user '.$user["url"]);
+                       poco_last_updated($user["url"]);
+               }
+       }
+}
+
 function discover_directory($search) {
 
        $data = Cache::get("dirsearch:".$search);