X-Git-Url: https://git.mxchange.org/?a=blobdiff_plain;f=include%2Fexpire.php;h=bb0129aad6278f1ad10759be8ad91f48f6731553;hb=9f2196aa1aa0dc112e3fc238832828d4e22fe137;hp=855d7fb5e44abc544f7eb5f7f5364e7bd05253f6;hpb=be7041c3e06ee5a799851ac3612849dde55a8198;p=friendica.git diff --git a/include/expire.php b/include/expire.php index 855d7fb5e4..bb0129aad6 100644 --- a/include/expire.php +++ b/include/expire.php @@ -1,60 +1,74 @@ set_baseurl(get_config('system','url')); + if (($argc == 2) && ($argv[1] == 'delete')) { + logger('Delete expired items', LOGGER_DEBUG); + // physically remove anything that has been deleted for more than two months + $r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY"); + while ($row = dba::fetch($r)) { + dba::delete('item', array('id' => $row['id'])); + } + dba::close($r); + logger('Delete expired items - done', LOGGER_DEBUG); - // physically remove anything that has been deleted for more than two months + // make this optional as it could have a performance impact on large sites + if (intval(get_config('system', 'optimize_items'))) { + q("OPTIMIZE TABLE `item`"); + } + return; + } elseif (($argc == 2) && (intval($argv[1]) > 0)) { + $user = dba::select('user', array('uid', 'username', 'expire'), array('uid' => $argv[1]), array('limit' => 1)); + if (dbm::is_result($user)) { + logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - interval: '.$user['expire'], LOGGER_DEBUG); + item_expire($user['uid'], $user['expire']); + logger('Expire items for user '.$user['uid'].' ('.$user['username'].') - done ', LOGGER_DEBUG); + } + return; + } elseif (($argc == 3) && ($argv[1] == 'hook') && is_array($a->hooks) && array_key_exists("expire", $a->hooks)) { + foreach ($a->hooks["expire"] as $hook) { + if ($hook[1] == $argv[2]) { + logger("Calling expire hook '" . $hook[1] . "'", LOGGER_DEBUG); + call_single_hook($a, $name, $hook, $data); + } + } + return; + } - $r = q("delete from item where deleted = 1 and changed < UTC_TIMESTAMP() - INTERVAL 60 DAY"); + logger('expire: start'); - // make this optional as it could have a performance impact on large sites + proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true), + 'include/expire.php', 'delete'); - if(intval(get_config('system','optimize_items'))) - q("optimize table item"); + $r = dba::p("SELECT `uid`, `username` FROM `user` WHERE `expire` != 0"); + while ($row = dba::fetch($r)) { + logger('Calling expiry for user '.$row['uid'].' ('.$row['username'].')', LOGGER_DEBUG); + proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true), + 'include/expire.php', (int)$row['uid']); + } + dba::close($r); - logger('expire: start'); + logger('expire: calling hooks'); - $r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0"); - if (dbm::is_result($r)) { - foreach ($r as $rr) { - logger('Expire: ' . $rr['username'] . ' interval: ' . $rr['expire'], LOGGER_DEBUG); - item_expire($rr['uid'],$rr['expire']); + if (is_array($a->hooks) && array_key_exists('expire', $a->hooks)) { + foreach ($a->hooks['expire'] as $hook) { + logger("Calling expire hook for '" . $hook[1] . "'", LOGGER_DEBUG); + proc_run(array('priority' => $a->queue['priority'], 'created' => $a->queue['created'], 'dont_fork' => true), + 'include/expire.php', 'hook', $hook[1]); } } - load_hooks(); - - call_hooks('expire'); + logger('expire: end'); return; } - -if (array_search(__file__,get_included_files())===0){ - expire_run($_SERVER["argv"],$_SERVER["argc"]); - killme(); -}