3 * @file src/Worker/Expire.php
4 * @brief Expires old item entries
7 namespace Friendica\Worker;
9 use Friendica\Core\Config;
10 use Friendica\Core\Worker;
11 use Friendica\Database\DBM;
15 public static function execute($param = '', $hook_name = '') {
18 require_once 'include/datetime.php';
19 require_once 'include/items.php';
23 if ($param == 'delete') {
24 logger('Delete expired items', LOGGER_DEBUG);
25 // physically remove anything that has been deleted for more than two months
26 $r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
27 while ($row = dba::fetch($r)) {
28 dba::delete('item', array('id' => $row['id']));
32 logger('Delete expired items - done', LOGGER_DEBUG);
34 // make this optional as it could have a performance impact on large sites
35 if (intval(Config::get('system', 'optimize_items'))) {
36 dba::e("OPTIMIZE TABLE `item`");
39 } elseif (intval($param) > 0) {
40 $user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $param), array('limit' => 1));
41 if (DBM::is_result($user)) {
42 logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG);
43 item_expire($user['uid'], $user['expire']);
44 logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG);
47 } elseif (!empty($hook_name) && ($param == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) {
48 foreach ($a->hooks["expire"] as $hook) {
49 if ($hook[1] == $hook_name) {
50 logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG);
51 call_single_hook($a, $name, $hook, $data);
57 logger('expire: start');
59 Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
62 $r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0");
63 while ($row = dba::fetch($r)) {
64 logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG);
65 Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
66 'Expire', (int)$row['uid']);
70 logger('expire: calling hooks');
72 if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) {
73 foreach ($a->hooks['expire'] as $hook) {
74 logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG);
75 Worker::add(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true),
76 'Expire', 'hook', $hook[1]);
80 logger('expire: end');