2 use \Friendica\Core\Config;
4 function cron_run(&$argv, &$argc){
7 require_once 'include/datetime.php';
9 // Poll contacts with specific parameters
11 cron_poll_contacts($argc, $argv);
15 $last = get_config('system', 'last_cron');
17 $poll_interval = intval(get_config('system', 'cron_interval'));
18 if (! $poll_interval) {
23 $next = $last + ($poll_interval * 60);
25 logger('cron intervall not reached');
30 logger('cron: start');
32 // run queue delivery process in the background
33 proc_run(PRIORITY_NEGLIGIBLE, "include/queue.php");
35 // run the process to discover global contacts in the background
36 proc_run(PRIORITY_LOW, "include/discover_poco.php");
38 // run the process to update locally stored global contacts in the background
39 proc_run(PRIORITY_LOW, "include/discover_poco.php", "checkcontact");
41 // Expire and remove user entries
42 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users");
44 // Check OStatus conversations
45 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
47 // Check every conversation
48 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
50 // Call possible post update functions
51 proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
53 // update nodeinfo data
54 proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
56 // Clear cache entries
57 proc_run(PRIORITY_LOW, "include/cronjobs.php", "clear_cache");
59 // Repair missing Diaspora values in contacts
60 proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_diaspora");
62 // Repair entries in the database
63 proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_database");
65 // once daily run birthday_updates and then expire in background
66 $d1 = get_config('system', 'last_expire_day');
67 $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
69 if ($d2 != intval($d1)) {
71 proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays");
73 proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
75 proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
77 set_config('system', 'last_expire_day', $d2);
79 proc_run(PRIORITY_LOW, 'include/expire.php');
81 proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
83 proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
87 cron_poll_contacts($argc, $argv);
91 set_config('system', 'last_cron', time());
97 * @brief Poll contacts for unreceived messages
99 * @param Integer $argc Number of command line arguments
100 * @param Array $argv Array of command line arguments
102 function cron_poll_contacts($argc, $argv) {
108 if (($argc > 1) && ($argv[1] == 'force')) {
111 if (($argc > 1) && ($argv[1] == 'restart')) {
113 $generation = intval($argv[2]);
119 if (($argc > 1) && intval($argv[1])) {
120 $manual_id = intval($argv[1]);
124 $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
128 $d = datetime_convert();
130 // Only poll from those with suitable relationships,
131 // and which have a polling address and ignore Diaspora since
132 // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
134 $abandon_days = intval(get_config('system', 'account_abandon_days'));
135 if ($abandon_days < 1) {
138 $abandon_sql = (($abandon_days)
139 ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
143 $contacts = q("SELECT `contact`.`id` FROM `user`
144 STRAIGHT_JOIN `contact`
145 ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != ''
146 AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s', '%s') $sql_extra
147 AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly`
148 AND NOT `contact`.`archive`
149 WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()",
150 intval(CONTACT_IS_SHARING),
151 intval(CONTACT_IS_FRIEND),
154 dbesc(NETWORK_OSTATUS),
160 if (!dbm::is_result($contacts)) {
164 foreach ($contacts as $c) {
166 $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
170 if (!dbm::is_result($res)) {
174 foreach ($res as $contact) {
179 $contact['last-update'] = NULL_DATE;
182 if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
183 $contact['priority'] = 2;
186 if ($contact['subhub'] AND in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
188 * We should be getting everything via a hub. But just to be sure, let's check once a day.
189 * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
190 * This also lets us update our subscription to the hub, and add or replace hubs in case it
191 * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
193 $poll_interval = get_config('system', 'pushpoll_frequency');
194 $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
197 if ($contact['priority'] AND !$force) {
200 $t = $contact['last-update'];
203 * Based on $contact['priority'], should we poll this site now? Or later?
205 switch ($contact['priority']) {
207 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) {
212 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) {
217 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
222 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) {
228 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) {
238 logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]);
240 if (($contact['network'] == NETWORK_FEED) AND ($contact['priority'] <= 3)) {
241 proc_run(PRIORITY_MEDIUM, 'include/onepoll.php', intval($contact['id']));
243 proc_run(PRIORITY_LOW, 'include/onepoll.php', intval($contact['id']));