Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test functions

delete_resources_in_collection()

Parameters

ColumnTypeDefaultDescription
$collection

Location

include/resource_functions.php lines 6748 to 6800

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 4th December 2024 09:05 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.