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

save_resource_type()

Description

Save updated resource_type data

Parameters

ColumnTypeDefaultDescription
$ref int Ref of resource type
$savedata array Array of column values

Return

bool *

Location

include/config_functions.php lines 1548 to 1635

Definition

 
function save_resource_type(int $ref, array $savedata)
    {
    global 
$execution_lockout;
    
$restypes get_resource_types("",true,false,true);
    
$restype_refs array_column($restypes,"ref");
    if(!
checkperm('a') || !in_array($ref,$restype_refs))
        {
        return 
false;
        }

    
$setcolumns = [];
    
$setparams = [];
    
$restypes array_combine($restype_refs,$restypes);
    foreach(
$savedata as $savecol=>$saveval)
        {
        
debug("checking for column " $savecol " in " json_encode(($restype_refs),true));
        if(
$saveval === $restypes[$ref][$savecol])
            {
            
// Unchanged value, skip
            
continue;
            }
        switch(
$savecol)
            {
            case 
"name":
                
$setcolumns[] = "name";
                
$setparams[] = "s";
                
$setparams[] = mb_strcut($saveval0100);
                break;

            case 
"order_by":
            case 
"push_metadata":
            case 
"tab":
            case 
"colour":
            case 
"pull_images":
                
$setcolumns[] = $savecol;
                
$setparams[] = "i";
                
$setparams[] = $saveval;
                break;

            case 
"config_options":
                if (!
$execution_lockout)
                    {
                    
// Not allowed to save PHP if execution_lockout set.
                    
$setcolumns[] = $savecol;
                    
$setparams[] = "s";
                    
$setparams[] = $saveval;
                    }
                break;

            case 
"allowed_extensions":
                
$setcolumns[] = $savecol;
                
$setparams[] = "s";
                
$setparams[] = $saveval;
                break;

            case 
"icon":
                
$setcolumns[] = $savecol;
                
$setparams[] = "s";
                
$setparams[] = mb_strcut($saveval0120);
                break;

            default:
                
// Invalid option, ignore
                
break;
            }
        }
    if(
count($setcolumns) === 0)
        {
        return 
false;
        }

    
$setparams[] = "i";
    
$setparams[] = $ref;

    
ps_query(
        
"UPDATE resource_type
            SET " 
implode("=?,",$setcolumns) . "=?
            WHERE ref = ?"
$setparams
        
);

    for(
$n=0;$n<count($setcolumns);$n++)
        {
        
log_activity(null,LOG_CODE_EDITED,$setparams[(2*$n)+1],'resource_type',$setcolumns[$n],$ref,null,$restypes[$ref][$setcolumns[$n]]);
        }

    
clear_query_cache("schema");
    return 
true;
    }

This article was last updated 29th May 2024 10:35 Europe/London time based on the source file dated 23rd May 2024 18:05 Europe/London time.