/** * Returns true if the passed {@link WizardComponent} validates against this rule. * @param ref object $component * @access public * @return boolean */ function checkValue($component) { $doc = new Harmoni_DOMDocument(); try { $doc->loadXML($component->getAllValues()); } catch (DOMException $e) { $component->setErrorText($e->getMessage()); return false; } try { $doc->schemaValidateWithException($this->xmlSchemaPath); } catch (ValidationFailedException $e) { $component->setErrorText($e->getMessage()); return false; } return true; }
/** * Update the options XML with a new document * * @param object Harmoni_DOMDocument $optionsDocument * @return null * @access public * @since 5/15/08 */ public function updateOptionsDocument(Harmoni_DOMDocument $optionsDocument) { if (!$this->canModify()) { throw new PermissionDeniedException(); } // Unset the options if we have an empty document. if (!isset($optionsDocument->documentElement)) { $this->updateThemeDataByType('options.xml', ''); return; } // Validate any options document given. $optionsDocument->schemaValidateWithException(HARMONI . '/Gui2/theme_options.xsd'); $this->updateThemeDataByType('options.xml', $optionsDocument->saveXML()); }
/** * Answer an XML document for the options for this theme * * @return object Harmoni_DOMDocument * @access public * @since 5/15/08 */ public function getOptionsDocument() { $options = new Harmoni_DOMDocument(); if (file_exists($this->optionsPath)) { $options->preserveWhiteSpace = false; $options->load($this->optionsPath); $options->schemaValidateWithException(dirname(__FILE__) . '/theme_options.xsd'); } return $options; }
/** * 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 1/28/08 */ public function saveWizard($cacheName) { $wizard = $this->getWizard($cacheName); if (!$wizard->validate()) { return false; } $values = $wizard->getAllValues(); // printpre($values); // return false; try { if (!defined('DATAPORT_TMP_DIR')) { throw new Exception("DATAPORT_TMP_DIR must be defined in the Segue configuration."); } $archivePath = $values['mode']['backup_file']['tmp_name']; $archiveName = basename($archivePath); $decompressDir = DATAPORT_TMP_DIR . '/' . $archiveName . '_source'; if (!$values['mode']['backup_file']['size']) { throw new Exception("File upload error - archive was not successfully uploaded and has no size."); } $this->decompressArchive($archivePath, $decompressDir); // Do the import $director = SiteDispatcher::getSiteDirector(); $doc = new Harmoni_DOMDocument(); $doc->load($decompressDir . "/site.xml"); // Validate the document contents $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); $mediaDir = $decompressDir; switch ($values['mode']['trust']) { case 'all': $class = 'DomImportSiteVisitor'; break; case 'time_only': $class = 'UntrustedAgentDomImportSiteVisitor'; break; default: $class = 'UntrustedAgentAndTimeDomImportSiteVisitor'; } $importer = new $class($doc, $mediaDir, $director); if ($values['mode']['roles'] == '1') { $importer->enableRoleImport(); } if ($values['mode']['comments'] == '0') { $importer->disableCommentImport(); } if (isset($values['owners'])) { $idMgr = Services::getService('Id'); foreach ($values['owners']['admins'] as $adminIdString) { $importer->addSiteAdministrator($idMgr->getId($adminIdString)); } } $importer->enableStatusOutput(); $site = $importer->importAtSlot($values['mode']['slotname']); // Delete the uploaded file unlink($archivePath); // Delete the decompressed Archive $this->deleteRecursive($decompressDir); } catch (Exception $importException) { // Delete the uploaded file try { if (file_exists($archivePath)) { unlink($archivePath); } } catch (Exception $deleteException) { print "\n<div>\n\t"; print $deleteException->getMessage(); print "\n</div>"; } // Delete the decompressed Archive try { if (file_exists($decompressDir)) { $this->deleteRecursive($decompressDir); } } catch (Exception $deleteException) { print "\n<div>\n\t"; print $deleteException->getMessage(); print "\n</div>"; } print "\n<div>\n\t"; print $importException->getMessage(); // print HarmoniErrorHandler::printDebugBacktrace($importException->getTrace()); print "\n</div>"; $wizard->backupFile->setValue(array('name' => null, 'size' => null, 'type' => null)); /********************************************************* * Log the failure *********************************************************/ if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Segue"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Error", "Recoverable errors."); $item = new AgentNodeEntryItem("Create Site", "Failure in importing site for placeholder, '" . $values['mode']['slotname'] . "'. " . $importException->getMessage()); $item->setBacktrace($importException->getTrace()); $item->addTextToBactrace("Archive Upload: " . printpre($values['mode']['backup_file'], true)); $log->appendLogWithTypes($item, $formatType, $priorityType); } return false; } /********************************************************* * Log the success *********************************************************/ if (Services::serviceRunning("Logging")) { $loggingManager = Services::getService("Logging"); $log = $loggingManager->getLogForWriting("Segue"); $formatType = new Type("logging", "edu.middlebury", "AgentsAndNodes", "A format in which the acting Agent[s] and the target nodes affected are specified."); $priorityType = new Type("logging", "edu.middlebury", "Event_Notice", "Normal events."); $item = new AgentNodeEntryItem("Create Site", "Site imported for placeholder, '" . $values['mode']['slotname'] . "'."); $item->addNodeId($site->getQualifierId()); $log->appendLogWithTypes($item, $formatType, $priorityType); } return true; }
/** * Create the new site with this template at the slot specified. * * @param object Slot $slot * @param optional string $displayName * @param optional string $description * @return object SiteNavBlockSiteComponent * @access public * @since 6/11/08 */ public function createSite(Slot $slot, $displayName = 'Untitled', $description = '') { $director = SiteDispatcher::getSiteDirector(); $doc = new Harmoni_DOMDocument(); $doc->load($this->_path . "/site.xml"); // Validate the document contents $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd"); $mediaDir = $this->_path . "/media"; if (!file_exists($mediaDir)) { $mediaDir = null; } // @todo Strip out any history. $importer = new StripHistoryImportSiteVisitor($doc, $mediaDir, $director); $importer->disableCommentImport(); $site = $importer->importAtSlot($slot->getShortname()); try { // Replace #SITE_NAME# and #SITE_DESCRIPTION# placeholders $site->acceptVisitor(new Segue_Templates_ReplacePlaceholderVisitor($displayName, $description)); } catch (Exception $e) { $director->deleteSiteComponent($site); $slot->deleteSiteId(); throw $e; } return $site; }