]> git.mxchange.org Git - friendica.git/blob - src/Worker/Expire.php
We now store the receivers as well
[friendica.git] / src / Worker / Expire.php
1 <?php
2 /**
3  * @copyright Copyright (C) 2010-2022, the Friendica project
4  *
5  * @license GNU AGPL version 3 or any later version
6  *
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.
11  *
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.
16  *
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/>.
19  *
20  */
21
22 namespace Friendica\Worker;
23
24 use Friendica\Core\Hook;
25 use Friendica\Core\Logger;
26 use Friendica\Core\Worker;
27 use Friendica\Database\DBA;
28 use Friendica\DI;
29 use Friendica\Model\Item;
30
31 /**
32  * Expires old item entries
33  */
34 class Expire
35 {
36         public static function execute($param = '', $hook_function = '')
37         {
38                 $a = DI::app();
39
40                 Hook::loadHooks();
41
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']]);
48                         }
49                         return;
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);
55                                 }
56                         }
57                         return;
58                 }
59
60                 Logger::notice('start expiry');
61
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']);
67                 }
68                 DBA::close($r);
69
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]);
75                 }
76
77                 Logger::notice('calling hooks done');
78
79                 return;
80         }
81 }