3 * @copyright Copyright (C) 2010-2022, the Friendica project
5 * @license GNU AGPL version 3 or any later version
7 * This program is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU Affero General Public License as
9 * published by the Free Software Foundation, either version 3 of the
10 * License, or (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU Affero General Public License for more details.
17 * You should have received a copy of the GNU Affero General Public License
18 * along with this program. If not, see <https://www.gnu.org/licenses/>.
22 namespace Friendica\Worker;
24 use Friendica\Core\Hook;
25 use Friendica\Core\Logger;
26 use Friendica\Core\Worker;
27 use Friendica\Database\DBA;
29 use Friendica\Model\Item;
32 * Expires old item entries
36 public static function execute($param = '', $hook_function = '')
42 if (intval($param) > 0) {
43 $user = DBA::selectFirst('user', ['uid', 'username', 'expire'], ['uid' => $param]);
44 if (DBA::isResult($user)) {
45 Logger::info('Expire items', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]);
46 Item::expire($user['uid'], $user['expire']);
47 Logger::info('Expire items done', ['user' => $user['uid'], 'username' => $user['username'], 'interval' => $user['expire']]);
50 } elseif ($param == 'hook' && !empty($hook_function)) {
51 foreach (Hook::getByName('expire') as $hook) {
52 if ($hook[1] == $hook_function) {
53 Logger::info('Calling expire hook', ['hook' => $hook[1]]);
54 Hook::callSingle($a, 'expire', $hook, $data);
60 Logger::notice('start expiry');
62 $r = DBA::select('user', ['uid', 'username'], ["`expire` != ?", 0]);
63 while ($row = DBA::fetch($r)) {
64 Logger::info('Calling expiry', ['user' => $row['uid'], 'username' => $row['username']]);
65 Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
66 'Expire', (int)$row['uid']);
70 Logger::notice('calling hooks');
71 foreach (Hook::getByName('expire') as $hook) {
72 Logger::info('Calling expire', ['hook' => $hook[1]]);
73 Worker::add(['priority' => $a->getQueueValue('priority'), 'created' => $a->getQueueValue('created'), 'dont_fork' => true],
74 'Expire', 'hook', $hook[1]);
77 Logger::notice('calling hooks done');