Example #1
0
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 10/9/08
  */
 public function execute()
 {
     header('Content-Type: text/plain;');
     try {
         if (!$this->isAuthorizedToExecute()) {
             throw new PermissionDeniedException("You must be logged in.");
         }
         $mgr = SlotManager::instance();
         $slot = $mgr->getSlotByShortname(RequestContext::value('slot'));
         $slot->makeAlias($mgr->getSlotByShortname(RequestContext::value('target_slot')));
         print _("Success");
         /*********************************************************
          * 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("Alias Made", "'" . $slot->getShortname() . "' has been made an alias of '" . RequestContext::value('target_slot') . "'.");
             $item->addNodeId($slot->getSiteId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     } catch (OperationFailedException $e) {
         print $e->getMessage();
     } catch (UnknownIdException $e) {
         print $e->getMessage();
     }
     exit;
 }
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryId = $idManager->getId(RequestContext::value('collection_id'));
     $systemAgentId = $idManager->getId('system:concerto');
     $tagGenerator = StructuredMetaDataTagGenerator::instance();
     $tagGenerator->regenerateTagsForRepository($repositoryId, $systemAgentId, 'concerto');
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Regenerated Tags", "Auto-generated tags were regenerated");
         $item->addNodeId($repositoryId);
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     RequestContext::sendTo($harmoni->request->quickURL("collection", "browse", array('collection_id' => RequestContext::value('collection_id'))));
 }
Example #3
0
 /**
  * Process changes to the site components. This is the method that the various
  * actions that modify the site should override.
  * 
  * @param object SiteDirector $director
  * @return void
  * @access public
  * @since 4/14/06
  */
 function processChanges(SiteDirector $director)
 {
     $component = $director->getSiteComponentById(SiteDispatcher::getCurrentNodeId());
     $component->acceptVisitor(new ModifySettingsSiteVisitor());
     /*********************************************************
      * Log the event
      *********************************************************/
     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("Component Modified", $component->getComponentClass() . " modified.");
         $item->addNodeId($component->getQualifierId());
         $site = $component->getDirector()->getRootSiteComponent($component->getId());
         if (!$component->getQualifierId()->isEqual($site->getQualifierId())) {
             $item->addNodeId($site->getQualifierId());
         }
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
 }
Example #4
0
 /**
  * Process the changes and build the output
  * 
  * @return void
  * @access public
  * @since 10/25/07
  */
 public function buildContent()
 {
     try {
         ob_start();
         $fileAsset = $this->getFileAsset();
         $fileAssetId = $fileAsset->getId();
         $contentAsset = $this->getContentAsset();
         $repository = $fileAsset->getRepository();
         $repository->deleteAsset($fileAsset->getId());
         // Log the success or 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", "Event_Notice", "Normal events.");
             $message = "File deleted with id '" . $fileAssetId->getIdString() . "'.";
             $item = new AgentNodeEntryItem("Media Library", $message);
             $item->addNodeId($fileAssetId);
             $item->addNodeId($contentAsset->getId());
             $idManager = Services::getService("Id");
             $director = AssetSiteDirector::forAsset($contentAsset);
             $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
             $item->addNodeId($idManager->getId($site->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $error = ob_get_clean();
         if ($error) {
             $this->error($error);
         }
     } catch (Exception $e) {
         $this->error($e->getMessage());
     }
     $this->start();
     print $this->getQuota();
     // No content.
     $this->end();
 }
Example #5
0
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 7/10/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException();
     }
     $authZ = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     $hierarchyManager = Services::getService('Hierarchy');
     $site = SiteDispatcher::getCurrentRootNode();
     $hierarchy = $hierarchyManager->getHierarchy($idManager->getId("edu.middlebury.authorization.hierarchy"));
     $infoList = $hierarchy->traverse($idManager->getId($site->getId()), Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_DOWN, Hierarchy::TRAVERSE_LEVELS_ALL);
     $status = new StatusStars(str_replace('%1', $infoList->count(), _("Rebuilding Implicit AZs on %1 nodes.")));
     $status->initializeStatistics($infoList->count());
     $azCache = $authZ->getAuthorizationCache();
     while ($infoList->hasNext()) {
         $info = $infoList->next();
         $node = $hierarchy->getNode($info->getNodeId());
         // 			printpre("Rebuilding implicit AZs for ".$node->getId()." '".$node->getDisplayName()."'. Ancestors:");
         // 			printpre($node->getAncestorIds());
         $azCache->createHierarchyImplictAZs($node, $node->getAncestorIds());
         $status->updateStatistics();
     }
     printpre("Done.");
     /*********************************************************
      * Log the event
      *********************************************************/
     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", "Errors that did not halt execution");
         $item = new AgentNodeEntryItem("Rebuilt Implict AZs", "Hierarchy-Implicit AZs for site '" . $site->getDisplayName() . "' were rebuilt manually.");
         $item->addNodeId($site->getQualifierId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
 }
Example #6
0
 /**
  * Execute the action
  * 
  * @return void
  * @access public
  * @since 10/9/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException("You must be logged in.");
     }
     $mgr = SlotManager::instance();
     $slot = $mgr->getSlotByShortname(RequestContext::value('slot'));
     $oldTarget = $slot->getAliasTarget();
     $slot->makeNotAlias();
     /*********************************************************
      * 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("Alias Removed", "'" . $slot->getShortname() . "' is no longer an alias of '" . $oldTarget->getShortname() . "'.");
         $item->addNodeId($oldTarget->getSiteId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $harmoni = Harmoni::instance();
     RequestContext::sendTo($harmoni->request->quickURL('portal', 'list'));
 }
Example #7
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $asset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_id')));
     // Log the action
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Delete Node", "Exhibition deleted:\n<br/>&nbsp; &nbsp; &nbsp;" . $asset->getDisplayName());
         $item->addNodeId($asset->getId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $repository->deleteAsset($idManager->getId(RequestContext::value('exhibition_id')));
     RequestContext::locationHeader($harmoni->request->quickURL("exhibitions", "browse"));
 }
 /**
  * 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 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // Make sure we have a valid Repository
     $authZ = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $slideshowAsset = $repository->getAsset($idManager->getId(RequestContext::value('slideshow_id')));
     $properties = $wizard->getAllValues();
     $status = new StatusStars(_("Saving Slideshow"));
     $status->initializeStatistics(count($properties['slidestep']['slides']) + 2);
     // First, verify that we chose a parent that we can add children to.
     if ($authZ->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $slideshowAsset->getId())) {
         $slideshowAssetId = $slideshowAsset->getId();
         $this->_slideshowAssetId = $slideshowAssetId;
         // Update the Name and description
         if ($properties['namedescstep']['display_name']) {
             $slideshowAsset->updateDisplayName($properties['namedescstep']['display_name']);
         }
         if ($properties['namedescstep']['description']) {
             $slideshowAsset->updateDescription($properties['namedescstep']['description']);
         }
         // Update the effective/expiration dates
         // 			if ($properties['datestep']['effective_date'])
         // 				$slideshowAsset->updateEffectiveDate(
         // 					DateAndTime::fromString(
         // 					$properties['datestep']['effective_date']));
         // 			if ($properties['datestep']['expiration_date'])
         // 				$slideshowAsset->updateExpirationDate(
         // 					DateAndTime::fromString(
         // 					$properties['datestep']['expiration_date']));
         // --- Slides ---
         $slideAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slide", "Slides are components of Slide-Shows that contain captions and may reference media Assets.");
         $slideRecordStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure");
         $targetIdPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.target_id");
         $textPositionPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.text_position");
         $displayMetadataPartStructId = $idManager->getId("Repository::edu.middlebury.concerto.exhibition_repository::edu.middlebury.concerto.slide_record_structure.edu.middlebury.concerto.slide_record_structure.display_metadata");
         $setManager = Services::getService("Sets");
         $pSlideOrder = $setManager->getPersistentSet($slideshowAssetId);
         $slideIterator = $slideshowAsset->getAssets();
         // ---- Add/Update Slides in new order (hopefully)
         $existingSlides = array();
         while ($slideIterator->hasNext()) {
             $currentSlide = $slideIterator->next();
             $id = $currentSlide->getId();
             $existingSlides[] = $id->getIdString();
         }
         $pSlideOrder->removeAllItems();
         $status->updateStatistics();
         foreach ($properties['slidestep']['slides'] as $slideProperties) {
             // 				print get_class($slideProperties['slideId']).": ".$slideProperties['title'];
             if (!isset($slideProperties['slideId'])) {
                 // ---- Clean the inputs ----
                 if (isset($slideProperties['title'])) {
                     $title = $slideProperties['title'];
                 } else {
                     $title = '';
                 }
                 if (isset($slideProperties['caption'])) {
                     $caption = $slideProperties['caption'];
                 } else {
                     $caption = '';
                 }
                 if (isset($slideProperties['text_position'])) {
                     $textPosition = String::withValue($slideProperties['text_position']);
                 } else {
                     $textPosition = String::withValue('');
                 }
                 if (isset($slideProperties['show_target_metadata'])) {
                     $displayMetadata = Boolean::withValue($slideProperties['show_target_metadata']);
                 } else {
                     $displayMetadata = Boolean::false();
                 }
                 if (isset($slideProperties['_assetId'])) {
                     $targetId = String::withValue($slideProperties['_assetId']->getIdString());
                 } else {
                     $targetId = String::withValue('');
                 }
                 // ---- Create the asset ----
                 $slideAsset = $repository->createAsset($title, $caption, $slideAssetType);
                 $slideAssetId = $slideAsset->getId();
                 $slideshowAsset->addAsset($slideAssetId);
                 // Add it to the order field
                 $pSlideOrder->addItem($slideAssetId);
                 // ---- Set the additional info ----
                 $slideRecord = $slideAsset->createRecord($slideRecordStructId);
                 $slideRecord->createPart($textPositionPartStructId, $textPosition);
                 $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata);
                 $slideRecord->createPart($targetIdPartStructId, $targetId);
             } else {
                 if (in_array($slideProperties['slideId']->getIdString(), $existingSlides)) {
                     $slideAsset = $repository->getAsset($slideProperties['slideId']);
                     $slideAsset->updateDisplayName($slideProperties['title']);
                     $slideAsset->updateDescription($slideProperties['caption']);
                     $textPositionIterator = $slideAsset->getPartsByPartStructure($textPositionPartStructId);
                     if ($textPositionIterator->hasNext()) {
                         $part = $textPositionIterator->next();
                         $part->updateValue(new String($slideProperties['text_position']));
                     }
                     $showMetadataIterator = $slideAsset->getPartsByPartStructure($displayMetadataPartStructId);
                     if ($showMetadataIterator->hasNext()) {
                         $part = $showMetadataIterator->next();
                         $part->updateValue(new Boolean($slideProperties['show_target_metadata']));
                     }
                     $pSlideOrder->addItem($slideProperties['slideId']);
                     $records = $slideAsset->getRecordsByRecordStructure($slideRecordStructId);
                     $slideRecord = $records->next();
                 }
             }
             $status->updateStatistics();
         }
         // ==== Remove slide assets no longer in slideshow ----
         foreach ($existingSlides as $older) {
             $old = $idManager->getId($older);
             if (!$pSlideOrder->isInSet($old)) {
                 $slideshowAsset->removeAsset($old, false);
                 $repository->deleteAsset($old);
             }
         }
         $status->updateStatistics();
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $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("Modify Node", "Slideshow Modified");
             $item->addNodeId($slideshowAssetId);
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 8/15/06
  */
 function buildContent()
 {
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId("edu.middlebury.concerto.exhibition_repository"));
     $exhibitionId = $idManager->getId(RequestContext::value('exhibition_id'));
     $exhibition = $repository->getAsset($exhibitionId);
     $slideshowId = $idManager->getId(RequestContext::value('slideshow_id'));
     $slideshowAsset = $repository->getAsset($slideshowId);
     $setManager = Services::getService("Sets");
     $exhibitionSet = $setManager->getPersistentSet($exhibitionId);
     $oldPosition = $exhibitionSet->getPosition($slideshowId);
     $newPosition = RequestContext::value('new_position');
     // Out of range Error Condition
     if ($newPosition < 0 || $newPosition >= $exhibitionSet->count()) {
         // Log the error
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $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", "Errors.");
             $item = new AgentNodeEntryItem("Reorder Slideshows Failed", "Out of range error: Slideshow in the " . $exhibition->getDisplayName() . " exhibition could not be moved from position {$oldPosition} to {$newPosition} (" . $exhibitionSet->count() . " items in the set).");
             $item->addNodeId($exhibition->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     } else {
         $exhibitionSet->moveToPosition($slideshowId, $newPosition);
         // Log the action
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $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("Reorder Slideshows", "Slideshows in the " . $exhibition->getDisplayName() . " exhibition have been reorderd.");
             $item->addNodeId($exhibition->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         // Remove any missing slideshows
         $slideshowsIdStrings = array();
         $slideshows = $exhibition->getAssets();
         while ($slideshows->hasNext()) {
             $slideshow = $slideshows->next();
             $slideshowId = $slideshow->getId();
             $slideshowsIdStrings[] = $slideshowId->getIdString();
         }
         $itemsToRemove = array();
         $exhibitionSet->reset();
         while ($exhibitionSet->hasNext()) {
             $itemId = $exhibitionSet->next();
             if (!in_array($itemId->getIdString(), $slideshowsIdStrings)) {
                 $itemsToRemove[] = $itemId;
             }
         }
         foreach ($itemsToRemove as $id) {
             $exhibitionSet->removeItem($id);
         }
     }
     RequestContext::locationHeader($harmoni->request->quickURL("exhibitions", "browse_exhibition", array("exhibition_id" => $exhibitionId->getIdString())));
 }
Example #10
0
 /**
  * Execute this action.
  * 
  * @return void
  * @access public
  * @since 7/28/08
  */
 public function execute()
 {
     if (!$this->isAuthorizedToExecute()) {
         throw new PermissionDeniedException(_("Your are not authorized to copy this site here."));
     }
     $srcSlot = $this->getSourceSlot();
     $srcSiteAsset = $this->getSourceSiteAsset();
     $director = SiteDispatcher::getSiteDirector();
     $srcComponent = $director->getSiteComponentFromAsset($srcSiteAsset);
     $destSlot = $this->getDestSlot();
     if (RequestContext::value('command') == 'copy') {
         try {
             /*********************************************************
              * Export the Site
              *********************************************************/
             $exportDir = DATAPORT_TMP_DIR . "/" . $srcSlot->getShortname() . "-" . str_replace(':', '_', DateAndTime::now()->asString());
             mkdir($exportDir);
             // Do the export
             $visitor = new DomExportSiteVisitor($exportDir);
             $visitor->enableStatusOutput(_("Exporting from original location."));
             $srcComponent->acceptVisitor($visitor);
             $doc = $visitor->doc;
             // Validate the result
             // 			printpre(htmlentities($doc->saveXMLWithWhitespace()));
             // 			$tmp = new Harmoni_DomDocument;
             // 			$tmp->loadXML($doc->saveXMLWithWhitespace());
             // 			$tmp->schemaValidateWithException(MYDIR."/doc/raw/dtds/segue2-site.xsd");
             $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd");
             // 			printpre($this->listDir($exportDir));
             // 			throw new Exception('test');
             /*********************************************************
              * Import the site
              *********************************************************/
             $importer = new DomImportSiteVisitor($doc, $exportDir, $director);
             if (RequestContext::value('copy_permissions') == 'true') {
                 $importer->enableRoleImport();
             }
             if (RequestContext::value('copy_discussions') != 'true') {
                 $importer->disableCommentImport();
             }
             // 			if (isset($values['owners'])) {
             // 				$idMgr = Services::getService('Id');
             // 				foreach($values['owners']['admins'] as $adminIdString)
             // 					$importer->addSiteAdministrator($idMgr->getId($adminIdString));
             // 			}
             $importer->enableStatusOutput(_("Importing into new location"));
             $importer->makeUserSiteAdministrator();
             $site = $importer->importAtSlot($destSlot->getShortname());
             // Delete the decompressed Archive
             $this->deleteRecursive($exportDir);
             /*********************************************************
              * 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("Copy Site", "Site copied from placeholder, '" . $srcSlot->getShortname() . "' to '" . $destSlot->getShortname() . "'.");
                 $item->addNodeId($site->getQualifierId());
                 $log->appendLogWithTypes($item, $formatType, $priorityType);
             }
         } catch (Exception $e) {
             $this->deleteRecursive($exportDir);
             if (file_exists($exportDir . ".tar.gz")) {
                 unlink($exportDir . ".tar.gz");
             }
             throw $e;
         }
     } else {
         // Detach the site from the source slot.
         $srcSlot->deleteSiteId();
         // Attach the site to the dest slot.
         $destSlot->setSiteId($srcSiteAsset->getId());
         // Make the source an alias of the destination so that links still work.
         $srcSlot->makeAlias($destSlot);
         /*********************************************************
          * 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("Move Site", "Site moved from placeholder, '" . $srcSlot->getShortname() . "' to '" . $destSlot->getShortname() . "'.");
             $item->addNodeId($destSlot->getSiteId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     }
     // Remove from selection?
     if (RequestContext::value('remove_after_use') == 'remove') {
         $selection = Segue_Selection::instance();
         $selection->removeSiteComponent($srcComponent);
     }
     print "\n" . _("Done");
     exit;
 }
Example #11
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repository = $repositoryManager->getRepository($idManager->getId(RequestContext::value('collection_id')));
     $asset = $repository->getAsset($idManager->getId(RequestContext::value('asset_id')));
     // Remove this asset from the tagging manager
     $tagManager = Services::getService('Tagging');
     $tagManager->deleteItems(TaggedItem::forId($asset->getId(), 'concerto'));
     // Log the action
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Delete Node", "Asset deleted:\n<br/>&nbsp; &nbsp; &nbsp;" . $asset->getDisplayName());
         $item->addNodeId($asset->getId());
         $item->addNodeId($repository->getId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $repository->deleteAsset($idManager->getId(RequestContext::value('asset_id')));
     $harmoni->history->goBack("concerto/asset/delete-return");
 }
Example #12
0
 /**
  * Create a new file asset
  * 
  * @return object Asset
  * @access public
  * @since 1/26/07
  */
 function createFileAsset()
 {
     $contentAsset = $this->getContentAsset();
     $asset = MediaAsset::createForContentAsset($contentAsset);
     if (!($displayName = RequestContext::value('displayName'))) {
         $displayName = $_FILES['media_file']['name'];
     }
     if (!($description = RequestContext::value('description'))) {
         $description = '';
     }
     // Check the quota
     $slot = $this->getSlot();
     if ($this->getQuotaUsed() + $_FILES['media_file']['size'] > $slot->getMediaQuota()->value()) {
         throw new Exception("Cannot add File, {$displayName}, quota of " . $slot->getMediaQuota()->asString() . " exceeded.");
     }
     // Create the asset
     $asset->updateDisplayName($displayName);
     $asset->updateDescription($description);
     try {
         $this->addFileRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     try {
         $this->addDublinCoreRecord($asset);
     } catch (Exception $e) {
         HarmoniErrorHandler::logException($e, 'Segue');
         $this->nonFatalError($e->getMessage(), get_class($e));
     }
     // Log the success or 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", "Event_Notice", "Normal events.");
         $item = new AgentNodeEntryItem("Media Library", "File uploaded with id '" . $asset->getId()->getIdString() . "' and filename '" . $_FILES['media_file']['name'] . "'");
         $item->addNodeId($asset->getId());
         $item->addNodeId($contentAsset->getId());
         $idManager = Services::getService("Id");
         $director = AssetSiteDirector::forAsset($contentAsset);
         $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
         $item->addNodeId($idManager->getId($site->getId()));
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     return $asset;
 }
 /**
  * Log an event. Plugins should log events that involve data modification
  * with type 'Event_Notice' and events that involve errors with type 'Error'
  * 
  * @param string $category
  * @param string $description
  * @param optional string $type
  * @return void
  * @access public
  * @since 3/6/06
  */
 public final function logEvent($category, $description, $type = 'Event_Notice')
 {
     ArgumentValidator::validate($category, StringValidatorRule::getRule());
     ArgumentValidator::validate($description, StringValidatorRule::getRule());
     ArgumentValidator::validate($type, ChoiceValidatorRule::getRule('Event_Notice', 'Error'));
     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", $type, "Normal events.");
         $item = new AgentNodeEntryItem($category, $description);
         $item->addNodeId($this->_asset->getId());
         // Get the site Id (Note: this creates a circular dependancy between
         // the plugins package and the SiteDisplay Package.
         try {
             $idManager = Services::getService("Id");
             $director = SiteDispatcher::getSiteDirector();
             $relatedComponent = $this->getRelatedSiteComponent();
             $rootSiteComponent = $director->getRootSiteComponent($relatedComponent->getId());
             $item->addNodeId($idManager->getId($rootSiteComponent->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         } catch (OperationFailedException $e) {
         }
     }
 }
Example #14
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 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // If all properties validate then go through the steps nessisary to
     // save the data.
     if ($wizard->validate()) {
         $properties = $wizard->getAllValues();
         // Create the repository and get its id.
         $repositoryManager = Services::getService("Repository");
         $type = new HarmoniType($properties['type']['type_domain'], $properties['type']['type_authority'], $properties['type']['type_keyword'], $properties['type']['type_description']);
         $repository = $repositoryManager->createRepository($properties['namedesc']['display_name'], $properties['namedesc']['description'], $type);
         $this->repositoryId = $repository->getId();
         // Add the File Record Structure Id as a default Schema
         $setManager = Services::getService("Sets");
         $idManager = Services::getService("Id");
         $set = $setManager->getPersistentSet($this->repositoryId);
         $set->addItem($idManager->getId('FILE'));
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $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 Node", "Repository added");
             $item->addNodeId($repository->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * 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 4/28/05
  */
 function saveWizard($cacheName)
 {
     // 		$asset =$this->getAsset();
     $wizard = $this->getWizard($cacheName);
     $results = $wizard->getAllValues();
     $initialState = $wizard->initialState;
     // 		print "<hr><div style='background-color: #afa;'>";
     // 		printpre($results);
     // 		printpre($initialState);
     // 		print "</div>";
     // Go through all of the assets and update all of the values if they have
     // changed.
     $idManager = Services::getService("Id");
     $repository = $this->getRepository();
     if (!$repository) {
         throw new Exception("Repository not found");
     }
     // Records
     $repositoryId = $this->getRepositoryId();
     // Get the set of RecordStructures so that we can print them in order.
     $setManager = Services::getService("Sets");
     $recStructSet = $setManager->getPersistentSet($repositoryId);
     $authZMan = Services::getService("AuthZ");
     $idManager = Services::getService("Id");
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $item = new AgentNodeEntryItem("Modify Node", "Asset[s] modified");
     }
     $status = new StatusStars(_("Saving Assets"));
     $status->initializeStatistics(count($this->_assets));
     foreach (array_keys($this->_assets) as $key) {
         $asset = $this->_assets[$key];
         try {
             $isAuthorized = $authZMan->isUserAuthorized($idManager->getId("edu.middlebury.authorization.modify"), $asset->getId());
         } catch (UnknownIdException $e) {
             $isAuthorized = true;
         }
         if ($isAuthorized) {
             // 				printpre("<hr>".$asset->getDisplayName());
             if (isset($results['assetproperties'])) {
                 $this->updateAssetProperties($results['assetproperties'], $asset);
             }
             if (isset($results['contentstep']['content'])) {
                 $this->updateAssetContent($results['contentstep']['content'], $asset);
             }
             if (isset($results['filestep'])) {
                 $this->updateFileRecords($results['filestep']['files'], $initialState, $asset);
             }
             if (isset($results['remotefilestep'])) {
                 $this->updateFileRecords($results['remotefilestep']['files'], $initialState, $asset, 'REMOTE_FILE');
             }
             // First, lets go through the info structures listed in the set and print out
             // the info records for those structures in order.
             $recStructSet->reset();
             while ($recStructSet->hasNext()) {
                 $recStructId = $recStructSet->next();
                 if (in_array($recStructId->getIdString(), $this->_recStructsToIgnore)) {
                     continue;
                 }
                 if ($this->hasChangedParts($results, $initialState, $recStructId)) {
                     $this->updateAssetRecords($results, $initialState, $recStructId, $asset);
                     // Update the structured-metadata generated tags for this asset
                     $this->updateAssetTags($asset->getId());
                 }
             }
             if (isset($item)) {
                 $item->addNodeId($asset->getId());
             }
         }
         if (isset($results['parentstep']) && $results['parentstep'] != $initialState['parentstep']) {
             if (is_array($results['parentstep']['parent'])) {
                 if ($results['parentstep']['parent']['checked']) {
                     $this->updateAssetParent($results['parentstep']['parent']['value'], $asset);
                 }
             } else {
                 $this->updateAssetParent($results['parentstep']['parent'], $asset);
             }
         }
         $status->updateStatistics();
     }
     if (isset($log) && isset($item)) {
         $item->addNodeId($repository->getId());
         $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.");
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     // 		printpre($results);
     // 		exit;
     return TRUE;
 }
Example #16
0
 /**
  * Execute
  * 
  * @return mixed
  * @access public
  * @since 2/4/08
  */
 public function buildContent()
 {
     try {
         $status = new StatusStars(_("Preparing Site Import"));
         $status->initializeStatistics(4);
         $destPath = DATAPORT_TMP_DIR . "/Segue1Conversion-" . $this->getDestSlotName();
         mkdir($destPath);
         $destFilePath = $destPath . '/media';
         mkdir($destFilePath);
         $status->updateStatistics();
         // Download and convert the site
         $doc = $this->convertFrom1To2($destFilePath, 'media');
         // 			printpre(htmlentities($doc->saveXMLWithWhitespace()));
         // 			throw new Exception('test');
         $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-site.xsd");
         $status->updateStatistics();
         // Debug output
         // 			$outputDoc2 = new Harmoni_DOMDocument;
         // 			$outputDoc2->loadXML($doc->saveXMLWithWhitespace());
         // 			printpre(htmlentities($outputDoc2->saveXML()));
         // 			throw new Exception('test');
         // Add the user as the owner
         $authN = Services::getService("AuthN");
         $slotMgr = SlotManager::instance();
         $slot = $slotMgr->getSlotByShortname($this->getDestSlotName());
         $slot->addOwner($authN->getFirstUserId());
         // Make the slot personal if it matches the personal naming scheme.
         $userName = PersonalSlot::getPersonalShortname($authN->getFirstUserId());
         if ($slot->getType() != Slot::personal && preg_match('/^' . $userName . '(-.+)?$/', $this->getDestSlotName())) {
             $slot = $slotMgr->convertSlotToType($slot, Slot::personal);
         }
         $status->updateStatistics();
         // Import the converted site
         $director = SiteDispatcher::getSiteDirector();
         $importer = new Segue1MappingImportSiteVisitor($doc, $destPath, $director);
         $status->updateStatistics();
         $importer->enableStatusOutput();
         $importer->makeUserSiteAdministrator();
         $importer->enableRoleImport();
         $importer->setOrigenSlotname($this->getSourceSlotName());
         $importer->setDestinationSlotname($this->getDestSlotName());
         $site = $importer->importAtSlot($this->getDestSlotName());
         // Set the media quota if it is bigger than our default
         $quota = $importer->getMediaQuota();
         if ($quota > $slot->getMediaQuota()->value()) {
             $slot->setMediaQuota(ByteSize::withValue($quota));
         }
         // Delete the output directory
         try {
             if (file_exists($destPath)) {
                 $this->deleteRecursive($destPath);
             }
         } catch (Exception $deleteException) {
             print "\n<div>\n\t";
             print $deleteException->getMessage();
             print "\n</div>";
         }
         /*********************************************************
          * 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, '" . $this->getDestSlotName() . "', from Segue 1 placeholder, '" . $this->getSourceSlotName() . "'.");
             $item->addNodeId($site->getQualifierId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $harmoni = Harmoni::instance();
         RequestContext::sendTo($harmoni->request->quickURL('dataport', 'choose_site'));
     } catch (Exception $importException) {
         // Delete the output directory
         try {
             if (file_exists($destPath)) {
                 $this->deleteRecursive($destPath);
             }
         } catch (Exception $deleteException) {
             print "\n<div>\n\t";
             print $deleteException->getMessage();
             print "\n</div>";
         }
         /*********************************************************
          * 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, '" . $this->getDestSlotName() . "', from Segue 1 placeholder, '" . $this->getSourceSlotName() . "'.");
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         throw $importException;
     }
 }
 /**
  * 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 5/9/07
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // If all properties validate then go through the steps nessisary to
     // save the data.
     if ($wizard->validate()) {
         $properties = $wizard->getAllValues();
         if (!$this->saveTitleStep($properties['namedesc'])) {
             return FALSE;
         }
         if (isset($properties['permissions'])) {
             if (!$this->savePermissionsStep($properties['permissions'])) {
                 return FALSE;
             }
         }
         if (!$this->saveDisplayOptionsStep($properties['display'])) {
             return FALSE;
         }
         if (isset($properties['status'])) {
             if (!$this->saveStatusStep($properties['status'])) {
                 return FALSE;
             }
         }
         /*********************************************************
          * Log the event
          *********************************************************/
         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.");
             $siteComponent = $this->getSiteComponent();
             $item = new AgentNodeEntryItem("Component Modified", $siteComponent->getComponentClass() . " modified.");
             $item->addNodeId($siteComponent->getQualifierId());
             $site = $siteComponent->getDirector()->getRootSiteComponent($siteComponent->getId());
             if (!$siteComponent->getQualifierId()->isEqual($site->getQualifierId())) {
                 $item->addNodeId($site->getQualifierId());
             }
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
Example #18
0
 /**
  * Process the changes and build the output
  * 
  * @return void
  * @access public
  * @since 1/26/07
  */
 public function buildContent()
 {
     try {
         ob_start();
         $idManager = Services::getService("Id");
         $fileAsset = $this->getFileAsset();
         // Update the files
         $oldFilename = null;
         $newFilename = null;
         foreach (array_keys($_FILES) as $fieldName) {
             if (preg_match('/^file___(.+)$/', $fieldName, $matches)) {
                 $fileRecord = $fileAsset->getRecord($idManager->getId($matches[1]));
                 $filenameParts = $fileRecord->getPartsByPartStructure($idManager->getId("FILE_NAME"));
                 $oldFilename = $filenameParts->next()->getValue();
                 $newFilename = $_FILES[$fieldName]['name'];
                 $this->updateFileRecord($fileAsset, $fileRecord, $fieldName);
             } else {
                 if ($fieldName == 'media_file') {
                     $oldFilename = null;
                     $newFilename = $_FILES[$fieldName]['name'];
                     $this->addFileRecord($fileAsset);
                 }
             }
         }
         // Update the displayname
         //
         // If the displayname in the form is the old filename, update it to the
         // new filename
         if (RequestContext::value('displayName') && RequestContext::value('displayName') == $oldFilename && $newFilename) {
             $fileAsset->updateDisplayName($newFilename);
         } else {
             if (RequestContext::value('displayName') && RequestContext::value('displayName') != $fileAsset->getDisplayName()) {
                 $fileAsset->updateDisplayName(HtmlString::getSafeHtml(RequestContext::value('displayName')));
             }
         }
         // Update the description if needed.
         if (!RequestContext::value('description')) {
             $fileAsset->updateDescription('');
         } else {
             if (RequestContext::value('description') != $fileAsset->getDescription()) {
                 $fileAsset->updateDescription(HtmlString::getSafeHtml(RequestContext::value('description')));
             }
         }
         // Update the other metadata.
         $dublinCoreRecords = $fileAsset->getRecordsByRecordStructure($idManager->getId('dc'));
         if ($dublinCoreRecords->hasNext()) {
             $this->updateDublinCoreRecord($fileAsset, $dublinCoreRecords->next());
         } else {
             $this->addDublinCoreRecord($fileAsset);
         }
         // Log the success or 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", "Event_Notice", "Normal events.");
             $message = "File updated with id '" . $fileAsset->getId()->getIdString() . "'";
             if (isset($newFilename)) {
                 $message .= " and new filename '" . $newFilename . "'";
             }
             $item = new AgentNodeEntryItem("Media Library", $message);
             $item->addNodeId($fileAsset->getId());
             $item->addNodeId($this->getContentAsset()->getId());
             $contentAsset = $this->getContentAsset();
             $idManager = Services::getService("Id");
             $director = AssetSiteDirector::forAsset($contentAsset);
             $site = $director->getRootSiteComponent($contentAsset->getId()->getIdString());
             $item->addNodeId($idManager->getId($site->getId()));
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         // 		printpre($_FILES);
         if ($error = ob_get_clean()) {
             $this->error($error);
         }
         $this->start();
         // 		print "\n<![CDATA[";
         // 		print_r($_REQUEST);
         // 		print_r($_FILES);
         // 		print "\n]]>";
         print $this->getAssetXml($fileAsset);
         print $this->getQuota();
         $this->end();
     } catch (Exception $e) {
         $this->error($e->getMessage(), get_class($e));
     }
 }
 /**
  * Log an error or exception with the Logging OSID implemenation
  * 
  * @param string $type The type of error or exception that occurred
  * @param string $message A message.
  * @param array $backtrace
  * @param optional string $logName The name of the log to write to.
  * @param optional string $category A category for the error or exception.
  * @return void
  * @access public
  * @since 10/10/07
  * @static
  */
 public static function logMessage($type, $message, array $backtrace, $logName = 'Harmoni', $category = null)
 {
     /*********************************************************
      * Log the error in the default system log if the log_errors
      * directive is on.
      *********************************************************/
     if (ini_get('log_errors') === true || ini_get('log_errors') === 'On' || ini_get('log_errors') === '1') {
         error_log("PHP " . $type . ":  " . strip_tags($message));
     }
     /*********************************************************
      * Log the error using the Logging OSID if available.
      *********************************************************/
     // If we have an error in the error handler or the logging system,
     // don't infinitely loop trying to log the error of the error....
     $testBacktrace = debug_backtrace();
     for ($i = 1; $i < count($testBacktrace); $i++) {
         if (isset($testBacktrace[$i]['function']) && strtolower($testBacktrace[$i]['function']) == 'logMessage') {
             return;
         }
     }
     if (class_exists('Services') && Services::serviceRunning("Logging")) {
         $logName = preg_replace('/[^a-z0-9_\\s-.]/i', '', $logName);
         try {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting($logName);
             $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", strip_tags($type), "Events involving critical system errors.");
             $item = new AgentNodeEntryItem(strip_tags($category), HtmlString::getSafeHtml($message));
             $item->setBacktrace($backtrace);
             if (isset($_SERVER['REQUEST_URI'])) {
                 $item->addTextToBactrace("\n<div><strong>REQUEST_URI: </strong>" . $_SERVER['REQUEST_URI'] . "</div>");
             }
             if (isset($_SERVER['HTTP_REFERER'])) {
                 $item->addTextToBactrace("\n<div><strong>HTTP_REFERER: </strong>" . htmlspecialchars($_SERVER['HTTP_REFERER']) . "</div>");
             }
             if (isset($_SERVER['HTTP_USER_AGENT'])) {
                 $item->addTextToBactrace("\n<div><strong>HTTP_USER_AGENT: </strong><pre>" . htmlspecialchars(print_r($_SERVER['HTTP_USER_AGENT'], true)) . "</pre></div>");
             }
             // Log IP addresses of unauthenticated users for help in tracing
             // anonymous intrusion attempts. Currently not logging IP addresses
             // of logged-in users for privacy, even though visitor accounts
             // mean that logged-in users may be just as dangerous as anonymous ones.
             if (Services::serviceRunning("AuthN")) {
                 $authN = Services::getService("AuthN");
                 if (!$authN->isUserAuthenticatedWithAnyType()) {
                     if (isset($_SERVER['REMOTE_ADDR'])) {
                         $item->addTextToBactrace("\n<div><strong>REMOTE_ADDR: </strong><pre>" . htmlspecialchars($_SERVER['REMOTE_ADDR']) . "</pre></div>");
                     }
                     if (isset($_SERVER['REMOTE_HOST'])) {
                         $item->addTextToBactrace("\n<div><strong>REMOTE_HOST: </strong><pre>" . htmlspecialchars($_SERVER['REMOTE_HOST']) . "</pre></div>");
                     }
                 }
             }
             $item->addTextToBactrace("\n<div><strong>GET: </strong><pre>" . htmlspecialchars(print_r(self::stripPrivate($_GET), true)) . "</pre></div>");
             $item->addTextToBactrace("\n<div><strong>POST: </strong><pre>" . htmlspecialchars(print_r(self::stripPrivate($_POST), true)) . "</pre></div>");
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         } catch (Exception $e) {
             // Just continue if we can't log the exception.
         }
     }
 }
Example #20
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     if (RequestContext::value('collection_id')) {
         $collectionId = $idManager->getId(RequestContext::value('collection_id'));
         $repository = $repositoryManager->getRepository($collectionId);
     } else {
         if (RequestContext::value('asset_id')) {
             $parentAssetId = $idManager->getId(RequestContext::value('asset_id'));
             $parentAsset = $repositoryManager->getAsset($parentAssetId);
             $repository = $parentAsset->getRepository();
         } else {
             if (count($this->getAssetIds())) {
                 $assetIds = $this->getAssetIds();
                 $firstAsset = $repositoryManager->getAsset(current($assetIds));
                 $repository = $firstAsset->getRepository();
             }
         }
     }
     // Log the action
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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.");
     }
     $itemsToDelete = array();
     $assetIds = $this->getAssetIds();
     $status = new StatusStars(_("Deleting Assets"));
     $status->initializeStatistics(count($assetIds));
     foreach ($assetIds as $id) {
         $asset = $repository->getAsset($id);
         // Record the Tagged item to delete.
         $itemsToDelete[] = TaggedItem::forId($id, 'concerto');
         if (isset($log)) {
             $item = new AgentNodeEntryItem("Delete Node", "Asset deleted:\n<br/>&nbsp; &nbsp; &nbsp;" . $asset->getDisplayName());
             $item->addNodeId($asset->getId());
             $item->addNodeId($repository->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $repository->deleteAsset($id);
         $status->updateStatistics();
     }
     // Remove this asset from the tagging manager
     $tagManager = Services::getService('Tagging');
     $tagManager->deleteItems($itemsToDelete, 'concerto');
     $harmoni->history->goBack("concerto/asset/delete-return");
 }
 /**
  * Sets the node's internal information
  * 
  * @access public
  * @since 10/6/05
  */
 function getNodeInfo()
 {
     $dbHandler = Services::getService("DBHandler");
     // 		$dbIndexConcerto =$dbHandler->addDatabase(new
     // 			MySQLDatabase("localhost", "whitey_concerto", "test", "test"));
     $query = new SelectQuery();
     $query->addTable("xml_id_matrix");
     $query->addColumn("conc_id");
     $query->addColumn("xml_id");
     $id = $this->_node->getAttribute("xml:id");
     $query->addWhere("xml_id = '" . addslashes($id) . "'");
     //$dbHandler->connect($dbIndexConcerto);
     $results = $dbHandler->query($query, IMPORTER_CONNECTION);
     if ($results->getNumberOfRows() == 1) {
         $result = $results->next();
         $idManager = Services::getService("Id");
         $this->_info['recordStructureId'] = $idManager->getId($result['conc_id']);
     } else {
         $this->addError("Bad XML IDREF: " . $id);
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Harmoni");
             $formatType = new Type("logging", "edu.middlebury", "AgentsAndNonNodes", "A format in which the acting Agent[s] and the target nodes affected are specified.");
             $priorityType = new Type("logging", "edu.middlebury", "Error", "Events involving critical system errors.");
             $item = new AgentNodeEntryItem("RecordImport Error", "Bad XML IDREF: " . htmlspecialchars($id));
             $item->addNodeId($this->_parent->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
     }
     $results->free();
 }
Example #22
0
 /**
  * Process changes to the site components. This is the method that the various
  * actions that modify the site should override.
  * 
  * @param object SiteDirector $director
  * @return void
  * @access public
  * @since 4/14/06
  */
 function processChanges(SiteDirector $director)
 {
     // Get the target organizer's Id & Cell
     $targetId = RequestContext::value('destination');
     preg_match("/^(.+)_cell:(.+)\$/", $targetId, $matches);
     $targetOrgId = $matches[1];
     $targetCell = $matches[2];
     $component = $director->getSiteComponentById(RequestContext::value('component'));
     // Store the existing Role of the user.
     $roleMgr = SegueRoleManager::instance();
     $oldRole = $roleMgr->getUsersRole($component->getQualifierId(), true);
     // If we are moving a navOrganizer, update the target of the menu
     if (preg_match('/^.*NavOrganizerSiteComponent$/i', get_class($component))) {
         $menuOrganizer = $component->getMenuOrganizer();
         $menuOrganizer->updateTargetId(RequestContext::value('destination'));
         return;
     } else {
         if (preg_match('/^.*MenuOrganizerSiteComponent$/i', get_class($component))) {
             $newOrganizer = $director->getSiteComponentById($targetOrgId);
             $currentComponentInCell = $newOrganizer->getSubcomponentForCell($targetCell);
             if (preg_match('/^.*NavBlockSiteComponent$/i', get_class($currentComponentInCell))) {
                 $currentComponentInCell->makeNested($component);
                 return;
             }
         }
     }
     // 		printpre("targetId: ".$targetId);
     // 		printpre("targetOrgId: ".$targetOrgId);
     // 		printpre("targetCell: ".$targetCell);
     // 		printpre("componentId: ".RequestContext::value('component'));
     $filledTargetIds = $director->getFilledTargetIds($targetOrgId);
     $newOrganizer = $director->getSiteComponentById($targetOrgId);
     $oldCellId = $newOrganizer->putSubcomponentInCell($component, $targetCell);
     // 		printpre("oldCellId: ".$oldCellId);
     // If the targetCell was a target for any menus, change their targets
     // to the cell just vacated by the component we swapped with
     if (in_array($targetId, $filledTargetIds)) {
         $menuIds = array_keys($filledTargetIds, $targetId);
         foreach ($menuIds as $menuId) {
             $menuOrganizer = $director->getSiteComponentById($menuId);
             // 				printpre(get_class($menuOrganizer));
             $menuOrganizer->updateTargetId($oldCellId);
         }
     }
     // Update the new role if needed
     $newRole = $roleMgr->getUsersRole($component->getQualifierId(), true);
     if ($newRole->isLessThan($oldRole)) {
         $oldRole->applyToUser($component->getQualifierId(), true);
     }
     /*********************************************************
      * Log the event
      *********************************************************/
     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("Component Moved", $component->getComponentClass() . " moved.");
         $item->addNodeId($component->getQualifierId());
         $site = $component->getDirector()->getRootSiteComponent($component->getId());
         if (!$component->getQualifierId()->isEqual($site->getQualifierId())) {
             $item->addNodeId($site->getQualifierId());
         }
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     // 		exit;
 }
Example #23
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 4/28/05
  */
 function saveWizard($cacheName)
 {
     $wizard = $this->getWizard($cacheName);
     // If all properties validate then go through the steps nessisary to
     // save the data.
     if ($wizard->validate()) {
         $properties = $wizard->getAllValues();
         $repository = $this->getRepository();
         // Create the info Structure
         $recordStructure = $repository->createRecordStructure($properties['namedesc']['display_name'], $properties['namedesc']['description'], $properties['namedesc']['format'], $properties['namedesc']['display_name']);
         Debug::printAll();
         $recordStructureId = $recordStructure->getId();
         // Create a set for the RecordStructure
         $setManager = Services::getService("Sets");
         $set = $setManager->getPersistentSet($recordStructureId);
         // Store up the positions for later setting after all of the ids have
         // been added to the set and we can do checking to make sure that
         // the specified positions are valid.
         $positions = array();
         // Create the PartStructures
         $partStructureProperties = $properties['elementstep']['elements'];
         foreach (array_keys($partStructureProperties) as $index) {
             $type = HarmoniType::fromString(urldecode($partStructureProperties[$index]['type']), " :: ");
             $partStructure = $recordStructure->createPartStructure($partStructureProperties[$index]['display_name'], $partStructureProperties[$index]['description'], $type, $partStructureProperties[$index]['mandatory'] ? TRUE : FALSE, $partStructureProperties[$index]['repeatable'] ? TRUE : FALSE, FALSE);
             // Authoritative values
             $valuesString = trim($partStructureProperties[$index]['authoritative_values']);
             if ($valuesString) {
                 $authoritativeStrings = explode("\n", $valuesString);
                 array_walk($authoritativeStrings, "removeExcessWhitespace");
                 // Remove and missing values
                 $authoritativeValues = $partStructure->getAuthoritativeValues();
                 while ($authoritativeValues->hasNext()) {
                     $value = $authoritativeValues->next();
                     if (!in_array($value->asString(), $authoritativeStrings)) {
                         $partStructure->removeAuthoritativeValue($value);
                     }
                 }
                 // Add new values
                 foreach ($authoritativeStrings as $valueString) {
                     if ($valueString) {
                         $partStructure->addAuthoritativeValueAsString($valueString);
                     }
                 }
             }
             $partStructureId = $partStructure->getId();
             // Add the PartStructureId to the set
             if (!$set->isInSet($partStructureId)) {
                 $set->addItem($partStructureId);
             }
         }
         // Log the success or failure
         if (Services::serviceRunning("Logging")) {
             $loggingManager = Services::getService("Logging");
             $log = $loggingManager->getLogForWriting("Concerto");
             $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("Modify Node", "RecordStructure created:\n<br/>&nbsp; &nbsp; &nbsp; " . $recordStructure->getDisplayName());
             $item->addNodeId($repository->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         return TRUE;
     } else {
         return FALSE;
     }
 }
 /**
  * builds asset in repository from assetinfo and records from recordlist
  *
  * @param array assetInfo
  * @param array recordList
  * @return asset or false on fatal error
  * @access public
  * @since 7/18/05
  *
  */
 function buildAsset($info)
 {
     $assetInfo = $info['assetInfo'];
     $recordList = $info['recordList'];
     $childAssetList = $info['childAssetList'];
     $buildOrderedSet = $info['buildOrderedSet'];
     $idManager = Services::getService("Id");
     $mime = Services::getService("MIME");
     $FILE_ID = $idManager->getId("FILE");
     $FILE_DATA_ID = $idManager->getId("FILE_DATA");
     $FILE_NAME_ID = $idManager->getId("FILE_NAME");
     $MIME_TYPE_ID = $idManager->getId("MIME_TYPE");
     $THUMBNAIL_DATA_ID = $idManager->getId("THUMBNAIL_DATA");
     $THUMBNAIL_MIME_TYPE_ID = $idManager->getId("THUMBNAIL_MIME_TYPE");
     $asset = $this->_destinationRepository->createAsset($assetInfo['displayName'], $assetInfo['description'], $assetInfo['type']);
     $assetId = $asset->getId();
     // log creation
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Harmoni");
         $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 Node", "Asset: " . $assetId->getIdString() . " created.");
         $item->addNodeId($assetId);
         $item->addNodeId($this->_destinationRepository->getId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $this->addGoodAssetId($asset->getId());
     RecordManager::setCacheMode(false);
     if (is_array($recordList)) {
         foreach ($recordList as $entry) {
             $assetRecord = $asset->createRecord($entry['structureId']);
             $j = 0;
             // 				printpre("creating record for: "); printpre($entry['structureId']);
             foreach ($entry['partStructureIds'] as $id) {
                 if (!$entry['structureId']->isEqual($FILE_ID)) {
                     if (isset($entry['parts'][$j])) {
                         if (is_array($entry['parts'][$j])) {
                             for ($k = 0; $k < count($entry['parts'][$j]); $k++) {
                                 $assetRecord->createPart($id, $entry['parts'][$j][$k]);
                             }
                         } else {
                             $assetRecord->createPart($id, $entry['parts'][$j]);
                         }
                     }
                     $j++;
                 } else {
                     if ($entry['structureId']->isEqual($FILE_ID)) {
                         $filename = basename(trim($entry['parts'][0]));
                         $mimetype = $mime->getMIMETypeForFileName($filename);
                         $assetRecord->createPart($FILE_DATA_ID, file_get_contents($this->_srcDir . $filename));
                         $assetRecord->createPart($FILE_NAME_ID, basename($filename));
                         $assetRecord->createPart($MIME_TYPE_ID, $mimetype);
                         $imageProcessor = Services::getService("ImageProcessor");
                         if (isset($entry['parts'][1]) && $entry['parts'][1] != "") {
                             $assetRecord->createPart($THUMBNAIL_DATA_ID, file_get_contents($this->_srcDir . $entry['parts'][1]));
                         } else {
                             if ($imageProcessor->isFormatSupported($mimetype)) {
                                 try {
                                     $thumbData = $imageProcessor->generateThumbnailData($mimetype, file_get_contents($this->_srcDir . $filename));
                                 } catch (ImageProcessingFailedException $e) {
                                     $thumbData = null;
                                 }
                                 if ($thumbData) {
                                     $assetRecord->createPart($THUMBNAIL_DATA_ID, $thumbData);
                                     $assetRecord->createPart($THUMBNAIL_MIME_TYPE_ID, $imageProcessor->getThumbnailFormat());
                                 }
                             }
                         }
                         break;
                     }
                 }
             }
         }
     }
     if (!is_null($childAssetList)) {
         $stop = $this->assetBuildingIteration(new HarmoniIterator($childAssetList), $asset, $buildOrderedSet);
         if (!$stop) {
             return $stop;
         }
         // false
     }
     return $asset;
 }
 /**
  * Looks for discrepencies between imported data and current data
  * 
  * @access public
  * @since 9/12/05
  */
 function update()
 {
     $modified = false;
     if (isset($this->_info['name']) && !is_null($this->_info['name']) && $this->_info['name'] != $this->_object->getDisplayName()) {
         $modified = true;
         $this->_object->updateDisplayName($this->_info['name']);
     }
     if (isset($this->_info['description']) && !is_null($this->_info['description']) && $this->_info['description'] != $this->_object->getDescription()) {
         $modified = true;
         $this->_object->updateDescription($this->_info['description']);
     }
     if (Services::serviceRunning("Logging") && $modified) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Harmoni");
         $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("Modified Node", "Asset: " . htmlspecialchars($this->_myId->getIdString()) . " modified.");
         $item->addNodeId($this->_myId);
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     // 		if (isset($this->_info['effectivedate']) &&
     // 			(DateAndTime::fromString($this->_info['effectivedate']) !=
     // 			$this->_object->getEffectiveDate()))
     // 			$this->_object->updateEffectiveDate(DateAndTime::fromString(
     // 				$this->_info['effectivedate']));
     // 		if (isset($this->_info['effectivedate']) &&
     // 			(DateAndTime::fromString($this->_info['expirationdate']) !=
     // 			$this->_object->getExpirationDate()))
     // 			$this->_object->updateExpirationDate(DateAndTime::fromString(
     // 				$this->_info['expirationdate']));
 }
Example #26
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $repositoryManager = Services::getService("Repository");
     $repositoryId = $idManager->getId(RequestContext::value('collection_id'));
     $repository = $repositoryManager->getRepository($repositoryId);
     $displayName = $repository->getDisplayName();
     // Delete all of the tags for the assets in the repository
     $itemsToDelete = array();
     $assets = $repository->getAssets();
     while ($assets->hasNext()) {
         $asset = $assets->next();
         $itemsToDelete[] = TaggedItem::forId($asset->getId(), 'concerto');
     }
     $tagManager = Services::getService('Tagging');
     $tagManager->deleteItems($itemsToDelete, 'concerto');
     $repositoryManager->deleteRepository($idManager->getId(RequestContext::value('collection_id')));
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Delete Node", "Repository deleted:\n<br/>&nbsp; &nbsp; &nbsp;" . $displayName);
         $item->addNodeId($repositoryId);
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     RequestContext::locationHeader($harmoni->request->quickURL("collections", "namebrowse"));
 }
Example #27
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function buildContent()
 {
     $actionRows = $this->getActionRows();
     $harmoni = Harmoni::instance();
     $idManager = Services::getService("Id");
     $recordStructureId = $this->getRecordStructureId();
     $recordStructure = $this->getRecordStructure();
     $recordStructureIdString = $recordStructureId->getIdString();
     $repositoryId = $this->getRepositoryId();
     $repository = $this->getRepository();
     // Log the action
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Delete RecordStructure", "RecordStructure deleted:\n<br/>&nbsp; &nbsp; &nbsp;" . $recordStructure->getDisplayName());
         $item->addNodeId($recordStructureId);
         $item->addNodeId($repositoryId);
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $setManager = Services::getService("Sets");
     $set = $setManager->getPersistentSet($repositoryId);
     if ($set->isInSet($recordStructureId)) {
         $set->removeItem($recordStructureId);
     }
     $repository->deleteRecordStructure($recordStructureId, new StatusStars(_("Deleting Schema and associated Records")));
     RequestContext::sendTo($harmoni->history->getReturnUrl("concerto/schema/delete-return/" . $recordStructureIdString));
 }
Example #28
0
 /**
  * Set the migration status of this slot
  * 
  * @param string $status
  * @param string $url
  * @return null
  */
 public function setMigrationStatus($status, $url = '')
 {
     // Validate the status and URL, then save.
     $validStatus = array('incomplete', 'archived', 'migrated', 'unneeded');
     if (!in_array($status, $validStatus)) {
         throw new InvalidArgumentException("Invalid status. Must be one of: " . implode(', ', $validStatus));
     }
     if ($status == 'migrated' && strlen($url)) {
         $url = filter_var($url, FILTER_VALIDATE_URL);
         if (!is_string($url) || !strlen($url)) {
             throw new InvalidArgumentException("Invalid URL.");
         }
     } else {
         $url = '';
     }
     $dbc = Services::getService('DBHandler');
     $authN = Services::getService('AuthN');
     $query = new InsertQuery();
     $query->setTable('segue_slot_migration_status');
     $query->addValue('shortname', $this->getShortname());
     $query->addValue('status', $status);
     $query->addValue('redirect_url', $url);
     $query->addValue('user_id', $authN->getFirstUserId()->getIdString());
     try {
         $result = $dbc->query($query, IMPORTER_CONNECTION);
     } catch (DuplicateKeyDatabaseException $e) {
         $query = new UpdateQuery();
         $query->setTable('segue_slot_migration_status');
         $query->addValue('status', $status);
         $query->addValue('redirect_url', $url);
         $query->addValue('user_id', $authN->getFirstUserId()->getIdString());
         $query->addWhereEqual('shortname', $this->getShortname());
         $result = $dbc->query($query, IMPORTER_CONNECTION);
     }
     /*********************************************************
      * 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.");
         $message = "'" . $this->getShortname() . "' marked as " . $status;
         if ($url) {
             $message .= " to " . $url;
         }
         $item = new AgentNodeEntryItem("Set Slot Status", $message);
         if ($this->siteExists()) {
             $item->addNodeId($this->getSiteId());
         }
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
 }
 /**
  * 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 4/28/05
  */
 function saveWizard($cacheName)
 {
     $harmoni = Harmoni::instance();
     $harmoni->request->startNamespace('modify_exhibition');
     $harmoni->request->passthrough('exhibition_id');
     $wizard = $this->getWizard($cacheName);
     // Make sure we have a valid Repository
     $idManager = Services::getService("Id");
     $authZ = Services::getService("AuthZ");
     $repositoryManager = Services::getService("Repository");
     $exhibitionRepositoryId = $idManager->getId("edu.middlebury.concerto.exhibition_repository");
     $repository = $repositoryManager->getRepository($exhibitionRepositoryId);
     $asset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_id')));
     $properties = $wizard->getAllValues();
     $assetType = new Type("Asset Types", "edu.middlebury.concerto", "Exhibition", "Exhibition Assets are containers for Slideshows.");
     $asset->updateDisplayName($properties['namedescstep']['display_name']);
     $asset->updateDescription($properties['namedescstep']['description']);
     $assetId = $asset->getId();
     $this->_assetId = $assetId;
     // Update the effective/expiration dates
     if ($properties['datestep']['effective_date']) {
         $asset->updateEffectiveDate(DateAndTime::fromString($properties['datestep']['effective_date']));
     }
     if ($properties['datestep']['expiration_date']) {
         $asset->updateExpirationDate(DateAndTime::fromString($properties['datestep']['expiration_date']));
     }
     // Log the success or failure
     if (Services::serviceRunning("Logging")) {
         $loggingManager = Services::getService("Logging");
         $log = $loggingManager->getLogForWriting("Concerto");
         $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("Modify Node", "Exhibition Modified");
         $item->addNodeId($asset->getId());
         $log->appendLogWithTypes($item, $formatType, $priorityType);
     }
     $harmoni->request->endNamespace();
     return TRUE;
 }
Example #30
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 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;
 }