Collections functions
Encryption functions
General functions
Render functions
Theme permission functions
Video functions
Resource functions

copyAllDataToResource()

Description

Provides the ability to copy any metadata field data from one resource to another.

Parameters

ColumnTypeDefaultDescription
$from integer Resource we are copying data from
$to integer The Resource ID that needs updating
$resourcedata false

Return

boolean

Location

include/resource_functions.php lines 6437 to 6473

Definition

 
function copyAllDataToResource($from$to$resourcedata false)
    {
    if((int)(string)
$from !== (int)$from || (int)(string)$to !== (int)$to)
        {
        return 
false;
        }
        
    if(!
$resourcedata)
        {
        
$resourcedata get_resource_data($to);
        }
        
    if(!
get_edit_access($to,$resourcedata["archive"],false,$resourcedata))
        {
        return 
false;
        }
        
    
copyResourceDataValues($from$to);
    
copy_resource_nodes($from$to);
    
    
# Update 'joined' fields in resource table 
    
$joins=get_resource_table_joins();
    
$joinsql "UPDATE resource AS target LEFT JOIN resource AS source ON source.ref='{$from}' SET ";
    
$joinfields "";
    foreach(
$joins as $joinfield)
        {
        if(
$joinfields != "")
            {
            
$joinfields .= ",";
            }
        
$joinfields .= "target.field{$joinfield} = source.field{$joinfield}";
        
        }
    
$joinsql $joinsql $joinfields " WHERE target.ref='{$to}'";
    
sql_query($joinsql);
    return 
true;
    }

This article was last updated 17th May 2021 22:35 Europe/London time based on the source file dated 11th May 2021 10:25 Europe/London time.