Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

delete_resources_in_collection()

Parameters

ColumnTypeDefaultDescription
$collection

Location

include/resource_functions.php lines 6044 to 6091

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 sprintf("
                SELECT ref AS value
                  FROM resource
            INNER JOIN collection_resource ON collection_resource.resource = resource.ref AND collection_resource.collection = '%s'
                 %s;
    "
,
        
$collection,
        isset(
$resource_deletion_state) ? "WHERE archive = '" $resource_deletion_state "'" ''
    
);

    
$resources_in_deleted_state = array();
    
$resources_in_deleted_state sql_array($query);

    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 sql_query("SELECT cr.resource, r.archive FROM collection_resource cr LEFT JOIN resource r on r.ref=cr.resource WHERE cr.collection = '" $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']));
        
sql_query("DELETE FROM collection_resource  WHERE resource IN ('" implode("','",$r_refs) . "')");
        }

    return 
TRUE;
    }

This article was last updated 2nd December 2020 00:35 Europe/London time based on the source file dated 30th November 2020 11:55 Europe/London time.