- // Poll contacts
- self::pollContacts();
-
- // Update contact information
- self::updatePublicContacts();
-
- Logger::log('cron: end');
-
- DI::config()->set('system', 'last_cron', time());
-
- return;
- }
-
- /**
- * Optimize tables that are known to grow and shrink all the time
- *
- * @return void
- */
- private static function optimizeTables()
- {
- Logger::info('Optimize start');
-
- DBA::e("OPTIMIZE TABLE `auth_codes`");
- DBA::e("OPTIMIZE TABLE `challenge`");
- DBA::e("OPTIMIZE TABLE `locks`");
- DBA::e("OPTIMIZE TABLE `profile_check`");
- DBA::e("OPTIMIZE TABLE `session`");
- DBA::e("OPTIMIZE TABLE `tokens`");
-
- DI::lock()->release('optimize_tables');
- }
-
- /**
- * Checks for contacts that are about to be deleted and ensures that they are removed.
- * This should be done automatically in the "remove" function. This here is a cleanup job.
- */
- private static function checkdeletedContacts()
- {
- $contacts = DBA::select('contact', ['id'], ['deleted' => true]);
- while ($contact = DBA::fetch($contacts)) {
- Worker::add(PRIORITY_MEDIUM, 'RemoveContact', $contact['id']);
- }
- DBA::close($contacts);
- }
-
- /**
- * Update public contacts
- *
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- private static function updatePublicContacts() {
- $count = 0;
- $last_updated = DateTimeFormat::utc('now - 1 week');
- $condition = ["`network` IN (?, ?, ?, ?) AND `uid` = ? AND NOT `self` AND `last-update` < ?",
- Protocol::ACTIVITYPUB, Protocol::DFRN, Protocol::DIASPORA, Protocol::OSTATUS, 0, $last_updated];
-
- $oldest_date = '';
- $oldest_id = '';
- $contacts = DBA::select('contact', ['id', 'last-update'], $condition, ['limit' => 100, 'order' => ['last-update']]);
- while ($contact = DBA::fetch($contacts)) {
- if (empty($oldest_id)) {
- $oldest_id = $contact['id'];
- $oldest_date = $contact['last-update'];
- }
- Worker::add(PRIORITY_LOW, "UpdateContact", $contact['id']);
- ++$count;
- }
- Logger::info('Initiated update for public contacts', ['interval' => $count, 'id' => $oldest_id, 'oldest' => $oldest_date]);
- DBA::close($contacts);
- }
-
- /**
- * Poll contacts for unreceived messages
- *
- * @throws \Friendica\Network\HTTPException\InternalServerErrorException
- */
- private static function pollContacts() {
- Addon::reload();
-
- $sql = "SELECT `contact`.`id`, `contact`.`nick`, `contact`.`name`, `contact`.`network`, `contact`.`archive`,
- `contact`.`last-update`, `contact`.`priority`, `contact`.`rating`, `contact`.`rel`, `contact`.`subhub`
- FROM `user`
- STRAIGHT_JOIN `contact`
- ON `contact`.`uid` = `user`.`uid` AND `contact`.`poll` != ''
- AND `contact`.`network` IN (?, ?, ?, ?, ?)
- AND NOT `contact`.`self` AND NOT `contact`.`blocked`
- AND `contact`.`rel` != ?
- WHERE NOT `user`.`account_expired` AND NOT `user`.`account_removed`";
-
- $parameters = [Protocol::DFRN, Protocol::ACTIVITYPUB, Protocol::OSTATUS, Protocol::FEED, Protocol::MAIL, Contact::FOLLOWER];
-
- // Only poll from those with suitable relationships,
- // and which have a polling address and ignore Diaspora since
- // we are unable to match those posts with a Diaspora GUID and prevent duplicates.
- $abandon_days = intval(DI::config()->get('system', 'account_abandon_days'));
- if ($abandon_days < 1) {
- $abandon_days = 0;
- }
-
- if (!empty($abandon_days)) {
- $sql .= " AND `user`.`login_date` > UTC_TIMESTAMP() - INTERVAL ? DAY";
- $parameters[] = $abandon_days;
- }