/**
  * Answer a Plugin history comment for an element. Extensions of this
  * class may wish to override this method to modify the comment and/or store
  * the import date/user instead of that listed in the history.
  * 
  * @param object DOMElement $element
  * @return string
  * @access protected
  * @since 1/25/08
  */
 protected function getPluginHistoryComment(DOMElement $element)
 {
     $agentMgr = Services::getService('Agent');
     $origComment = parent::getPluginHistoryComment($element);
     $origAgentId = parent::getPluginHistoryAgentId($element);
     $origAgent = $agentMgr->getAgent($origAgentId);
     $origTstamp = parent::getPluginHistoryTimestamp($element);
     $agent = $agentMgr->getAgent($this->getPluginHistoryAgentId($element));
     $tstamp = $this->getPluginHistoryTimestamp($element);
     // If there is no change in authoriship, just return the original comment.
     if (!$this->addChangedAgentComment($origAgentId, $agent->getId())) {
         return $origComment;
     }
     // Otherwise, note the change.
     $time = $tstamp->asTime();
     $tstampString = $tstamp->ymdString() . " " . $time->string12(false);
     $time = $origTstamp->asTime();
     $origTstampString = $origTstamp->ymdString() . " " . $time->string12(false);
     $additional = _("Imported by %agent% on %tstamp%, marked as being created by %origAgent% on %origTstamp%.");
     $additional = str_replace("%agent%", $agent->getDisplayName(), $additional);
     $additional = str_replace("%tstamp%", $tstampString, $additional);
     $additional = str_replace("%origAgent%", $origAgent->getDisplayName(), $additional);
     $additional = str_replace("%origTstamp%", $origTstampString, $additional);
     return $origComment . " " . $additional;
 }
 /**
  * Create a new Site and import the source data into it.
  * 
  * @return object SiteNavBlockSiteComponent
  * @access public
  * @since 1/22/08
  */
 public function importSite()
 {
     $site = parent::importSite();
     $this->storeSegue1IdMapping();
     return $site;
 }
Example #3
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 #4
0
 /**
  * Copy a component.
  * 
  * @param object SiteComponent
  * @return void
  * @access protected
  * @since 8/4/08
  */
 protected function copyComponent(SiteComponent $siteComponent)
 {
     $authZ = Services::getService("AuthZ");
     $idMgr = Services::getService("Id");
     if (!$authZ->isUserAuthorized($idMgr->getId('edu.middlebury.authorization.modify'), $siteComponent->getQualifierId())) {
         throw new PermissionDeniedException("You are not authorized to copy this node from its original location.");
     }
     try {
         /*********************************************************
          * Export the Component
          *********************************************************/
         $exportDir = DATAPORT_TMP_DIR . "/" . $siteComponent->getId() . "-" . str_replace(':', '_', DateAndTime::now()->asString());
         mkdir($exportDir);
         // Do the export
         $visitor = new DomExportSiteVisitor($exportDir);
         $visitor->enableStatusOutput(_("Exporting from original location."));
         $siteComponent->acceptVisitor($visitor);
         $doc = $visitor->doc;
         // Validate the result
         // 			printpre(htmlentities($doc->saveXMLWithWhitespace()));
         $doc->schemaValidateWithException(MYDIR . "/doc/raw/dtds/segue2-subtree.xsd");
         // 			printpre($this->listDir($exportDir));
         // 			throw new Exception('test');
         /*********************************************************
          * Import the Component
          *********************************************************/
         $importer = new DomImportSiteVisitor($doc, $exportDir, SiteDispatcher::getSiteDirector());
         if (RequestContext::value('copy_permissions') == 'true') {
             $importer->enableRoleImport();
         }
         if (RequestContext::value('copy_discussions') == 'false') {
             $importer->disableCommentImport();
         }
         $importer->enableStatusOutput(_("Importing into new location"));
         $newComponent = $importer->importSubtreeUnderOrganizer($this->getDestinationComponent());
         // Delete the decompressed Archive
         $this->deleteRecursive($exportDir);
         return $newComponent;
     } catch (Exception $e) {
         $this->deleteRecursive($exportDir);
         if (file_exists($exportDir . ".tar.gz")) {
             unlink($exportDir . ".tar.gz");
         }
         throw $e;
     }
 }