]> git.mxchange.org Git - friendica.git/commitdiff
New hook that is called when items expire
authorMichael Vogel <icarus@dabo.de>
Mon, 2 Jun 2014 21:41:33 +0000 (23:41 +0200)
committerMichael Vogel <icarus@dabo.de>
Mon, 2 Jun 2014 21:41:33 +0000 (23:41 +0200)
include/expire.php
include/items.php

index a73272a2efd93b47824ebc75526c956dca95d934..a7b561bf0cdf47cad3750213a294496a366da960 100644 (file)
@@ -8,7 +8,7 @@ function expire_run(&$argv, &$argc){
        if(is_null($a)) {
                $a = new App;
        }
-  
+
        if(is_null($db)) {
            @include(".htconfig.php");
        require_once("include/dba.php");
@@ -38,7 +38,7 @@ function expire_run(&$argv, &$argc){
                q("optimize table item");
 
        logger('expire: start');
-       
+
        $r = q("SELECT `uid`,`username`,`expire` FROM `user` WHERE `expire` != 0");
        if(count($r)) {
                foreach($r as $rr) {
@@ -47,6 +47,10 @@ function expire_run(&$argv, &$argc){
                }
        }
 
+       load_hooks();
+
+       call_hooks('expire');
+
        return;
 }
 
index c80e3478e34e53b6a22a672bad53299ac3d0e81c..7aac15b585a266510f2c2e97a9f9927a0284d379 100755 (executable)
@@ -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