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

delete_resource_type_field()

Description

Delete the specified metadata field. Also delets any node or resource_data rows associated with that field

Parameters

ColumnTypeDefaultDescription
$ref integer Metadata field id (ref from resource_type_field)
$varnames array Array of variable names

Return

boolean|string Returns true on success or text on failure describing error

Location

include/resource_functions.php lines 7999 to 8052

Definition

 
function delete_resource_type_field($ref)
    {
    global 
$lang$corefields;

    if(
'cli' != php_sapi_name() && !checkperm('a'))
        {
        return 
$lang["error-permissiondenied"];
        }

    
$fieldvars = array();
    foreach (
$corefields as $scope=>$scopevars)
        {
        foreach(
$scopevars as $varname)
            {
            global $
$varname;
            if(isset($
$varname) && (is_array($$varname) && in_array($ref,$$varname) || ((int)$$varname==$ref)))
                {
                
$fieldvars[] = $varname . ($scope != "BASE" " (" $scope ")" "");
                }
            }
        }

    if(
count($fieldvars) > 0)
        {
        return 
$lang["admin_delete_field_error"] . "<br />\$" implode(", \$",$fieldvars);
        }

    
    
$fieldinfo get_resource_type_field($ref);

    
$ref escape_check($ref);
    
    
// Delete the resource type field
    
sql_query("DELETE FROM resource_type_field WHERE ref='$ref'");

    
// Remove all data        
    
sql_query("DELETE FROM resource_data WHERE resource_type_field='$ref'");

    
// Remove all nodes and keywords or resources. Always remove nodes last otherwise foreign keys will not work
    
sql_query("DELETE rn.* FROM resource_node rn LEFT JOIN node n ON n.ref=rn.node WHERE n.resource_type_field='$ref'");
    
sql_query("DELETE nk.* FROM node_keyword AS nk LEFT JOIN node AS n ON n.ref = nk.node WHERE n.resource_type_field = '$ref'");
    
sql_query("DELETE FROM node WHERE resource_type_field='$ref'");

    
// Remove all keywords        
    
sql_query("DELETE FROM resource_keyword where resource_type_field='$ref'");

    
hook("after_delete_resource_type_field");

    
log_activity('Deleted metadata field "' $fieldinfo["title"] . '" (' $fieldinfo["ref"] . ')',LOG_CODE_DELETED,null,'resource_type_field',null,$ref);

    
clear_query_cache("schema");

    return 
true;
    }

This article was last updated 21st September 2020 20:35 Europe/London time based on the source file dated 18th September 2020 17:00 Europe/London time.