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

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 1385 to 1446

Definition

 
function add_resource_nodes_multi($resources=array(),$nodes=array(), $checkperms truebool $logthis false)
    {
    global 
$userref$lang;
    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"],$resourcedata);
            if(!
$access)
                {return 
false;}
            
            if(
$resourcedata["lock_user"] > && $resourcedata["lock_user"] != $userref)
                {
                return 
false;
                }
            }
        }

    
$resources_chunks array_chunk($resourcesSYSTEM_DATABASE_IDS_CHUNK_SIZE);
    
$done=0;
    foreach(
$resources_chunks as $resources_chunk)
        {
        if (
PHP_SAPI !== "cli") {
            
set_processing_message(str_replace(["[done]","[total]"],[$done,count($resources)],$lang["processing_updating_resources"]));
        }
        
$done+=count($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 13th December 2024 08:35 Europe/London time based on the source file dated 11th December 2024 22:35 Europe/London time.