]> git.mxchange.org Git - friendica.git/blob - include/expire.php
Merge pull request #3554 from Alkarex/semaphore_warning
[friendica.git] / include / expire.php
1 <?php
2
3 use Friendica\Core\Config;
4
5 function expire_run(&$argv, &$argc){
6         global $a;
7
8         require_once('include/datetime.php');
9         require_once('include/items.php');
10         require_once('include/Contact.php');
11
12         load_hooks();
13
14         if (($argc == 2) && (intval($argv[1]) > 0)) {
15                 $user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $argv[1]), array('limit' => 1));
16                 if (dbm::is_result($user)) {
17                         logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
18                         item_expire($user['uid'], $user['expire']);
19                         logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
20                 }
21                 return;
22         } elseif (($argc == 3) && ($argv[1] == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
23                 foreach ($a->hooks["expire"] as $hook) {
24                         if ($hook[1] == $argv[2]) {
25                                 logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
26                                 call_single_hook($a, $name, $hook, $data);
27                         }
28                 }
29                 return;
30         }
31
32         // physically remove anything that has been deleted for more than two months
33         $r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
34         while ($row = dba::fetch($r)) {
35                 dba::delete('item', array('id' => $row['id']));
36         }
37         dba::close($r);
38
39         // make this optional as it could have a performance impact on large sites
40         if (intval(get_config('system', 'optimize_items'))) {
41                 q("OPTIMIZE TABLE `item`");
42         }
43
44         logger('expire: start');
45
46         $r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
47         while ($row = dba::fetch($r)) {
48                 logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
49                 proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
50                                 'include/expire.php', (int)$row['uid']);
51         }
52         dba::close($r);
53
54         logger('expire: calling hooks');
55
56         if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
57                 foreach ($a->hooks['expire'] as $hook) {
58                         logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
59                         proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
60                                         'include/expire.php', 'hook', $hook[1]);
61                 }
62         }
63
64         logger('expire: end');
65
66         return;
67 }