Collections functions
General functions
Render functions
Theme permission functions
Resource 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
$resourceto integer Resource we are copying data to

Return

void

Location

include/node_functions.php lines 1635 to 1700

Definition

 
function copy_resource_nodes($resourcefrom$resourceto)
    {
    
$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);
            }
        else if (
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 = ?
        
{$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
                
{$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());

    return;
    }

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