New hook that is called when items expire

This commit is contained in:
Michael Vogel 2014-06-02 23:41:33 +02:00
parent 6a28ae8b52
commit d8d745891a
2 changed files with 21 additions and 5 deletions

View file

@ -47,6 +47,10 @@ function expire_run(&$argv, &$argc){
}
}
load_hooks();
call_hooks('expire');
return;
}

View file

@ -4102,7 +4102,7 @@ function item_getfeedattach($item) {
function item_expire($uid,$days) {
function item_expire($uid, $days, $network = "", $force = false) {
if((! $uid) || ($days < 1))
return;
@ -4113,9 +4113,17 @@ function item_expire($uid,$days) {
$expire_network_only = get_pconfig($uid,'expire','network_only');
$sql_extra = ((intval($expire_network_only)) ? " AND wall = 0 " : "");
if ($network != "") {
$sql_extra .= sprintf(" AND network = '%s' ", dbesc($network));
// There is an index "uid_network_received" but not "uid_network_created"
// This avoids the creation of another index just for one purpose.
// And it doesn't really matter wether to look at "received" or "created"
$range = "AND `received` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
} else
$range = "AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY ";
$r = q("SELECT * FROM `item`
WHERE `uid` = %d
AND `created` < UTC_TIMESTAMP() - INTERVAL %d DAY
WHERE `uid` = %d $range
AND `id` = `parent`
$sql_extra
AND `deleted` = 0",
@ -4129,6 +4137,10 @@ function item_expire($uid,$days) {
$expire_items = get_pconfig($uid, 'expire','items');
$expire_items = (($expire_items===false)?1:intval($expire_items)); // default if not set: 1
// Forcing expiring of items - but not notes and marked items
if ($force)
$expire_items = true;
$expire_notes = get_pconfig($uid, 'expire','notes');
$expire_notes = (($expire_notes===false)?1:intval($expire_notes)); // default if not set: 1