]> git.mxchange.org Git - friendica.git/blob - include/update_gcontact.php
New process table for a better detection of running workers
[friendica.git] / include / update_gcontact.php
1 <?php
2
3 require_once("boot.php");
4
5 function update_gcontact_run(&$argv, &$argc){
6         global $a, $db;
7
8         if(is_null($a)) {
9                 $a = new App;
10         }
11
12         if(is_null($db)) {
13                 @include(".htconfig.php");
14                 require_once("include/dba.php");
15                 $db = new dba($db_host, $db_user, $db_pass, $db_data);
16                 unset($db_host, $db_user, $db_pass, $db_data);
17         };
18
19         $a->start_process();
20
21         require_once('include/Scrape.php');
22         require_once("include/socgraph.php");
23
24         load_config('config');
25         load_config('system');
26
27         $a->set_baseurl(get_config('system','url'));
28
29         load_hooks();
30
31         logger('update_gcontact: start');
32
33         if(($argc > 1) && (intval($argv[1])))
34                 $contact_id = intval($argv[1]);
35
36         if(!$contact_id) {
37                 logger('update_gcontact: no contact');
38                 return;
39         }
40
41         // Don't check this stuff if the function is called by the poller
42         if (App::callstack() != "poller_run")
43                 if (App::is_already_running('update_gcontact'.$contact_id, '', 540))
44                         return;
45
46         $r = q("SELECT * FROM `gcontact` WHERE `id` = %d", intval($contact_id));
47
48         if (!$r)
49                 return;
50
51         if (!in_array($r[0]["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS)))
52                 return;
53
54         $data = probe_url($r[0]["url"]);
55
56         if (!in_array($data["network"], array(NETWORK_DFRN, NETWORK_DIASPORA, NETWORK_OSTATUS))) {
57                 if ($r[0]["server_url"] != "")
58                         poco_check_server($r[0]["server_url"], $r[0]["network"]);
59
60                 q("UPDATE `gcontact` SET `last_failure` = '%s' WHERE `id` = %d",
61                         dbesc(datetime_convert()), intval($contact_id));
62                 return;
63         }
64
65         if (($data["name"] == "") AND ($r[0]['name'] != ""))
66                 $data["name"] = $r[0]['name'];
67
68         if (($data["nick"] == "") AND ($r[0]['nick'] != ""))
69                 $data["nick"] = $r[0]['nick'];
70
71         if (($data["addr"] == "") AND ($r[0]['addr'] != ""))
72                 $data["addr"] = $r[0]['addr'];
73
74         if (($data["photo"] == "") AND ($r[0]['photo'] != ""))
75                 $data["photo"] = $r[0]['photo'];
76
77
78         q("UPDATE `gcontact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
79                                 WHERE `id` = %d",
80                                 dbesc($data["name"]),
81                                 dbesc($data["nick"]),
82                                 dbesc($data["addr"]),
83                                 dbesc($data["photo"]),
84                                 intval($contact_id)
85                         );
86
87         q("UPDATE `contact` SET `name` = '%s', `nick` = '%s', `addr` = '%s', `photo` = '%s'
88                                 WHERE `uid` = 0 AND `addr` = '' AND `nurl` = '%s'",
89                                 dbesc($data["name"]),
90                                 dbesc($data["nick"]),
91                                 dbesc($data["addr"]),
92                                 dbesc($data["photo"]),
93                                 dbesc(normalise_link($data["url"]))
94                         );
95
96         q("UPDATE `contact` SET `addr` = '%s'
97                                 WHERE `uid` != 0 AND `addr` = '' AND `nurl` = '%s'",
98                                 dbesc($data["addr"]),
99                                 dbesc(normalise_link($data["url"]))
100                         );
101 }
102
103 if (array_search(__file__,get_included_files())===0){
104         update_gcontact_run($_SERVER["argv"],$_SERVER["argc"]);
105         killme();
106 }