Omeka_File_Ingest_AbstractSourceIngest

Package: File\Ingest

class Omeka_File_Ingest_AbstractSourceIngest

extends Omeka_File_Ingest_AbstractIngest

This abstract class encapsulates all the behavior that facilitates file ingest based on the assumption that each file can be retrieved via a string containing both the name and location of that file.

Applies to: URLs, file paths on a server. Does not apply to: direct HTTP uploads.

Also, if the original filename is not properly represented by the source identifier (incorrect file extension, etc.), a more accurate filename can be provided via the ‘filename’ attribute.

property Omeka_File_Ingest_AbstractSourceIngest::$_item

protected Item

property Omeka_File_Ingest_AbstractSourceIngest::$_options

protected array

Set of arbitrary options to use when ingesting files.

property Omeka_File_Ingest_AbstractSourceIngest::$mimeType

string

The current validated file MIME type.

Omeka_File_Ingest_AbstractSourceIngest::_getFileSource($fileInfo)

The ‘source’ key of the file info is parsed out by default.

Parameters:
  • $fileInfo
Returns:

string

Omeka_File_Ingest_AbstractSourceIngest::_parseFileInfo($files)

Normalize a file info array.

Files can be represented as one of the following: - a string, representing the source identifier for a single file. - an array containing a ‘source’ key. - an array of strings. - an array of arrays that each contain a ‘source’ key.

Parameters:
  • $files (string|array) –
Returns:

array Formatted info array.

Omeka_File_Ingest_AbstractSourceIngest::_addZendValidatorAttributes($fileInfo)

Modify the set of info about each file to ensure that it is compatible with the Zend_Validate_File_* validators.

Parameters:
  • $fileInfo (array) –
Returns:

array

Omeka_File_Ingest_AbstractSourceIngest::_getOriginalFilename($fileInfo)

Retrieve the original filename.

By default, this is stored as the ‘name’ attribute in the array.

Parameters:
  • $fileInfo (array) –
Returns:

string

Omeka_File_Ingest_AbstractSourceIngest::_transferFile($fileInfo, $originalFilename)

Transfer the file to Omeka.

Parameters:
  • $fileInfo (array) –
  • $originalFilename (string) –
Returns:

string Path to file in Omeka.

Omeka_File_Ingest_AbstractSourceIngest::_transfer($source, $destination, $fileInfo)

Transfer the file from the original location to its destination.

Examples would include transferring the file via wget, or making use of stream wrappers to copy the file.

Parameters:
  • $source (string) –
  • $destination (string) –
  • $fileInfo (array) –
Omeka_File_Ingest_AbstractSourceIngest::_validateSource($source, $info)

Determine whether or not the file source is valid.

Examples of this would include determining whether a URL exists, or whether read access is available for a given file.

Parameters:
  • $source (string) –
  • $info (array) –
Omeka_File_Ingest_AbstractSourceIngest::setItem(Item $item)

Set the item to use as a target when ingesting files.

Parameters:
Omeka_File_Ingest_AbstractSourceIngest::factory($adapterName, $item, $options = array())

Factory to retrieve Omeka_File_Ingest_* instances.

Parameters:
  • $adapterName (string) – Ingest adapter.
  • $item (Item) –
  • $options (array) –
Returns:

Omeka_File_Ingest_AbstractIngest

Omeka_File_Ingest_AbstractSourceIngest::setOptions($options)

Set options for ingesting files.

Parameters:
  • $options (array) – Available options include: - ‘ignore_invalid_files’: boolean false by default. Determine whether or not to throw exceptions when a file is not valid. This can be based on a number of factors: whether or not the original identifier is valid (i.e. a valid URL), whether or not the file itself is valid (i.e. invalid file extension), or whether the basic algorithm for ingesting the file fails (i.e., files cannot be transferred because the files/ directory is not writeable). This option is primarily useful for skipping known invalid files when ingesting large data sets.
Omeka_File_Ingest_AbstractSourceIngest::ingest($fileInfo)

Ingest based on arbitrary file identifier info.

If this is an array that has a ‘metadata’ key, that should be an array representing element text metadata to assign to the file. See ActsAsElementText::addElementTextsByArray() for more details.

Parameters:
  • $fileInfo (mixed) – An arbitrary input (array, string, object, etc.) that corresponds to one or more files to be ingested into Omeka.
Returns:

array Ingested file records.

Omeka_File_Ingest_AbstractSourceIngest::_ignoreIngestErrors()

Determine whether or not to ignore file ingest errors. Based on ‘ignore_invalid_files’, which is false by default.

Returns:bool
Omeka_File_Ingest_AbstractSourceIngest::_logException(Exception $e)

Log any exceptions that are thrown as a result of attempting to ingest invalid files.

These are logged as warnings because they are being ignored by the script, so they don’t actually kill the file ingest process.

Parameters:
  • $e (Exception) –
Omeka_File_Ingest_AbstractSourceIngest::_createFile($newFilePath, $oldFilename, $elementMetadata = array())

Insert a File record corresponding to an ingested file and its metadata.

Parameters:
  • $newFilePath (string) – Path to the file within Omeka.
  • $oldFilename (string) – The original filename for the file. This will usually be displayed to the end user.
  • $elementMetadata (array) – See ActsAsElementText::addElementTextsByArray() for more information about the format of this array.
Returns:

File

Omeka_File_Ingest_AbstractSourceIngest::_getDestination($fromFilename)

Retrieve the destination path for the file to be transferred.

This will generate an archival filename in order to prevent naming conflicts between ingested files.

This should be used as necessary by Omeka_File_Ingest_AbstractIngest implementations in order to determine where to transfer any given file.

Parameters:
  • $fromFilename (string) – The filename from which to derive the archival filename.
Returns:

string

Omeka_File_Ingest_AbstractSourceIngest::addValidator(Zend_Validate_Interface $validator)

Add Zend Framework file validators.

Emulates the way Zend Framework adds validators.

Parameters:
  • $validator (Zend_Validate_Interface) –
Returns:

Omeka_File_Ingest_AbstractIngest

Omeka_File_Ingest_AbstractSourceIngest::_validateFile($filePath, $fileInfo)

Validate a file that has been transferred to Omeka.

Implementations of Omeka_File_Ingest_AbstractIngest should use this to validate the uploaded file based on user-defined security criteria.

Important: $fileInfo may need to contain the following keys in order to work with particular Zend_Validate_File_* validation classes:

  • ‘name’: string filename (for Zend_Validate_File_Extension) If ZF is

unable to determine the file extension when validating, it will check the ‘name’ attribute instead. Current use cases involve saving the file to a temporary location before transferring to Omeka. Most temporary files do not maintain the original file extension. - ‘type’: string MIME type (for Zend_Validate_File_MimeType) If ZF is unable to determine the mime type from the transferred file. Unless the server running Omeka has a mime_magic file or has installed the FileInfo extension, this will be necessary.

Parameters:
  • $filePath (string) – Absolute path to the file. The file should be local and readable, which is required by most (if not all) of the Zend_Validate_File_* classes.
  • $fileInfo (array) – Set of file info that describes a given file being ingested.
Returns:

bool True if valid, otherwise throws an exception.