delete_resources_in_collection()

Parameters

ColumnTypeDefaultDescription
$collection

Location

include/resource_functions.php lines 6217 to 6269

Definition

 
function delete_resources_in_collection($collection)
{
    if (
        !
is_int_loose($collection)
        || 
checkperm("D")
        || !
allow_multi_edit($collection)
        || !
collection_writeable($collection)
    ) {
        
debug("Unable to delete resources in collection: $collection");
        return 
false;
    }

    global 
$resource_deletion_state$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);
        
collection_log($collection'D'''str_replace("%ARCHIVE"$resource_deletion_state$lang['log-deleted_all']));
    }

    return 
true;
}

This article was last updated 20th April 2025 20:05 Europe/London time based on the source file dated 17th April 2025 12:45 Europe/London time.