2020-09-01 10:09:16 +02:00
< ? php
/**
2023-01-01 15:36:24 +01:00
* @ copyright Copyright ( C ) 2010 - 2023 , the Friendica project
2020-09-01 10:09:16 +02:00
*
* @ license GNU AGPL version 3 or any later version
*
* This program is free software : you can redistribute it and / or modify
* it under the terms of the GNU Affero General Public License as
* published by the Free Software Foundation , either version 3 of the
* License , or ( at your option ) any later version .
*
* This program is distributed in the hope that it will be useful ,
* but WITHOUT ANY WARRANTY ; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE . See the
* GNU Affero General Public License for more details .
*
* You should have received a copy of the GNU Affero General Public License
* along with this program . If not , see < https :// www . gnu . org / licenses />.
*
*/
namespace Friendica\Worker ;
use Friendica\Core\Logger ;
use Friendica\Core\Protocol ;
use Friendica\Core\Worker ;
use Friendica\Database\DBA ;
use Friendica\DI ;
2020-11-30 06:39:12 +01:00
use Friendica\Protocol\Feed ;
2020-09-01 10:09:16 +02:00
use Friendica\Util\DateTimeFormat ;
/**
* Poll contacts for unreceived messages
*/
class PollContacts
{
public static function execute ()
{
$abandon_days = intval ( DI :: config () -> get ( 'system' , 'account_abandon_days' ));
if ( $abandon_days < 1 ) {
$abandon_days = 0 ;
}
2023-01-28 15:57:04 +01:00
$condition = [ 'network' => [ Protocol :: FEED , Protocol :: MAIL , Protocol :: OSTATUS ], 'self' => false , 'blocked' => false , 'archive' => false ];
2020-11-22 15:42:24 +01:00
2020-09-01 10:09:16 +02:00
if ( ! empty ( $abandon_days )) {
2020-11-22 15:42:24 +01:00
$condition = DBA :: mergeConditions ( $condition ,
2022-12-04 08:17:26 +01:00
[ " `uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed` AND `last-activity` > ?) " , 0 , DateTimeFormat :: utc ( 'now - ' . $abandon_days . ' days' )]);
2020-11-22 15:42:24 +01:00
} else {
$condition = DBA :: mergeConditions ( $condition ,
[ " `uid` != ? AND `uid` IN (SELECT `uid` FROM `user` WHERE NOT `account_expired` AND NOT `account_removed`) " , 0 ]);
2020-09-01 10:09:16 +02:00
}
2020-11-22 15:42:24 +01:00
$contacts = DBA :: select ( 'contact' , [ 'id' , 'nick' , 'name' , 'network' , 'archive' , 'last-update' , 'priority' , 'rating' ], $condition );
2020-09-01 10:09:16 +02:00
if ( ! DBA :: isResult ( $contacts )) {
return ;
}
while ( $contact = DBA :: fetch ( $contacts )) {
2020-11-30 06:39:12 +01:00
$interval = Feed :: getPollInterval ( $contact );
if ( $interval == 0 ) {
2020-09-01 10:09:16 +02:00
continue ;
}
$now = DateTimeFormat :: utcNow ();
2020-11-30 06:39:12 +01:00
$next_update = DateTimeFormat :: utc ( $contact [ 'last-update' ] . ' + ' . $interval . ' minute' );
2020-09-01 10:09:16 +02:00
2020-11-30 06:39:12 +01:00
if ( $now < $next_update ) {
Logger :: debug ( 'No update' , [ 'cid' => $contact [ 'id' ], 'interval' => $interval , 'next' => $next_update , 'now' => $now ]);
2020-09-01 10:09:16 +02:00
continue ;
}
if ((( $contact [ 'network' ] == Protocol :: FEED ) && ( $contact [ 'priority' ] <= 3 )) || ( $contact [ 'network' ] == Protocol :: MAIL )) {
2022-10-17 07:49:55 +02:00
$priority = Worker :: PRIORITY_MEDIUM ;
2020-09-01 10:09:16 +02:00
} elseif ( $contact [ 'archive' ]) {
2022-10-17 07:49:55 +02:00
$priority = Worker :: PRIORITY_NEGLIGIBLE ;
2020-09-01 10:09:16 +02:00
} else {
2022-10-17 07:49:55 +02:00
$priority = Worker :: PRIORITY_LOW ;
2020-09-01 10:09:16 +02:00
}
Logger :: notice ( " Polling " . $contact [ " network " ] . " " . $contact [ " id " ] . " " . $contact [ 'priority' ] . " " . $contact [ " nick " ] . " " . $contact [ " name " ]);
Worker :: add ([ 'priority' => $priority , 'dont_fork' => true , 'force_priority' => true ], 'OnePoll' , ( int ) $contact [ 'id' ]);
2022-09-21 21:03:07 +02:00
Worker :: coolDown ();
2020-09-01 10:09:16 +02:00
}
DBA :: close ( $contacts );
}
}