Omeka_File_Ingest_Upload

Package: File\Ingest

class Omeka_File_Ingest_Upload

extends Omeka_File_Ingest_AbstractIngest

This class creates a bridge between the ZF File Transfer HTTP adapter and Omeka’s file ingest classes.

property Omeka_File_Ingest_Upload::$_adapter

protected Zend_File_Transfer_Adapter_Http

property Omeka_File_Ingest_Upload::$_adapterOptions

protected array

property Omeka_File_Ingest_Upload::$_item

protected Item

property Omeka_File_Ingest_Upload::$_options

protected array

Set of arbitrary options to use when ingesting files.

property Omeka_File_Ingest_Upload::$mimeType

string

The current validated file MIME type.

Omeka_File_Ingest_Upload::_buildAdapter()

Create a ZF HTTP file transfer adapter.

Omeka_File_Ingest_Upload::setOptions($options)

In addition to the default options available for Omeka_File_Ingest_AbstractIngest, this understands the following options: - ‘ignoreNoFile’ => boolean False by default. Whether or not to ignore - validation errors that occur when an uploaded file is missing. This - may occur when a file input is left empty on a form.

This option can be overridden by the ‘ignore_invalid_files’ option. For instance, if ‘ignoreNoFile’ is set to false but ‘ignore_invalid_files’ is set to true, any exceptions due to missing uploads will be suppressed and ignored.

Parameters:
  • $options (array) –
Omeka_File_Ingest_Upload::_getOriginalFilename($fileInfo)

The ‘name’ attribute of the $_FILES array will always contain the original name of the file.

Parameters:
  • $fileInfo (array) –
Returns:

string

Omeka_File_Ingest_Upload::_transferFile($fileInfo, $originalFilename)

Use the Zend_File_Transfer adapter to upload the file.

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

string Path to the file in Omeka.

Omeka_File_Ingest_Upload::_parseFileInfo($fileInfo)

Use the adapter to extract the array of file information.

Parameters:
  • $fileInfo (string|null) – The name of the form input to ingest.
Returns:

array

Omeka_File_Ingest_Upload::addValidator(Zend_Validate_Interface $validator)

Use the Zend Framework adapter to handle validation instead of the built-in _validateFile() method.

Parameters:
  • $validator (Zend_Validate_Interface) –
Omeka_File_Ingest_Upload::setItem(Item $item)

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

Parameters:
Omeka_File_Ingest_Upload::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_Upload::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_Upload::_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_Upload::_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_Upload::_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_Upload::_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_Upload::_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.