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_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 8825 to 8884

Definition

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

    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 ")" "");
                }
            }
        }

    
// Prevent deleting a "core" field required by other parts of the system (e.g plugins)
    
$core_field_scopes = [];
    foreach(
$core_field_refs as $scope => $core_refs)
        {
        if(
in_array($ref$core_refs) && !in_array($scope$core_field_scopes))
            {
            
$core_field_scopes[] = $scope;
            }
        }

    if(
count($fieldvars) > 0)
        {
        return 
$lang["admin_delete_field_error"] . "<br/>\$" implode(", \$",$fieldvars);
        }
    elseif(!empty(
$core_field_scopes))
        {
        return 
sprintf('%s%s'$lang["admin_delete_field_error_scopes"], implode(', '$core_field_scopes));
        }


    
$fieldinfo get_resource_type_field($ref);

    
// Delete the resource type field
    
ps_query("DELETE FROM resource_type_field WHERE ref=?",["i",$ref]);

    
// Remove all nodes and keywords or resources. Always remove nodes last otherwise foreign keys will not work
    
ps_query("DELETE rn.* FROM resource_node rn LEFT JOIN node n ON n.ref=rn.node WHERE n.resource_type_field = ?",["i",$ref]);
    
ps_query("DELETE nk.* FROM node_keyword AS nk LEFT JOIN node AS n ON n.ref = nk.node WHERE n.resource_type_field = ?",["i",$ref]);
    
ps_query("DELETE FROM node WHERE resource_type_field = ?",["i",$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 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.