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

copyResourceDataValues()

Description

Copy resource data from one resource to another one.

Parameters

ColumnTypeDefaultDescription
$from integer Resource we are copying data from
$to
$resource_type ""
$ref integer Resource we are copying data to

Return

void

Location

include/resource_functions.php lines 6454 to 6490

Definition

 
function copyResourceDataValues($from$to$resource_type "")
    {
    
$from            escape_check($from);    
    
$to              escape_check($to);
    
$omit_fields_sql '';

    
// 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($from 0)
        {
        
$omitfields      sql_array("SELECT ref AS `value` FROM resource_type_field WHERE omit_when_copying = 1""schema");
        
$omit_fields_sql "AND rd.resource_type_field NOT IN ('" implode("','"$omitfields) . "')";
        }
    
    
$resource_type_sql "AND (rtf.resource_type = r.resource_type OR rtf.resource_type = 999 OR rtf.resource_type = 0)";
    
// Don't consider resource types if saving metadata template as fields from all types should be copied.
    
global $metadata_template_resource_type;
    if (isset(
$metadata_template_resource_type) && $resource_type==$metadata_template_resource_type)
        {
        
$resource_type_sql "";
        }

    
sql_query("
        INSERT INTO resource_data(resource, resource_type_field, value)
             SELECT '
{$to}',
                    rd.resource_type_field,
                    rd.value
               FROM resource_data AS rd
               JOIN resource AS r ON rd.resource = r.ref
               JOIN resource_type_field AS rtf ON rd.resource_type_field = rtf.ref
               
{$resource_type_sql}
              WHERE rd.resource = '
{$from}'
                
{$omit_fields_sql}
    "
);

    return;
    }

This article was last updated 1st March 2021 09:35 Europe/London time based on the source file dated 26th February 2021 17:25 Europe/London time.