Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

copy_resource_type_field_nodes()

Description

Copy all nodes from one metadata field to another one.
Used mostly with copy field functionality

Parameters

ColumnTypeDefaultDescription
$from integer resource_type_field ID FROM which we copy
$to integer resource_type_field ID TO which we copy

Return

boolean

Location

include/node_functions.php lines 1442 to 1491

Definition

 
function copy_resource_type_field_nodes($from$to)
    {
    global 
$FIXED_LIST_FIELD_TYPES;

    
// Since field has been copied, they are both the same, so we only need to check the from field
    
$type sql_value("SELECT `type` AS `value` FROM resource_type_field WHERE ref = '{$from}'"0"schema");

    if(!
in_array($type$FIXED_LIST_FIELD_TYPES))
        {
        return 
false;
        }

    
$nodes get_nodes($fromnulltrue);

    
// Handle category trees
    
if(== $type)
        {
        
// array(from_ref => new_ref)
        
$processed_nodes = array();

        foreach(
$nodes as $node)
            {
            if(
array_key_exists($node['ref'], $processed_nodes))
                {
                continue;
                }

            
$parent $node['parent'];

            
// Child nodes need to have their parent set to the new parent ID
            
if('' != trim($parent))
                {
                
$parent $processed_nodes[$parent];
                }

            
$new_node_id                   set_node(null$to$node['name'], $parent$node['order_by']);
            
$processed_nodes[$node['ref']] = $new_node_id;
            }

        return 
true;
        }

    
// Default handle for types different than category trees
    
foreach($nodes as $node)
        {
        
set_node(null$to$node['name'], $node['parent'], $node['order_by']);
        }

    return 
true;
    }

This article was last updated 15th July 2020 07:05 Europe/London time based on the source file dated 6th July 2020 18:09 Europe/London time.