Collections functions
General functions
Render functions
Theme permission functions
Resource functions

purge_expired_shares()

Description

Purge all expired shares
"share_group" - (int) Usergroup ref 'shared as'
"share_user" - (int) user ID of share creator
"share_type" - (int) 0=view, 1=upload
"share_collection" - (int) Collection ID

Parameters

ColumnTypeDefaultDescription
$filteropts array Array of options to filter shares purged

Return

void

Location

include/collections_functions.php lines 6583 to 6647

Definition

 
function purge_expired_shares($filteropts)
    {
    global 
$userref;

    
$validfilterops = array(
        
"share_group",
        
"share_user",
        
"share_type",
        
"share_collection",
    );
    foreach(
$validfilterops as $validfilterop)
        {
        if(isset(
$filteropts[$validfilterop]))
            {
            $
$validfilterop $filteropts[$validfilterop];
            }
        else
            {
            $
$validfilterop NULL;
            }
        }
   
    
$conditions = array();
    
$params = [];
    if((int)
$share_user && ($share_user == $userref || checkperm_user_edit($share_user)))
        {
        
$conditions[] = "user = ?";
        
$params array_merge($params, ['i'$share_user]);
        }
    elseif(!
checkperm('a') && !checkperm('ex'))
        {
        
$conditions[] = "user = ?";
        
$params array_merge($params, ['i'$userref]);
        }

    if(!
is_null($share_group) && (int)$share_group 0  && checkperm('a'))
        {
        
$conditions[] = "usergroup = ?";
        
$params array_merge($params, ['i'$share_group]);
        }
    if(
$share_type == 0)
        {
        
$conditions[] = "(upload=0 OR upload IS NULL)";
        }
    elseif(
$share_type == 1)
        {
        
$conditions[] = "upload=1";
        }
    if((int)
$share_collection 0)
        {
        
$conditions[] = "collection = ?";
        
$params array_merge($params, ['i'$share_collection]);
        }

    
$conditional_sql=" WHERE expires < now()";
    if (
count($conditions)>0)
        {
        
$conditional_sql .= " AND " implode(" AND ",$conditions);
        }

    
$purge_query "DELETE FROM external_access_keys " $conditional_sql;
    
ps_query($purge_query$params);
    
$deleted sql_affected_rows();
    return 
$deleted;
    }

This article was last updated 5th October 2022 02:05 Europe/London time based on the source file dated 4th October 2022 09:50 Europe/London time.