Example #1
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 7/27/05
  */
 function saveWizard($cacheName)
 {
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $wizard = $this->getWizard($cacheName);
     $properties = $wizard->getAllValues();
     $centerPane = $this->getActionRows();
     ob_start();
     $path = $properties['filename']['tmp_name'];
     $filename = $properties['filename']['name'];
     if ($properties['filename']['name'] == "") {
         print "Please choose a file to upload!";
         $centerPane->add(new Block(ob_get_contents(), 1));
         ob_end_clean();
         return FALSE;
     }
     $newName = $this->moveArchive($path, $filename);
     //===== THIS ARRAY DEFINES THINGS THAT SHOULD NOT BE IMPORTED =====//
     $this->_ignore = array("REMOTE_FILE", "FILE_URL", "FILE", "FILE_DATA", "FILE_NAME", "MIME_TYPE", "THUMBNAIL_DATA", "THUMBNAIL_MIME_TYPE", "FILE_SIZE", "DIMENSIONS", "THUMBNAIL_DIMENSIONS", "edu.middlebury.harmoni.repository.asset_content", "edu.middlebury.harmoni.repository.asset_content.Content");
     $repository = $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id')));
     $startTime = DateAndTime::now();
     $this->_hasErrors = false;
     //===== Exif and Tab-Delim Importers are special =====//
     if ($properties['file_type'] == "Tab-Delimited") {
         $importer = new TabRepositoryImporter($newName, $repository->getId(), false);
     } else {
         if ($properties['file_type'] == "Exif") {
             $importer = new ExifRepositoryImporter($newName, $repository->getId(), false);
         } else {
             if ($properties['file_type'] == "FilesOnly") {
                 $importer = new FilesOnlyRepositoryImporter($newName, $repository->getId(), false);
             }
         }
     }
     if (isset($importer)) {
         if ($properties['parent']) {
             $importer->setParent($repository->getAsset($idManager->getId($properties['parent'])));
         }
         $importer->import($properties['is_archived']);
         // something happened so tell the end user
         if ($importer->hasErrors()) {
             $importer->printErrorMessages();
             $this->_hasErrors = true;
         }
     }
     //===== Done with special "RepositoryImporters" =====//
     if ($properties['file_type'] == "XML") {
         if ($properties['is_archived'] == TRUE) {
             //	define an empty importer for decompression
             $importer = new XMLImporter($this->_ignore);
             $directory = $importer->decompress($newName);
             unset($importer);
             $this->_repository = $repository;
             $this->_importType = $properties['import_type'];
             if ($properties['parent']) {
                 $parent = $repository->getAsset($idManager->getId($properties['parent']));
             } else {
                 $parent = null;
             }
             $this->importDirectoriesDown($directory, $parent);
         } else {
             // not compressed, only one xml file
             $importer = XMLRepositoryImporter::withObject($this->_ignore, $repositoryManager->getRepository($idManager->getId($harmoni->request->get('collection_id'))), $newName, $properties['import_type']);
             if ($properties['parent']) {
                 $importer->setParent($repository->getAsset($idManager->getId($properties['parent'])));
             }
             $importer->parseAndImportBelow("asset", 100);
             // something happened so tell the end user
             if ($importer->hasErrors()) {
                 $importer->printErrorMessages();
                 $this->_hasErrors = true;
             }
             unset($importer);
         }
     }
     // Unlink the directory
     if (isset($directory) && $directory) {
         $this->deleteRecursive($directory);
     }
     if (file_exists($newName)) {
         unlink($newName);
     }
     if ($this->_hasErrors) {
         $centerPane->add(new Block(ob_get_contents(), 1));
         ob_end_clean();
         return FALSE;
     }
     // Update any newly modified assets' tags
     $searchProperties = new HarmoniProperties(new Type("repository", "harmoni", "order"));
     $searchProperties->addProperty("order", $order = "ModificationDate");
     $searchProperties->addProperty("direction", $direction = "DESC");
     $assets = $repository->getAssetsBySearch($criteria = '*', new Type("Repository", "edu.middlebury.harmoni", "DisplayName"), $searchProperties);
     $systemAgentId = $idManager->getId('system:concerto');
     $tagGenerator = StructuredMetaDataTagGenerator::instance();
     while ($assets->hasNext()) {
         $asset = $assets->next();
         if ($startTime->isGreaterThan($asset->getModificationDate())) {
             break;
         }
         $tagGenerator->regenerateTagsForAsset($asset, $systemAgentId, 'concerto', $repository->getId());
     }
     // clean and clear
     $centerPane->add(new Block(ob_get_contents(), 1));
     ob_end_clean();
     return TRUE;
 }
Example #2
0
 /**
  * Save our results. Tearing down and unsetting the Wizard is handled by
  * in {@link runWizard()} and does not need to be implemented here.
  * 
  * @param string $cacheName
  * @return boolean TRUE if save was successful and tear-down/cleanup of the
  *		Wizard should ensue.
  * @access public
  * @since 10/24/07
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     $properties = $wizard->getAllValues();
     /*********************************************************
      * Create generic
      *********************************************************/
     if ($properties['asset_kind'] == 'generic') {
         $this->addGeneric = true;
         $this->parentAsset = $properties['parent'];
         return true;
     }
     /*********************************************************
      * Asset from file
      *********************************************************/
     try {
         if ($properties['file']['name'] == "") {
             throw new Exception("Please choose a file to upload.");
         }
         $path = $properties['file']['tmp_name'];
         $filename = $properties['file']['name'];
         $newName = $this->moveArchive($path, $filename);
         // check the file type:
         $mime = Services::getService("MIME");
         $mimeType = $mime->getMimeTypeForFileName(basename($filename));
         // Load Exif metadata from JPEGS
         if ($mimeType == "image/jpeg") {
             $importer = new ExifRepositoryImporter($newName, $this->getRepositoryId(), false);
         } else {
             $importer = new FilesOnlyRepositoryImporter($newName, $this->getRepositoryId(), false);
         }
         if ($properties['parent']) {
             $repository = $this->getRepository();
             $idManager = Services::getService("Id");
             $this->parentAsset = $properties['parent'];
             $importer->setParent($repository->getAsset($idManager->getId($properties['parent'])));
         }
         ob_start();
         $importer->import(false);
         $importerOutput = ob_get_clean();
         if ($importer->hasErrors()) {
             ob_start();
             $importer->printErrorMessages();
             throw new Exception(ob_get_clean());
         }
     } catch (Exception $e) {
         unlink($newName);
         rmdir(dirname($newName));
         $centerPane = $this->getActionRows();
         $centerPane->add(new Block($e->getMessage(), 1));
         return false;
     }
     unlink($newName);
     rmdir(dirname($newName));
     return true;
 }