Example #1
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 #2
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;
     }
 }