2011-03-15 20:31:49 -04:00
|
|
|
<?php
|
|
|
|
|
2017-04-30 00:29:14 -04:00
|
|
|
use Friendica\Core\Config;
|
2017-01-18 16:45:32 -05:00
|
|
|
|
2012-11-05 03:28:54 -05:00
|
|
|
function expire_run(&$argv, &$argc){
|
2017-02-26 18:16:49 -05:00
|
|
|
global $a;
|
2014-06-02 17:41:33 -04:00
|
|
|
|
2011-06-29 00:11:52 -04:00
|
|
|
require_once('include/datetime.php');
|
2011-03-15 20:31:49 -04:00
|
|
|
require_once('include/items.php');
|
|
|
|
require_once('include/Contact.php');
|
|
|
|
|
2017-07-06 01:48:02 -04:00
|
|
|
load_hooks();
|
|
|
|
|
|
|
|
if (($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;
|
|
|
|
}
|
|
|
|
|
2012-02-02 21:02:08 -05:00
|
|
|
// physically remove anything that has been deleted for more than two months
|
2017-05-12 02:17:48 -04:00
|
|
|
$r = dba::p("SELECT `id` FROM `item` WHERE `deleted` AND `changed` < UTC_TIMESTAMP() - INTERVAL 60 DAY");
|
2017-07-06 01:48:02 -04:00
|
|
|
while ($row = dba::fetch($r)) {
|
|
|
|
dba::delete('item', array('id' => $row['id']));
|
2017-05-12 02:17:48 -04:00
|
|
|
}
|
2017-07-06 01:48:02 -04:00
|
|
|
dba::close($r);
|
2012-05-08 18:33:01 -04:00
|
|
|
|
|
|
|
// make this optional as it could have a performance impact on large sites
|
2017-04-04 13:47:32 -04:00
|
|
|
if (intval(get_config('system', 'optimize_items'))) {
|
2017-04-04 13:47:32 -04:00
|
|
|
q("OPTIMIZE TABLE `item`");
|
|
|
|
}
|
2012-01-30 18:13:24 -05:00
|
|
|
|
2011-03-15 20:31:49 -04:00
|
|
|
logger('expire: start');
|
2014-06-02 17:41:33 -04:00
|
|
|
|
2017-07-06 01:48:02 -04:00
|
|
|
$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']);
|
2011-03-15 20:31:49 -04:00
|
|
|
}
|
2017-07-06 01:48:02 -04:00
|
|
|
dba::close($r);
|
2011-03-15 20:31:49 -04:00
|
|
|
|
2017-07-06 01:48:02 -04:00
|
|
|
logger('expire: calling hooks');
|
|
|
|
|
|
|
|
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]);
|
|
|
|
}
|
|
|
|
}
|
2014-06-02 17:41:33 -04:00
|
|
|
|
2017-07-06 01:48:02 -04:00
|
|
|
logger('expire: end');
|
2014-06-02 17:41:33 -04:00
|
|
|
|
2011-03-15 20:31:49 -04:00
|
|
|
return;
|
|
|
|
}
|