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

replace_resource_file()

Description

Replace the primary resource file with the file located at the path specified

Parameters

ColumnTypeDefaultDescription
$ref integer Resource ID to replace
$file_location
$no_exif false
$autorotate false
$keep_original true

Return

boolean

Location

include/resource_functions.php lines 7340 to 7394

Definition

 
function replace_resource_file($ref$file_location$no_exif=false$autorotate=false$keep_original=true)
    {
    global 
$replace_resource_preserve_option$notify_on_resource_change_days$lang$userref;
    
debug("replace_resource_file(ref=" $ref ", file_location=" $file_location ", no_exif=" . ($no_exif "TRUE" "FALSE") . " , keep_original=" . ($keep_original "TRUE" "FALSE"));

    
$resource get_resource_data($ref);
    if (!
get_edit_access($ref,$resource["archive"],$resource)
        ||
        (
$resource["lock_user"] > && $resource["lock_user"] != $userref)
        )
        {
        return 
false;
        }

    
// save original file as an alternative file
    
if($replace_resource_preserve_option && $keep_original)
        {
        
// the following save may not succeed because there is no original in which case a debug log will have been created
        // allow replace resource to continue with its principal task of uploading
        
save_original_file_as_alternative($ref);
        }

    if (
filter_var($file_locationFILTER_VALIDATE_URL))
        {
        
$uploadstatus upload_file_by_url($ref,$no_exif,false,$autorotate,$file_location);
        if(!
$uploadstatus)
            {
            
debug("replace_resource_file - upload_file_by_url() failed");
            return 
false;
            }
        }
    else
        {
        
$uploadstatus upload_file($ref,$no_exif,false,$autorotate,$file_location,false,false);
        if(!
$uploadstatus)
            {
            
debug("replace_resource_file - upload_file() failed");
            return 
false;
            }
        }

    
hook('replace_resource_file_extra''', array($resource));
    
$log_ref resource_log($ref,LOG_CODE_REPLACED,'','','');
    
daily_stat('Resource upload'$ref);
    
hook("additional_replace_existing","",array($ref,$log_ref));

    if(
$notify_on_resource_change_days != 0)
        {
        
// we don't need to wait for this.
        
ob_flush();flush();
        
notify_resource_change($ref);
        }

    return 
true;
    }

This article was last updated 19th March 2024 02:05 Europe/London time based on the source file dated 11th March 2024 14:25 Europe/London time.