Example #1
0
 /**
  * Insert a File record corresponding to an ingested file and its metadata.
  * 
  * @param string $newFilePath Path to the file within Omeka.
  * @param string $oldFilename The original filename for the file.  This will
  * usually be displayed to the end user.
  * @param array $elementMetadata See ActsAsElementText::addElementTextsByArray()
  * for more information about the format of this array.
  * @uses ActsAsElementText::addElementTextsByArray()
  * @return File
  */
 private function _createFile($newFilePath, $oldFilename, $elementMetadata = array())
 {
     // Normally, the MIME type validator sets the type to this class's
     // static $mimeType property during validation. If that validator has
     // been disabled (from the admin settings menu, for example), set the
     // MIME type here.
     if (self::$mimeType) {
         $mimeType = self::$mimeType;
         // Make sure types don't leak between files.
         self::$mimeType = null;
     } else {
         $detect = new Omeka_File_MimeType_Detect($newFilePath);
         $mimeType = $detect->detect();
     }
     $file = new File();
     try {
         $file->original_filename = $oldFilename;
         $file->mime_type = $mimeType;
         $file->setDefaults($newFilePath);
         if ($elementMetadata) {
             $file->addElementTextsByArray($elementMetadata);
         }
         fire_plugin_hook('after_ingest_file', array('file' => $file, 'item' => $this->_item));
         $this->_item->addFile($file);
     } catch (Exception $e) {
         if (!$file->exists()) {
             $file->unlinkFile();
         }
         throw $e;
     }
     return $file;
 }