Collections functions
Encryption functions
General functions
Theme permission functions
Resource functions

extractFitsMetadata()

Description

Extract FITS metadata from a file for a specific resource.

Parameters

ColumnTypeDefaultDescription
$file_path string Path to the file from which you will extract FITS metadata
$resource integer|array Resource ID or resource array (as returned by get_resource_data())

Return

boolean

Location

include/metadata_functions.php lines 109 to 179

Definition

 
function extractFitsMetadata($file_path$resource)
    {
    if(
get_utility_path('fits') === false)
        {
        return 
false;
        }

    if(!
file_exists($file_path))
        {
        return 
false;
        }

    if(!
is_array($resource) && !is_numeric($resource))
        {
        return 
false;
        }

    if(!
is_array($resource) && is_numeric($resource) && $resource)
        {
        
$resource get_resource_data($resource);
        }

    
$resource_type escape_check($resource['resource_type']);

    
// Get a list of all the fields that have a FITS field set
    
$rs_fields_to_read_for sql_query("
           SELECT rtf.ref,
                  rtf.`type`,
                  rtf.`name`,
                  rtf.fits_field
             FROM resource_type_field AS rtf
            WHERE length(rtf.fits_field) > 0
              AND (rtf.resource_type = '
{$resource_type}' OR rtf.resource_type = 0)
         ORDER BY fits_field;
    "
"schema");

    if(
=== count($rs_fields_to_read_for))
        {
        return 
false;
        }

    
// Run FITS and extract metadata
    
$fits_xml            runFitsForFile($file_path);
    
$fits_updated_fields = array();

    foreach(
$rs_fields_to_read_for as $rs_field)
        {
        
$fits_fields explode(','$rs_field['fits_field']);

        foreach(
$fits_fields as $fits_field)
            {
            
$fits_field_value getFitsMetadataFieldValue($fits_xml$fits_field);

            if(
'' == $fits_field_value)
                {
                continue;
                }

            
update_field($resource['ref'], $rs_field['ref'], $fits_field_value);

            
$fits_updated_fields[] = $rs_field['ref'];
            }
        }

    if(
count($fits_updated_fields))
        {
        return 
true;
        }

    return 
false;
    }

This article was last updated 15th July 2020 02:05 Europe/London time based on the source file dated 5th June 2020 16:33 Europe/London time.