collection_download_process_csv_metadata_file()

Description

Add a CSV containing resource metadata to a downloaded zip file during creation of the zip.

(passed by reference so can be added to)

Parameters

ColumnTypeDefaultDescription
&$dl_data array
&$zip
$dl_data array Array of collection download data from process_collection_download()
$zip object Collection zip file

Return

void

Location

include/collections_functions.php lines 4661 to 4690

Definition

 
function collection_download_process_csv_metadata_file(array &$dl_data, &$zip)
{
    
// Include the CSV file with the metadata of the resources found in this collection
    
$result $dl_data['collection_resources'];
    
$csv_file    get_temp_dir(false$dl_data['id']) . '/Col-' $dl_data['collection'] . '-metadata-export.csv';
    if (isset(
$result[0]["ref"])) {
        
$result array_column($result"ref");
    }
    
generateResourcesMetadataCSV($resultfalsefalse$csv_file);
    
// Add link to file for use by tar to prevent full paths being included.
    
if ($dl_data['collection_download_tar']) {
        
$usertempdir get_temp_dir(false"rs_" $GLOBALS["userref"] . "_" $dl_data['id']);
        
debug("collection_download adding symlink: " $csv_file " - " $usertempdir DIRECTORY_SEPARATOR 'Col-' $dl_data['collection'] . '-metadata-export.csv');
        
$GLOBALS["use_error_exception"] = true;
        try {
            
symlink($csv_file$usertempdir DIRECTORY_SEPARATOR 'Col-' $dl_data['collection'] . '-metadata-export.csv');
        } catch (
Throwable $e) {
            
debug("collection_download_process_csv_metadata_file(): Unable to create symlink for CSV {$e->getMessage()}");
            return;
        }
        unset(
$GLOBALS["use_error_exception"]);
    } elseif (
$GLOBALS['use_zip_extension']) {
        
debug("Adding $csv_file to " $zip->filename);
        
$zip->addFile($csv_file'Col-' $dl_data['collection'] . '-metadata-export.csv');
    } else {
        
debug("collection_download_process_csv_metadata_file: "$csv_file);
        
$dl_data['includefiles'][] = $csv_file;
    }
    
$dl_data['deletion_array'][] = $csv_file;
}

This article was last updated 21st April 2025 21:35 Europe/London time based on the source file dated 17th April 2025 18:30 Europe/London time.