Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video 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 5673 to 5732

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();
    if((int)
$share_user && ($share_user == $userref || checkperm_user_edit($share_user)))
        {
        
$conditions[] = "user ='" . (int)$share_user "'";
        }
    elseif(!
checkperm('a') && !checkperm('ex'))
        {
        
$conditions[] = "user ='" . (int)$userref "'";
        }

    if(!
is_null($share_group) && (int)$share_group 0  && checkperm('a'))
        {
        
$conditions[] = "usergroup ='" . (int)$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 ='" . (int)$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;
    
sql_query($purge_query);
    
$deleted sql_affected_rows();
    return 
$deleted;
    }

This article was last updated 28th February 2021 15:05 Europe/London time based on the source file dated 26th February 2021 11:40 Europe/London time.