3 use Friendica\Core\Config;
5 function expire_run(&$argv, &$argc){
8 require_once('include/datetime.php');
9 require_once('include/items.php');
10 require_once('include/Contact.php');
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);
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);
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']));
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`");
44 logger('expire: start');
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']);
54 logger('expire: calling hooks');
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]);
64 logger('expire: end');