Esempio n. 1
0
 /**
  * Ingest from a URL.
  *
  * Accepts the following non-prefixed keys:
  *
  * + ingest_url: (required) The URL to ingest. The idea is that some URLs
  *   contain sensitive data that should not be saved to the database, such
  *   as private keys. To preserve the URL, remove sensitive data from the
  *   URL and set it to o:source.
  * + store_original: (optional, default true) Whether to store an original
  *   file. This is helpful when you want the media to have thumbnails but do
  *   not need the original file.
  *
  * {@inheritDoc}
  */
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     if (!isset($data['ingest_url'])) {
         $errorStore->addError('error', 'No ingest URL specified');
         return;
     }
     $uri = new HttpUri($data['ingest_url']);
     if (!($uri->isValid() && $uri->isAbsolute())) {
         $errorStore->addError('ingest_url', 'Invalid ingest URL');
         return;
     }
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $file->setSourceName($uri->getPath());
     $this->downloadFile($uri, $file->getTempPath());
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $media->setHasThumbnails($hasThumbnails);
     if (!isset($data['store_original']) || $data['store_original']) {
         $fileManager->storeOriginal($file);
         $media->setHasOriginal(true);
     }
     $media->setFilename($file->getStorageName());
     $media->setMediaType($file->getMediaType());
     if (!array_key_exists('o:source', $data)) {
         $media->setSource($uri);
     }
 }
Esempio n. 2
0
 /**
  * {@inheritDoc}
  */
 public function ingest(Media $media, Request $request, ErrorStore $errorStore)
 {
     $data = $request->getContent();
     $fileData = $request->getFileData();
     if (!isset($fileData['file'])) {
         $errorStore->addError('error', 'No files were uploaded');
         return;
     }
     if (!isset($data['file_index'])) {
         $errorStore->addError('error', 'No file index was specified');
         return;
     }
     $index = $data['file_index'];
     if (!isset($fileData['file'][$index])) {
         $errorStore->addError('error', 'No file uploaded for the specified index');
         return;
     }
     $fileManager = $this->getServiceLocator()->get('Omeka\\File\\Manager');
     $file = $this->getServiceLocator()->get('Omeka\\File');
     $fileInput = new FileInput('file');
     $fileInput->getFilterChain()->attach(new RenameUpload(['target' => $file->getTempPath(), 'overwrite' => true]));
     $fileData = $fileData['file'][$index];
     $fileInput->setValue($fileData);
     if (!$fileInput->isValid()) {
         foreach ($fileInput->getMessages() as $message) {
             $errorStore->addError('upload', $message);
         }
         return;
     }
     // Actually process and move the upload
     $fileInput->getValue();
     $file->setSourceName($fileData['name']);
     $hasThumbnails = $fileManager->storeThumbnails($file);
     $fileManager->storeOriginal($file);
     $media->setFilename($file->getStorageName());
     $media->setMediaType($file->getMediaType());
     $media->setHasThumbnails($hasThumbnails);
     $media->setHasOriginal(true);
     if (!array_key_exists('o:source', $data)) {
         $media->setSource($fileData['name']);
     }
 }
Esempio n. 3
0
 /**
  * {@inheritDoc}
  */
 public function setHasOriginal($hasOriginal)
 {
     $this->__initializer__ && $this->__initializer__->__invoke($this, 'setHasOriginal', array($hasOriginal));
     return parent::setHasOriginal($hasOriginal);
 }