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

update_disk_usage()

Description

Updates the disk usage for a specified resource by calculating the total size of the files
in the resource's directory and storing the result in the resource table.

This function first checks for the size of the primary resource file and then scans the
associated folder to compute the total disk usage, excluding any files in staticsync locations.

Parameters

ColumnTypeDefaultDescription
$resource int The resource reference whose disk usage is to be updated.

Return

bool Returns true on success, or false if the directory does not exist.

Location

include/resource_functions.php lines 6287 to 6314

Definition

 
function update_disk_usage($resource)
    {
    
# we're also going to record the size of the primary resource here before we do the entire folder
    
$ext ps_value("SELECT file_extension value FROM resource where ref = ? AND file_path IS NULL",array("i",$resource), 'jpg');
    
$path get_resource_path($resource,true,'',false,$ext);
    if (
file_exists($path)){
        
$rsize filesize_unlimited($path);
    } else {
        
$rsize 0;
    }

    
# Scan the appropriate filestore folder and update the disk usage fields on the resource table. Use the thm size so that we don't get a Staticsync location
    
$dir=dirname(get_resource_path($resource,true,"thm",false));
    if (!
file_exists($dir)) {return false;} # Folder does not yet exist.
    
$d dir($dir);
    
$total=0;
    while (
$f $d->read())
        {
        if (
$f!=".." && $f!=".")
            {
            
$s=(int) filesize_unlimited($dir "/" .$f);
            
$total+=$s;
            }
        }
    
ps_query("update resource set disk_usage=?,disk_usage_last_updated=now(),file_size=? where ref=?",array("i",$total,"i",$rsize,"i",$resource));

    return 
true;
    }

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