3 use Friendica\Core\Config;
5 function cron_run(&$argv, &$argc){
8 require_once 'include/datetime.php';
10 // Poll contacts with specific parameters
12 cron_poll_contacts($argc, $argv);
16 $last = get_config('system', 'last_cron');
18 $poll_interval = intval(get_config('system', 'cron_interval'));
19 if (! $poll_interval) {
24 $next = $last + ($poll_interval * 60);
26 logger('cron intervall not reached');
31 logger('cron: start');
33 // run queue delivery process in the background
34 proc_run(PRIORITY_NEGLIGIBLE, "include/queue.php");
36 // run the process to discover global contacts in the background
37 proc_run(PRIORITY_LOW, "include/discover_poco.php");
39 // run the process to update locally stored global contacts in the background
40 proc_run(PRIORITY_LOW, "include/discover_poco.php", "checkcontact");
42 // Expire and remove user entries
43 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "expire_and_remove_users");
45 // Check OStatus conversations
46 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_mentions");
48 // Check every conversation
49 proc_run(PRIORITY_MEDIUM, "include/cronjobs.php", "ostatus_conversations");
51 // Call possible post update functions
52 proc_run(PRIORITY_LOW, "include/cronjobs.php", "post_update");
54 // update nodeinfo data
55 proc_run(PRIORITY_LOW, "include/cronjobs.php", "nodeinfo");
57 // Clear cache entries
58 proc_run(PRIORITY_LOW, "include/cronjobs.php", "clear_cache");
60 // Repair missing Diaspora values in contacts
61 proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_diaspora");
63 // Repair entries in the database
64 proc_run(PRIORITY_LOW, "include/cronjobs.php", "repair_database");
66 // once daily run birthday_updates and then expire in background
67 $d1 = get_config('system', 'last_expire_day');
68 $d2 = intval(datetime_convert('UTC', 'UTC', 'now', 'd'));
70 if ($d2 != intval($d1)) {
72 proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_contact_birthdays");
74 proc_run(PRIORITY_LOW, "include/discover_poco.php", "update_server");
76 proc_run(PRIORITY_LOW, "include/discover_poco.php", "suggestions");
78 set_config('system', 'last_expire_day', $d2);
80 proc_run(PRIORITY_LOW, 'include/expire.php');
82 proc_run(PRIORITY_MEDIUM, 'include/dbclean.php');
84 proc_run(PRIORITY_LOW, "include/cronjobs.php", "update_photo_albums");
88 cron_poll_contacts($argc, $argv);
92 set_config('system', 'last_cron', time());
98 * @brief Poll contacts for unreceived messages
100 * @param Integer $argc Number of command line arguments
101 * @param Array $argv Array of command line arguments
103 function cron_poll_contacts($argc, $argv) {
109 if (($argc > 1) && ($argv[1] == 'force')) {
112 if (($argc > 1) && ($argv[1] == 'restart')) {
114 $generation = intval($argv[2]);
120 if (($argc > 1) && intval($argv[1])) {
121 $manual_id = intval($argv[1]);
125 $min_poll_interval = Config::get('system', 'min_poll_interval', 1);
127 $sql_extra = (($manual_id) ? " AND `id` = $manual_id " : "");
131 $d = datetime_convert();
133 // Only poll from those with suitable relationships,
134 // and which have a polling address and ignore Diaspora since
135 // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
137 $abandon_days = intval(get_config('system', 'account_abandon_days'));
138 if ($abandon_days < 1) {
141 $abandon_sql = (($abandon_days)
142 ? sprintf(" AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL %d DAY ", intval($abandon_days))
146 $contacts = q("SELECT `contact`.`id` FROM `user`
147 STRAIGHT_JOIN `contact`
148 ON `contact`.`uid` = `user`.`uid` AND `contact`.`rel` IN (%d, %d) AND `contact`.`poll` != ''
149 AND `contact`.`network` IN ('%s', '%s', '%s', '%s', '%s', '%s') $sql_extra
150 AND NOT `contact`.`self` AND NOT `contact`.`blocked` AND NOT `contact`.`readonly`
151 AND NOT `contact`.`archive`
152 WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed` $abandon_sql ORDER BY RAND()",
153 intval(CONTACT_IS_SHARING),
154 intval(CONTACT_IS_FRIEND),
157 dbesc(NETWORK_OSTATUS),
163 if (!dbm::is_result($contacts)) {
167 foreach ($contacts as $c) {
169 $res = q("SELECT * FROM `contact` WHERE `id` = %d LIMIT 1",
173 if (!dbm::is_result($res)) {
177 foreach ($res as $contact) {
182 $contact['last-update'] = NULL_DATE;
185 if (in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
186 $contact['priority'] = 2;
189 if ($contact['subhub'] && in_array($contact['network'], array(NETWORK_DFRN, NETWORK_ZOT, NETWORK_OSTATUS))) {
191 * We should be getting everything via a hub. But just to be sure, let's check once a day.
192 * (You can make this more or less frequent if desired by setting 'pushpoll_frequency' appropriately)
193 * This also lets us update our subscription to the hub, and add or replace hubs in case it
194 * changed. We will only update hubs once a day, regardless of 'pushpoll_frequency'.
196 $poll_interval = get_config('system', 'pushpoll_frequency');
197 $contact['priority'] = (($poll_interval !== false) ? intval($poll_interval) : 3);
200 if (($contact['priority'] >= 0) && !$force) {
203 $t = $contact['last-update'];
206 * Based on $contact['priority'], should we poll this site now? Or later?
208 switch ($contact['priority']) {
210 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 month")) {
215 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 week")) {
220 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 day")) {
225 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 12 hour")) {
230 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + 1 hour")) {
236 if (datetime_convert('UTC', 'UTC', 'now') > datetime_convert('UTC', 'UTC', $t . " + ".$min_poll_interval." minute")) {
246 logger("Polling " . $contact["network"] . " " . $contact["id"] . " " . $contact["nick"] . " " . $contact["name"]);
248 if (($contact['network'] == NETWORK_FEED) && ($contact['priority'] <= 3)) {
249 $priority = PRIORITY_MEDIUM;
251 $priority = PRIORITY_LOW;
253 proc_run(array('priority' => $priority, 'dont_fork' => true), 'include/onepoll.php', intval($contact['id']));