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

copy_resource_nodes()

Description

Copy resource nodes from one resource to another. Only applies for active metadata fields.

Parameters

ColumnTypeDefaultDescription
$resourcefrom integer Resource we are copying data from
void $resourceto:
for check
$resourceto integer Resource we are copying data to

Location

include/node_functions.php lines 1648 to 1713

Definition

 
function copy_resource_nodes($resourcefrom$resourceto): void
    
{
    
$omit_fields_sql '';
    
$omit_fields_sql_params = array();
    
$omitfields = array();

    
// When copying normal resources from one to another, check for fields that should be excluded
    // NOTE: this does not apply to user template resources (negative ID resource)
    
if($resourcefrom 0)
        {
        
$omitfields ps_array("SELECT ref AS `value` FROM resource_type_field WHERE omit_when_copying = 1", array(), "schema");
        }

    
// Exclude fields which user cannot edit "F?" or cannot see "f-?". With config, users permissions maybe overridden for different resource types.
    
global $userpermissions;

    
$no_permission_fields = array();
    foreach (
$userpermissions as $permission_to_check)
        {
        if (
substr($permission_to_check02) == "f-")
            {
            
$no_permission_fields[] = substr($permission_to_check2);
            }
        elseif (
substr($permission_to_check01) == "F")
            {
            
$no_permission_fields[] = substr($permission_to_check1);
            }
        }
    
    
$omitfields array_merge($omitfieldsarray_unique($no_permission_fields));

    if (
count($omitfields) > 0)
        {
        
$omit_fields_sql " AND n.resource_type_field NOT IN (" ps_param_insert(count($omitfields)) . ") ";
        
$omit_fields_sql_params ps_param_fill($omitfields"i");
        }
    else
        {
        
$omit_fields_sql "";
        }

    
// This is for logging after the insert statement
    
$nodes_to_add ps_array("
    SELECT node value
        FROM resource_node AS rnold
    LEFT JOIN node AS n ON n.ref = rnold.node
    WHERE resource = ?
        AND n.`active` = 1
        
{$omit_fields_sql};
    "
array_merge(array("i", (int) $resourcefrom), $omit_fields_sql_params));

    
ps_query("
        INSERT INTO resource_node(resource, node, hit_count, new_hit_count)
             SELECT ?, node, 0, 0
               FROM resource_node AS rnold
          LEFT JOIN node AS n ON n.ref = rnold.node
          LEFT JOIN resource_type_field AS rtf ON n.resource_type_field = rtf.ref
              WHERE resource = ?
              AND rtf.active = 1
                AND n.`active` = 1
                
{$omit_fields_sql}
                 ON DUPLICATE KEY UPDATE hit_count = rnold.new_hit_count;
    "
array_merge(array("i"$resourceto"i"$resourcefrom), $omit_fields_sql_params));

    
log_node_changes($resourceto,$nodes_to_add,array());
    }

This article was last updated 5th December 2024 07:35 Europe/London time based on the source file dated 28th November 2024 12:10 Europe/London time.