Collections functions
General functions
Node functions
Render functions
Theme permission functions
User functions
Resource functions

copy_resource_type_field_nodes()

Parameters

ColumnTypeDefaultDescription
$from
bool $to:
are they
we so
array"i"
0
"schema";
$FIXED_LIST_FIELD_TYPES

Location

include/node_functions.php lines 1696 to 1751

Definition

 
function copy_resource_type_field_nodes($from$to): bool
    
{
    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 ps_value("SELECT `type` AS `value` FROM resource_type_field WHERE ref = ?", array("i"$from), 0"schema");

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

    if (
FIELD_TYPE_CATEGORY_TREE == $type)
        {
        
$nodes get_cattree_nodes_ordered($fromnulltrue);
        
// Remove the fake "root" node which get_cattree_nodes_ordered() is adding since we won't be
        // using get_cattree_node_strings() with it.
        
array_shift($nodes);
        
$nodes array_filter($nodes'node_is_active');

        
// array(from_ref => new_ref)
        
$processed_nodes = array();

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

            
// Make the parent the expected type of a node parent (i.e. null|int) because get_cattree_nodes_ordered() is
            // setting root parent to string zero for some unknown reason.
            
$parent $node['parent'] == null $node['parent'];

            
// Child nodes need to have their parent set to the new parent ID
            
if($parent !== null)
                {
                
$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
    
$nodes array_filter(get_nodes($from), 'node_is_active');
    foreach(
$nodes as $node)
        {
        
set_node(null$to$node['name'], $node['parent'], $node['order_by']);
        }

    return 
true;
    }

This article was last updated 26th April 2024 11:05 Europe/London time based on the source file dated 15th April 2024 11:30 Europe/London time.