Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

delete_collection()

Description

Deletes the collection with reference $ref

Parameters

ColumnTypeDefaultDescription
$collection integer

Return

boolean|void

Location

include/collections_functions.php lines 891 to 938

Definition

 
function delete_collection($collection)
    {
    global 
$home_dash$lang;
    if(!
is_array($collection))
        {
        
$collection=get_collection($collection);
        }
    if(!
$collection)
        {
        return 
false;
        }
    
$ref=$collection["ref"];
    
$type $collection["type"];
    
    if(!
collection_writeable($ref) || is_featured_collection_category_by_children($ref))
        {
        return 
false;
        }

    
hook("beforedeletecollection","",array($ref));
    
ps_query("DELETE FROM collection WHERE ref=?",array("i",$ref));
    
ps_query("DELETE FROM collection_resource WHERE collection=?",array("i",$ref));
    
ps_query("DELETE FROM collection_keyword WHERE collection=?",array("i",$ref));
    
ps_query("DELETE FROM external_access_keys WHERE collection=?",array("i",$ref));
    
    if(
$home_dash)
        {
        
// Delete any dash tiles pointing to this collection
        
$collection_dash_tiles=ps_array("SELECT ref value FROM dash_tile WHERE link LIKE ?",array("s","%search.php?search=!collection" $ref "&%"));
        if(
count($collection_dash_tiles)>0)
            {
            
ps_query("DELETE FROM dash_tile WHERE ref IN (" .  ps_param_insert(count($collection_dash_tiles)) . ")",ps_param_fill($collection_dash_tiles,"i"));
            
ps_query("DELETE FROM user_dash_tile WHERE dash_tile IN (" .  ps_param_insert(count($collection_dash_tiles)) . ")",ps_param_fill($collection_dash_tiles,"i"));
            }
        }

    
collection_log($ref,LOG_CODE_COLLECTION_DELETED_COLLECTION,0$collection["name"] . " (" $lang["owner"] . ":" $collection["username"] . ")");

    if(
$type === COLLECTION_TYPE_FEATURED)
        {
        
clear_query_cache("featured_collections");
        }
    else
        {
        
/** {@see create_collection()} */
        
clear_query_cache("collection_access{$collection['user']}");
        }
    }

This article was last updated 19th March 2024 11:05 Europe/London time based on the source file dated 15th March 2024 17:00 Europe/London time.