Collections functions
General functions
Render functions
Theme permission functions
Resource functions

add_resource_nodes_multi()

Description

Add nodes in array to multiple resources. Changes made using this function will not be logged by default.

Parameters

ColumnTypeDefaultDescription
$resources array array Array of resource IDs to add nodes to
$nodes array array Array of node IDs to add
$checkperms boolean true Check permissions before adding?
$logthis boolean false Log this? Log entries are ideally added when more data on all the changes made is available to make reverts easier.

Return

boolean

Location

include/node_functions.php lines 1403 to 1459

Definition

 
function add_resource_nodes_multi($resources=array(),$nodes=array(), $checkperms truebool $logthis false)
    {
    global 
$userref;
    if((!
is_array($resources) && (string)(int)$resources != $resources) || (!is_array($nodes) && (string)(int)$nodes != $nodes))
        {return 
false;}

    
$resources array_values(array_filter($resources'is_int_loose'));
    
$nodes array_values(array_filter(is_array($nodes) ? $nodes : [$nodes], 'is_int_loose'));

    if(
$checkperms)
        {
        
// Need to check user has permissions to add nodes
        
foreach($resources as $resourceid)
            {
            
$resourcedata get_resource_data($resourceid);
            
$access get_edit_access($resourceid,$resourcedata["archive"],false,$resourcedata);
            if(!
$access)
                {return 
false;}
            
            if(
$resourcedata["lock_user"] > && $resourcedata["lock_user"] != $userref)
                {
                
$error get_resource_lock_message($resourcedata["lock_user"]);
                return 
false;
                }
            }
        }

    
$resources_chunks array_chunk($resourcesSYSTEM_DATABASE_IDS_CHUNK_SIZE);
    foreach(
$resources_chunks as $resources_chunk)
        {
        
$resource_node_values '';
        
$sql_params = [];
        foreach(
$resources_chunk as $resource)
            {
            foreach(
$nodes as $node)
                {
                
$resource_node_values .= ',(?, ?)';
                
$sql_params[] = 'i';
                
$sql_params[] = $resource;
                
$sql_params[] = 'i';
                
$sql_params[] = $node;
                }

            if(
$logthis && !empty($nodes))
                {
                
log_node_changes($resource$nodes, []);
                }
            }
        
$resource_node_values ltrim($resource_node_values',');

        if(
$resource_node_values !== '')
            {
            
ps_query("INSERT INTO resource_node (resource, node) VALUES {$resource_node_values} ON DUPLICATE KEY UPDATE hit_count=hit_count"$sql_params);
            }
        }
    return 
true;
    }

This article was last updated 4th October 2022 10:05 Europe/London time based on the source file dated 3rd October 2022 13:50 Europe/London time.