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

resource_log()

Description

Log resource activity

Parameters

ColumnTypeDefaultDescription
$resource int - resource ref -- resource_log.resource
$type string - log code defined in include/definitions.php -- resource_log.type
$field int - resource type field -- resource_log.resource_type_field
$notes string "" - text notes -- resource_log.notes
$fromvalue mixed "" - original value (int or string) -- resource_log.previous_value
$tovalue mixed "" - new value (int or string)
$usage int -1 -- resource_log.usageoption

Return

int (or false)

Location

include/resource_functions.php lines 4069 to 4180

Definition

 
function resource_log($resource$type$field$notes=""$fromvalue=""$tovalue=""$usage=-1)
    {
    global 
$userref,$k,$lang,$resource_log_previous_ref$internal_share_access;

    
// Param type checks
    
$param_str = array($type,$notes);
    
$param_num = array($resource,$usage);

    foreach(
$param_str as $par)
        {
        if (!
is_string($par))
            {
            return 
false;
            }
        }

    foreach(
$param_num as $par)
        {
        if (!
is_numeric($par))
            {
            return 
false;
            }
        }

    
// check that $usage is valid value for int type db field
    // https://dev.mysql.com/doc/refman/8.0/en/integer-types.html
    
$options_db_int = [ 'options' => [ 'min_range' => -2147483648,   'max_range' => 2147483647] ];
    if (!
filter_var($usageFILTER_VALIDATE_INT$options_db_int) && $usage != 0)
        {
        return 
false;
        }

    
// If it is worthy of logging, update the modified date in the resource table
    
update_timestamp($resource);

    if((
$resource === RESOURCE_LOG_APPEND_PREVIOUS && !isset($resource_log_previous_ref)) || ($resource !== RESOURCE_LOG_APPEND_PREVIOUS && $resource 0))
        {
        return 
false;
        }

    if (
$fromvalue===$tovalue)
        {
        
$diff="";
        }
    else
        {
        switch (
$type)
            {
            case 
LOG_CODE_STATUS_CHANGED:
                
$diff $lang["status" $fromvalue] . " -> " $lang["status" $tovalue];
                break;

            case 
LOG_CODE_ACCESS_CHANGED:
                
$diff $lang["access" $fromvalue] . " -> " $lang["access" $tovalue];
                break;

            
// do not do a diff, just dump out whole new value (this is so we can cleanly append transform output)
            
case LOG_CODE_TRANSFORMED:
            case 
LOG_CODE_NODE_REVERT:
            case 
LOG_CODE_EXTERNAL_UPLOAD:
            case 
LOG_CODE_CREATED:
                
$diff $tovalue;
                break;

            default:
                
$diff log_diff($fromvalue$tovalue);
            }
        }

    
// Avoid out of memory errors such as when working with large PDF files
    
if(mb_strlen($diff) > 10000)
        {
        
$diff mb_strcut($diff010000);
        }

    
$modifiedlogtype=hook("modifylogtype","",array($type));
    if (
$modifiedlogtype)
        {
        
$type $modifiedlogtype;
        }

    
$modifiedlognotes=hook("modifylognotes","",array($notes,$type,$resource));
    if(
$modifiedlognotes)
        {
        
$notes $modifiedlognotes;
        }

    if (
$resource === RESOURCE_LOG_APPEND_PREVIOUS)
        {
        
ps_query("UPDATE `resource_log` SET `diff`=left(concat(`diff`,'\n',?),60000) WHERE `ref`=?",array("s",$diff,"i",$resource_log_previous_ref));
        return 
$resource_log_previous_ref;
        }
    else
        {
        
ps_query("INSERT INTO `resource_log` (`date`, `user`, `resource`, `type`, `resource_type_field`, `notes`, `diff`, `usageoption`, `access_key`, `previous_value`) VALUES (NOW(), ?, ?, ?, ?, ?, ?, ?, ?, ?)",
            [
            
'i', (($userref != "" && $type !== LOG_CODE_SYSTEM) ? $userref null),
            
'i'$resource,
            
's'$type,
            
'i', (($field=="" || !is_numeric($field)) ? null $field),
            
's'$notes,
            
's'$diff,
            
'i'$usage,
            
's', ((isset($k) && !$internal_share_access) ? mb_strcut($k050): null),
            
's'$fromvalue
            
]
        );
        
$log_ref sql_insert_id();
        
$resource_log_previous_ref $log_ref;
        return 
$log_ref;
        }
    }

This article was last updated 13th December 2024 20:35 Europe/London time based on the source file dated 13th December 2024 14:45 Europe/London time.