Collections functions
General functions
Render functions
Theme permission functions
Resource functions

delete_resources_in_collection()

Parameters

ColumnTypeDefaultDescription
$collection

Location

include/resource_functions.php lines 5992 to 6044

Definition

 
function delete_resources_in_collection($collection)
    {
    global 
$resource_deletion_state,$userref,$lang;

    
// Always find all resources in deleted state and delete them permanently:
    // Note: when resource_deletion_state is null it will find all resources in collection and delete them permanently
    
$query "SELECT ref AS value FROM resource INNER JOIN collection_resource ON collection_resource.resource = resource.ref AND collection_resource.collection = ?";
    
$params=array("i",$collection);

    if(isset(
$resource_deletion_state))
        {
        
$query .= " WHERE archive = ?";
        
$params[] = "i";$params[] = $resource_deletion_state;
        }

    
$resources_in_deleted_state ps_array($query,$params);

    if(!empty(
$resources_in_deleted_state))
        {
        foreach (
$resources_in_deleted_state as $resource_in_deleted_state)
            {
            
delete_resource($resource_in_deleted_state);
            
collection_log($collection,'D''''Resource ' $resource_in_deleted_state ' deleted permanently.');
            }
        }

    
// Create a comma separated list of all resources remaining in this collection:
    
$resources ps_query("SELECT cr.resource, r.archive FROM collection_resource cr LEFT JOIN resource r on r.ref=cr.resource WHERE cr.collection = ?",["i",$collection]);
    
$r_refs array_column($resources,"resource");
    
$r_states array_column($resources,"archive");

    
// If all resources had their state the same as resource_deletion_state, stop here:
    // Note: when resource_deletion_state is null it will always stop here
    
if(empty($resources))
        {
        return 
TRUE;
        }

    
// Delete (ie. move to resource_deletion_state set in config):
    
if(isset($resource_deletion_state))
        {
        
update_archive_status($r_refs,$resource_deletion_state,$r_states);
        foreach(
$r_refs as $ref){resource_log($ref,LOG_CODE_DELETED,'');}
        
collection_log($collection,'D'''str_replace("%ARCHIVE",$resource_deletion_state,$lang['log-deleted_all']));
        
ps_query(
            
"DELETE FROM collection_resource  WHERE resource IN (" ps_param_insert(count($r_refs)) . ")",
            
ps_param_fill($r_refs,"i")
        );

        }

    return 
TRUE;
    }

This article was last updated 5th October 2022 04:05 Europe/London time based on the source file dated 30th September 2022 14:20 Europe/London time.