Coding standards
Security in ResourceSpace
Developer reference
Database
Action functions
Admin functions
Ajax functions
Annotation functions
API functions
Collections functions
Comment functions
Config functions
CSV export functions
Dash functions
Debug functions
Encryption functions
Facial recognition functions
File functions
General functions
Language functions
Log functions
Login functions
Message functions
Migration functions
Node functions
PDF functions
Plugin functions
Render functions
Reporting functions
Request functions
Research functions
Slideshow functions
Theme permission functions
User functions
Video functions
Database functions
Metadata functions
Resource functions
Search functions
Map functions
Job functions
Tab functions
Test 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 7038 to 7078

Definition

 
function copyAllDataToResource($from$to$resourcedata false)
    {
    global 
$userref;

    if((int)(string)
$from !== (int)$from || (int)(string)$to !== (int)$to)
        {
        return 
false;
        }

    if(!
$resourcedata)
        {
        
$resourcedata get_resource_data($to);
        }

    
# Permission check isn't required if copying data from the user's upload template as with edit then upload mode.
    
if (
        
$from != $userref
        
&& !get_edit_access($to,$resourcedata["archive"],$resourcedata)
        ) {
            return 
false;
        }

    
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=? SET ";
    
$joinfields "";
    foreach(
$joins as $joinfield)
        {
        if(
$joinfields != "")
            {
            
$joinfields .= ",";
            }
        
$joinfield=(int)$joinfield// Ensure integer for inclusion in SQL.
        
$joinfields .= "target.field{$joinfield} = source.field{$joinfield}";
        }
    
$joinsql $joinsql $joinfields " WHERE target.ref=?";
    
ps_query($joinsql,array("i",$from,"i",$to));
    return 
true;
    }

This article was last updated 17th November 2024 15:35 Europe/London time based on the source file dated 15th November 2024 18:30 Europe/London time.