Exemplo n.º 1
0
 public function hookAfterSaveItem($args)
 {
     $item = $args['record'];
     $post = $args['post'];
     if (!($post && isset($post['dropbox-files']))) {
         return;
     }
     $fileNames = $post['dropbox-files'];
     if ($fileNames) {
         if (!dropbox_can_access_files_dir()) {
             throw new Dropbox_Exception(__('The Dropbox files directory must be both readable and writable.'));
         }
         $filePaths = array();
         foreach ($fileNames as $fileName) {
             $filePaths[] = dropbox_validate_file($fileName);
         }
         $files = array();
         try {
             $files = insert_files_for_item($item, 'Filesystem', $filePaths, array('file_ingest_options' => array('ignore_invalid_files' => false)));
         } catch (Omeka_File_Ingest_InvalidException $e) {
             release_object($files);
             $item->addError('Dropbox', $e->getMessage());
             return;
         } catch (Exception $e) {
             release_object($files);
             throw $e;
         }
         release_object($files);
         // delete the files
         foreach ($filePaths as $filePath) {
             try {
                 unlink($filePath);
             } catch (Exception $e) {
                 throw $e;
             }
         }
     }
 }
Exemplo n.º 2
0
 /**
  * Create a new Item for each of the given files.
  *
  * @param array $filenames
  * @return array An array of errors that occurred when creating the
  *  Items, indexed by the filename that caused the error.
  */
 protected function _uploadFiles($fileNames)
 {
     if (!dropbox_can_access_files_dir()) {
         throw new Dropbox_Exception('The Dropbox files directory must be both readable and writable.');
     }
     $fileErrors = array();
     foreach ($fileNames as $fileName) {
         $item = null;
         try {
             $filePath = dropbox_validate_file($fileName);
             $itemMetadata = array('public' => $_POST['dropbox-public'], 'featured' => $_POST['dropbox-featured'], 'collection_id' => $_POST['dropbox-collection-id'] ? $_POST['dropbox-collection-id'] : null, 'tags' => $_POST['dropbox-tags']);
             $elementTexts = array('Dublin Core' => array('Title' => array(array('text' => $fileName, 'html' => false))));
             $fileMetadata = array('file_transfer_type' => 'Filesystem', 'file_ingest_options' => array('ignore_invalid_files' => false), 'files' => array($filePath));
             $item = insert_item($itemMetadata, $elementTexts, $fileMetadata);
             release_object($item);
             // delete the file from the dropbox folder
             unlink($filePath);
         } catch (Exception $e) {
             release_object($item);
             $fileErrors[$fileName] = $e->getMessage();
         }
     }
     return $fileErrors;
 }