/** * 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; }
/** * 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 =====// $array = 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", "edu.middlebury.concerto.exhibition_repository", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata"); $hasErrors = false; if ($properties['file_type'] == "XML") { // define an empty importer for decompression if ($properties['is_archived'] == TRUE) { $importer = new XMLImporter($array); $directory = $importer->decompress($newName); // something happened so tell the end user if ($importer->hasErrors()) { $importer->printErrorMessages(); $hasErrors = true; } unset($importer); $dir = opendir($directory); while ($file = readdir($dir)) { // each folder is a collection if (is_dir($directory . "/" . $file) && $file != "." && $file != "..") { $importer = XMLRepositoryImporter::withFile($array, $directory . "/" . $file . "/metadata.xml", $properties['import_type']); $importer->parseAndImport("asset"); // something happened so tell the end user if ($importer->hasErrors()) { $importer->printErrorMessages(); $hasErrors = true; } unset($importer); } } closedir($dir); // Unlink the directory $this->deleteRecursive($directory); } else { // not compressed, only one xml file $importer = XMLRepositoryImporter::withFile($array, $newName, $properties['import_type']); $importer->parseAndImport("asset"); // something happened so tell the end user if ($importer->hasErrors()) { $importer->printErrorMessages(); $hasErrors = true; } } } if (file_exists($newName)) { unlink($newName); } if ($hasErrors) { $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return FALSE; } // clean and clear $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return TRUE; }
/** * 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(); $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); $array = array("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", "edu.middlebury.concerto.exhibition_repository", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position", "Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata"); if ($properties['file_type'] == "XML") { $importer = new XMLImporter($array); if ($properties['is_archived'] == TRUE) { $directory = $importer->decompress($newName); $importer = XMLImporter::withFile($array, $directory . "/metadata.xml", $properties['import_type']); } else { $importer = XMLImporter::withFile($array, $newName, $properties['import_type']); } $importer->parseAndImportBelow("asset", 75); } if ($importer->hasErrors()) { $importer->printErrorMessages(); $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return FALSE; } $centerPane->add(new Block(ob_get_contents(), 1)); ob_end_clean(); return true; }