コード例 #1
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);
     }
 }
コード例 #2
0
 /**
  * Iterates through the building of the assets
  * 
  * @return boolean
  * @access public
  * @since 7/20/05
  */
 function assetBuildingIteration($assetIterator, $parent, $buildOrderedSet)
 {
     $setManager = Services::getService("Sets");
     $assetInfoIterator = $this->getAllAssetsInfoIterator($assetIterator);
     $statusStars = new StatusStars(_("Creating Assets"));
     $statusStars->initializeStatistics($assetInfoIterator->count());
     if (!$assetInfoIterator) {
         return $assetInfoIterator;
     }
     // false
     if ($buildOrderedSet) {
         $set = $setManager->getPersistentSet($parent->getId());
     }
     while ($assetInfoIterator->hasNext()) {
         $info = $assetInfoIterator->next();
         $child = $this->buildAsset($info);
         if (!$child) {
             return $child;
         }
         // false
         if (!is_null($parent)) {
             $parent->addAsset($child->getId());
         }
         if ($buildOrderedSet) {
             $set->addItem($child->getId());
         }
         $statusStars->updateStatistics();
     }
     unset($assetInfoIterator);
     $true = true;
     return $true;
 }
コード例 #3
0
ファイル: migration.php プロジェクト: adamfranco/harmoni
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate($dbIndex)
 {
     $prepStatus = new StatusStars("Preparing Migration");
     $prepStatus->initializeStatistics(3);
     // Configure the original Hierarchy and AZ services
     $context = new OsidContext();
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("IdManager", $context, $configuration);
     Services::startManagerAsService("HierarchyManager", $context, $configuration);
     Services::startManagerAsService("AuthorizationManager", $context, $configuration);
     // Agent Manager
     $configuration = new ConfigurationProperties();
     // default agent Flavor is one that can be editted
     $agentFlavor = "HarmoniEditableAgent";
     $agentHierarchyId = "edu.middlebury.authorization.hierarchy";
     $configuration->addProperty('hierarchy_id', $agentHierarchyId);
     $configuration->addProperty('defaultAgentFlavor', $agentFlavor);
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("AgentManager", $context, $configuration);
     // :: Set up PropertyManager ::
     //the property manager operates in the same context as the AgentManager and is more or less an adjunct to it
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("PropertyManager", $context, $configuration);
     // :: Start the AuthenticationManager OSID Impl.
     $configuration = new ConfigurationProperties();
     $tokenCollectors = array(serialize(new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB")) => new FormActionNamePassTokenCollector('does not exist'));
     $configuration->addProperty('token_collectors', $tokenCollectors);
     Services::startManagerAsService("AuthenticationManager", $context, $configuration);
     // :: Start and configure the AuthenticationMethodManager
     $configuration = new ConfigurationProperties();
     // set up a Database Authentication Method
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseAuthNMethod.class.php";
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseMD5UsernamePasswordAuthNTokens.class.php";
     $dbAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
     $dbMethodConfiguration = new ConfigurationProperties();
     $dbMethodConfiguration->addProperty('tokens_class', 'SQLDatabaseMD5UsernamePasswordAuthNTokens');
     $dbMethodConfiguration->addProperty('database_id', $dbIndex);
     $dbMethodConfiguration->addProperty('authentication_table', 'auth_db_user');
     $dbMethodConfiguration->addProperty('username_field', 'username');
     $dbMethodConfiguration->addProperty('password_field', 'password');
     $propertiesFields = array('username' => 'username');
     $dbMethodConfiguration->addProperty('properties_fields', $propertiesFields);
     $dbAuthNMethod = new SQLDatabaseAuthNMethod();
     $dbAuthNMethod->assignConfiguration($dbMethodConfiguration);
     $configuration->addProperty($dbAuthType, $dbAuthNMethod);
     Services::startManagerAsService("AuthNMethodManager", $context, $configuration);
     // :: Agent-Token Mapping Manager ::
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_id', $dbIndex);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("AgentTokenMappingManager", $context, $configuration);
     $prepStatus->updateStatistics();
     $dbc = Services::getService("DatabaseManager");
     try {
         /*********************************************************
          * Check for the old tables. They must exist for us to run
          *********************************************************/
         $azTables = array('az_authorization', 'az_function', 'hierarchy', 'j_node_node', 'node', 'node_ancestry');
         // Check for old tables
         $tables = $dbc->getTableList($dbIndex);
         foreach ($azTables as $table) {
             if (!in_array($table, $tables)) {
                 throw new Exception("Old AZ table, {$table}, is missing. Can not run Update.");
             }
         }
         /*********************************************************
          * Create the new tables
          *********************************************************/
         $type = $dbc->getDatabaseType($dbIndex);
         switch ($type) {
             case MYSQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/MySQL/AuthZ2.sql", $dbIndex);
                 break;
             case POSTGRESQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             case ORACLE:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             default:
                 throw new Exception("Database schemas are not defined for specified database type.");
         }
         /*********************************************************
          * Hierarchy
          *********************************************************/
         $hierarchyMgr1 = Services::getService("Hierarchy");
         if (get_class($hierarchyMgr1) == "AuthZ2_HierarchyManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $hierarchyMgr2 = new AuthZ2_HierarchyManager();
         $azMgr2 = new AuthZ2_AuthorizationManager();
         $azMgr2->setHierarchyManager($hierarchyMgr2);
         $hierarchyMgr2->assignConfiguration($hierarchyMgr1->_configuration);
         /*********************************************************
          * Authorization
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $azMgr2->assignConfiguration($azMgr1->_configuration);
         $prepStatus->updateStatistics();
         /*********************************************************
          * Hierarchies
          *********************************************************/
         $hierarchies = $hierarchyMgr1->getHierarchies();
         $prepStatus->updateStatistics();
         while ($hierarchies->hasNext()) {
             $hierarchy = $hierarchies->next();
             try {
                 $newHierarchy = $hierarchyMgr2->getHierarchy($hierarchy->getId());
             } catch (UnknownIdException $e) {
                 $newHierarchy = $hierarchyMgr2->createHierarchy($hierarchy->getDisplayName(), array(), $hierarchy->getDescription(), $hierarchy->allowsMultipleParents(), $hierarchy->allowsRecursion(), $hierarchy->getId());
             }
             $query = new SelectQuery();
             $query->addTable("node");
             $query->addColumn("COUNT(*)", "num");
             $query->addWhereEqual("fk_hierarchy", $hierarchy->getId()->getIdString());
             $dbc = Services::getService("DatabaseManager");
             $result = $dbc->query($query);
             $this->nodeStatus = new StatusStars("Migrating nodes in the '" . $hierarchy->getDisplayName() . "' Hierarchy.");
             $this->nodeStatus->initializeStatistics($result->field("num"));
             // Add all of the nodes
             $nodes = $hierarchy->getRootNodes();
             while ($nodes->hasNext()) {
                 $this->addNode($newHierarchy, $nodes->next());
             }
         }
         /*********************************************************
          * Authorizations
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         // Add all of the Authorization functions
         $functionTypes = $azMgr1->getFunctionTypes();
         while ($functionTypes->hasNext()) {
             $oldFunctions = $azMgr1->getFunctions($functionTypes->next());
             while ($oldFunctions->hasNext()) {
                 $oldFunction = $oldFunctions->next();
                 // Get or create the function
                 try {
                     $newFunction = $azMgr2->getFunction($oldFunction->getId());
                 } catch (UnknownIdException $e) {
                     $newFunction = $azMgr2->createFunction($oldFunction->getId(), $oldFunction->getReferenceName(), $oldFunction->getDescription(), $oldFunction->getFunctionType(), $oldFunction->getQualifierHierarchyId());
                 }
                 // Get all authorizations for this function.
                 $oldAZs = $azMgr1->getExplicitAZs(null, $oldFunction->getId(), null, false);
                 $status = new StatusStars("Migrating '" . $newFunction->getReferenceName() . "' Authorizations (" . $oldAZs->count() . ")");
                 $status->initializeStatistics($oldAZs->count());
                 while ($oldAZs->hasNext()) {
                     $oldAZ = $oldAZs->next();
                     $status->updateStatistics();
                     try {
                         $oldQualifier = $oldAZ->getQualifier();
                     } catch (UnknownIdException $e) {
                         // continue if the qualifier no longer exists.
                         continue;
                     }
                     // Add the new authorization
                     try {
                         $newAZ = $azMgr2->createAuthorization($oldAZ->getAgentId(), $oldAZ->getFunction()->getId(), $oldQualifier->getId());
                         if ($oldAZ->getExpirationDate()) {
                             $newAZ->updateExpirationDate($oldAZ->getExpirationDate());
                         }
                         if ($oldAZ->getEffectiveDate()) {
                             $newAZ->updateEffectiveDate($oldAZ->getEffectiveDate());
                         }
                     } catch (OperationFailedException $e) {
                     }
                 }
             }
         }
     } catch (Exception $e) {
         printpre($e->getMessage());
         HarmoniErrorHandler::printDebugBacktrace($e->getTrace());
         printpre("An error has occurred. Removing new tables.");
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_implicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_explicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_ancestry');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_j_node_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_hierarchy');
         } catch (DatabaseException $e) {
         }
         $query = new GenericSQLQuery('DROP TABLE az2_implicit_az, az2_explicit_az, az2_function, az2_function_type, az2_node_ancestry, az2_j_node_node, az2_node, az2_node_type,  az2_hierarchy;');
         $dbc->query($query, $dbIndex);
         return false;
     }
     /*********************************************************
      * If we have successfully gotten this far, drop the old 
      * hierarchy and AuthZ tables to prevent confusion.
      *********************************************************/
     $query = new GenericSQLQuery('DROP TABLE az_authorization, az_function, hierarchy, j_node_node, node, node_ancestry;');
     $dbc->query($query, $dbIndex);
     print "Success!";
     return true;
 }
コード例 #4
0
 /**
  * Compress a directory with status stars. Return the resulting file path
  * 
  * @return string the new archive path.
  * @static
  * @access public
  * @since 12/12/06
  */
 function compressWithStatus()
 {
     $archiveBaseName = "export_" . md5(time() . " " . rand());
     // Get the number of files in the directory and initialize the status stars
     $status = new StatusStars(_("Compressing the archive"));
     $numFiles = $this->numFiles($this->_tmpDir);
     $status->initializeStatistics($numFiles);
     $filesSeen = 1;
     // With safe-mode we can't easily get the PID to monitor the compression status,
     // so just execute the compression command.
     if (ini_get('safe_mode')) {
         if (!defined('XML_EXPORT_EXEC_PATH')) {
             throw new ConfigurationErrorException("XML_EXPORT_EXEC_PATH must be defined for exporting to work with SafeMode on. The tar command must exist in the XML_EXPORT_EXEC_PATH.");
         }
         $command = rtrim(XML_EXPORT_EXEC_PATH, '/') . '/tar -v -czf ' . self::getTmpDir() . '/' . $archiveBaseName . $this->_compression . " -C " . $this->_tmpDir . " . ";
         // 			printpre(escapeshellcmd($command));
         exec($command, $result, $return);
         if ($return) {
             throw new OperationFailedException("Could not compress the export archive. 'tar' unavailable in XML_EXPORT_EXEC_PATH or exited with an error.", $return);
         }
         // Update our statistics to fill the screen even though they will just be
         // happening at the end.
         for ($i = 0; $i < $numFiles; $i++) {
             $status->updateStatistics();
         }
     } else {
         $PID = $this->run_in_background('tar -v -czf ' . self::getTmpDir() . '/' . $archiveBaseName . $this->_compression . " -C " . str_replace(":", "\\:", $this->_tmpDir) . " . ", 0, str_replace(":", "\\:", $this->_tmpDir) . "-compress_status");
         while ($this->is_process_running($PID)) {
             $lines = count(file($this->_tmpDir . "-compress_status"));
             for ($i = $filesSeen; $i < $lines; $i++) {
                 $status->updateStatistics();
                 $filesSeen++;
             }
             sleep(1);
         }
         // Finish off any last statistics
         for ($i = $filesSeen; $i <= $numFiles; $i++) {
             $status->updateStatistics();
         }
         // Remove our status file
         unlink($this->_tmpDir . "-compress_status");
     }
     // Remove the source directory
     $this->deleteRecursive($this->_tmpDir);
     return self::getTmpDir() . '/' . $archiveBaseName . $this->_compression;
 }
コード例 #5
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");
 }
コード例 #6
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);
     // 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;
     }
 }
コード例 #7
0
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 6/12/08
  */
 function runUpdate()
 {
     set_time_limit(600);
     $status = new StatusStars(_("Initializing"));
     $status->initializeStatistics(3);
     $idMgr = Services::getService("IdManager");
     $status->updateStatistics();
     $view = $idMgr->getId("edu.middlebury.authorization.view");
     $adminId = $this->getAdminId();
     $status->updateStatistics();
     $authZ = Services::getService("AuthZ");
     $status->updateStatistics();
     $status = new StatusStars(str_replace('%1', count($this->toDo), _("Rebuilding Implicit AZs on %1 nodes.")));
     $status->initializeStatistics(count($this->toDo));
     $azCache = $authZ->getAuthorizationCache();
     foreach ($this->toDo as $node) {
         $azCache->createHierarchyImplictAZs($node, $node->getAncestorIds());
         $status->updateStatistics();
     }
     return true;
 }
コード例 #8
0
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate()
 {
     $agentMgr = Services::getService('Agent');
     $idMgr = Services::getService('Id');
     $groupType = new Type("System", "edu.middlebury.harmoni", "ApplicationGroups", "");
     $nullType = new Type("System", "edu.middlebury.harmoni", "NULL");
     $nullProperties = new HarmoniProperties($nullType);
     try {
         $containerGroup = $agentMgr->getGroup($idMgr->getId('edu.middlebury.segue.site-members'));
     } catch (UnknownIdException $e) {
         $containerGroup = $agentMgr->createGroup('Site-Members', $groupType, 'A container for site-membership groups', $nullProperties, $idMgr->getId('edu.middlebury.segue.site-members'));
     }
     // Since updates can only be run by admins, which in turn can see all sites,
     // the all visible folder will get all slots.
     $folder = new AllVisiblePortalFolder();
     $slots = $folder->getSlots();
     $status = new StatusStars(_("Checking Nodes"));
     $status->initializeStatistics(count($slots));
     $director = SiteDispatcher::getSiteDirector();
     foreach ($slots as $slot) {
         $site = $director->getSiteComponentById($slot->getSiteId()->getIdString());
         $site->getMembersGroup();
         $status->updateStatistics();
     }
     return $this->isInPlace();
 }
コード例 #9
0
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate()
 {
     $prepStatus = new StatusStars("Preparing Migration");
     $prepStatus->initializeStatistics(3);
     $prepStatus->updateStatistics();
     $dbc = Services::getService("DatabaseManager");
     try {
         /*********************************************************
          * Check for the old tables. They must exist for us to run
          *********************************************************/
         $azTables = array('az_authorization', 'az_function', 'hierarchy', 'j_node_node', 'node', 'node_ancestry');
         // Check for old tables
         $tables = $dbc->getTableList(IMPORTER_CONNECTION);
         foreach ($azTables as $table) {
             if (!in_array($table, $tables)) {
                 throw new Exception("Old AZ table, {$table}, is missing. Can not run Update.");
             }
         }
         /*********************************************************
          * Create the new tables
          *********************************************************/
         $type = $dbc->getDatabaseType(IMPORTER_CONNECTION);
         switch ($type) {
             case MYSQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/MySQL/AuthZ2.sql", IMPORTER_CONNECTION);
                 break;
             case POSTGRESQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", IMPORTER_CONNECTION);
                 break;
             case ORACLE:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", IMPORTER_CONNECTION);
                 break;
             default:
                 throw new Exception("Database schemas are not defined for specified database type.");
         }
         /*********************************************************
          * Hierarchy
          *********************************************************/
         $hierarchyMgr1 = Services::getService("Hierarchy");
         if (get_class($hierarchyMgr1) == "AuthZ2_HierarchyManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $hierarchyMgr2 = new AuthZ2_HierarchyManager();
         $azMgr2 = new AuthZ2_AuthorizationManager();
         $azMgr2->setHierarchyManager($hierarchyMgr2);
         $hierarchyMgr2->assignConfiguration($hierarchyMgr1->_configuration);
         /*********************************************************
          * Authorization
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $azMgr2->assignConfiguration($azMgr1->_configuration);
         $prepStatus->updateStatistics();
         /*********************************************************
          * Hierarchies
          *********************************************************/
         $hierarchies = $hierarchyMgr1->getHierarchies();
         $prepStatus->updateStatistics();
         while ($hierarchies->hasNext()) {
             $hierarchy = $hierarchies->next();
             try {
                 $newHierarchy = $hierarchyMgr2->getHierarchy($hierarchy->getId());
             } catch (UnknownIdException $e) {
                 $newHierarchy = $hierarchyMgr2->createHierarchy($hierarchy->getDisplayName(), array(), $hierarchy->getDescription(), $hierarchy->allowsMultipleParents(), $hierarchy->allowsRecursion(), $hierarchy->getId());
             }
             $query = new SelectQuery();
             $query->addTable("node");
             $query->addColumn("COUNT(*)", "num");
             $query->addWhereEqual("fk_hierarchy", $hierarchy->getId()->getIdString());
             $dbc = Services::getService("DatabaseManager");
             $result = $dbc->query($query);
             $this->nodeStatus = new StatusStars("Migrating nodes in the '" . $hierarchy->getDisplayName() . "' Hierarchy.");
             $this->nodeStatus->initializeStatistics($result->field("num"));
             // Add all of the nodes
             $nodes = $hierarchy->getRootNodes();
             while ($nodes->hasNext()) {
                 $this->addNode($newHierarchy, $nodes->next());
             }
         }
         /*********************************************************
          * Authorizations
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         // Add all of the Authorization functions
         $functionTypes = $azMgr1->getFunctionTypes();
         while ($functionTypes->hasNext()) {
             $oldFunctions = $azMgr1->getFunctions($functionTypes->next());
             while ($oldFunctions->hasNext()) {
                 $oldFunction = $oldFunctions->next();
                 // Get or create the function
                 try {
                     $newFunction = $azMgr2->getFunction($oldFunction->getId());
                 } catch (UnknownIdException $e) {
                     $newFunction = $azMgr2->createFunction($oldFunction->getId(), $oldFunction->getReferenceName(), $oldFunction->getDescription(), $oldFunction->getFunctionType(), $oldFunction->getQualifierHierarchyId());
                 }
                 // Get all authorizations for this function.
                 $oldAZs = $azMgr1->getExplicitAZs(null, $oldFunction->getId(), null, false);
                 $status = new StatusStars("Migrating '" . $newFunction->getReferenceName() . "' Authorizations (" . $oldAZs->count() . ")");
                 $status->initializeStatistics($oldAZs->count());
                 while ($oldAZs->hasNext()) {
                     $oldAZ = $oldAZs->next();
                     $status->updateStatistics();
                     try {
                         $oldQualifier = $oldAZ->getQualifier();
                     } catch (UnknownIdException $e) {
                         // continue if the qualifier no longer exists.
                         continue;
                     }
                     // Add the new authorization
                     try {
                         $newAZ = $azMgr2->createAuthorization($oldAZ->getAgentId(), $oldAZ->getFunction()->getId(), $oldQualifier->getId());
                         if ($oldAZ->getExpirationDate()) {
                             $newAZ->updateExpirationDate($oldAZ->getExpirationDate());
                         }
                         if ($oldAZ->getEffectiveDate()) {
                             $newAZ->updateEffectiveDate($oldAZ->getEffectiveDate());
                         }
                     } catch (OperationFailedException $e) {
                     }
                 }
             }
         }
     } catch (Exception $e) {
         printpre($e->getMessage());
         HarmoniErrorHandler::printDebugBacktrace($e->getTrace());
         printpre("An error has occurred. Removing new tables.");
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_implicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_explicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_ancestry');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_j_node_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_hierarchy');
         } catch (DatabaseException $e) {
         }
         $query = new GenericSQLQuery('DROP TABLE az2_implicit_az, az2_explicit_az, az2_function, az2_function_type, az2_node_ancestry, az2_j_node_node, az2_node, az2_node_type,  az2_hierarchy;');
         $dbc->query($query, IMPORTER_CONNECTION);
         return false;
     }
     /*********************************************************
      * If we have successfully gotten this far, drop the old 
      * hierarchy and AuthZ tables to prevent confusion.
      *********************************************************/
     $query = new GenericSQLQuery('DROP TABLE az_authorization, az_function, hierarchy, j_node_node, node, node_ancestry;');
     $dbc->query($query, IMPORTER_CONNECTION);
     return true;
 }
コード例 #10
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)
 {
     // 		$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;
 }
コード例 #11
0
ファイル: convert.act.php プロジェクト: adamfranco/segue
 /**
  * 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;
     }
 }
コード例 #12
0
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 6/12/08
  */
 function runUpdate()
 {
     set_time_limit(600);
     $hierarchyMgr = Services::getService("HierarchyManager");
     $idMgr = Services::getService("IdManager");
     $hierarchyId = $idMgr->getId("edu.middlebury.authorization.hierarchy");
     $hierarchy = $hierarchyMgr->getHierarchy($hierarchyId);
     $view = $idMgr->getId("edu.middlebury.authorization.view");
     $authZ = Services::getService("AuthZ");
     $query = new SelectQuery();
     $query->addColumn('az2_explicit_az.id', 'explicit_az_id');
     $query->addTable('az2_explicit_az');
     $query->addTable('az2_j_node_node', INNER_JOIN, 'az2_j_node_node.fk_child = az2_explicit_az.fk_qualifier');
     $query->addTable('az2_implicit_az', LEFT_JOIN, '(az2_implicit_az.fk_explicit_az = az2_explicit_az.id AND az2_j_node_node.fk_parent = az2_implicit_az.fk_qualifier)');
     $query->addWhereEqual('az2_explicit_az.fk_function', 'edu.middlebury.authorization.view');
     $query->addWhereNull('az2_implicit_az.fk_explicit_az');
     $dbc = Services::getService('DatabaseManager');
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     $status = new StatusStars(str_replace('%1', $result->getNumberOfRows(), _("Rebuilding cascading-up implicit 'view' AZs on %1 nodes.")));
     $status->initializeStatistics($result->getNumberOfRows());
     $azCache = $authZ->getAuthorizationCache();
     while ($result->hasNext()) {
         $row = $result->next();
         $azCache->createImplicitAZsUpForAZ($azCache->getExplicitAZById($row['explicit_az_id']));
         $status->updateStatistics();
     }
     return true;
 }
コード例 #13
0
 /**
  * Regenerate tags for a number of assets
  * 
  * @param mixed $assets An AssetIterator, an array of Assets, or a single Asset
  * @param object Id $agent Id	The agent id to associate with these tags
  * @param string $system		The system to associate with these tags
  * @param optional object Id $repositoryId	Not required, but can enhance 
  *								efficiency if it is known ahead of time.
  * @return void
  * @access public
  * @since 11/27/06
  */
 function regenerateTagsForAssets($assets, $agentId, $system, $repositoryId = null)
 {
     $status = new StatusStars(dgettext("polyphony", "Regenerating Tags for Assets"));
     // array
     if (is_array($assets)) {
         $status->initializeStatistics(count($assets));
         foreach (array_keys($assets) as $key) {
             $this->regenerateTagsForAsset($assets[$key], $agentId, $system, $repositoryId);
             $status->updateStatistics();
         }
     } else {
         if (method_exists($assets, 'next')) {
             $status->initializeStatistics($assets->count());
             while ($assets->hasNext()) {
                 $this->regenerateTagsForAsset($assets->next(), $agentId, $system, $repositoryId);
                 $status->updateStatistics();
             }
         } else {
             if (method_exists($assets, 'getPartValuesByPartStructure')) {
                 $status->initializeStatistics(1);
                 $this->regenerateTagsForAsset($assets, $agentId, $system, $repositoryId);
                 $status->updateStatistics();
             } else {
                 throwError(new Error("Invalid parameter, {$assets}, for \$assets", "Tagging"));
             }
         }
     }
 }
コード例 #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);
     // 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"));
     $exhibitionAsset = $repository->getAsset($idManager->getId(RequestContext::value('exhibition_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.add_children"), $exhibitionAsset->getId())) {
         $slideshowAssetType = new HarmoniType("Asset Types", "edu.middlebury.concerto", "Slideshow", "Slide-Shows are ordered collections of slides that contain captions and may reference media Assets.");
         $slideshowAsset = $repository->createAsset($properties['namedescstep']['display_name'], $properties['namedescstep']['description'], $slideshowAssetType);
         $slideshowAssetId = $slideshowAsset->getId();
         $this->_slideshowAssetId = $slideshowAssetId;
         // 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']));
         $exhibitionAsset->addAsset($slideshowAssetId);
         // --- 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");
         $slideOrder = $setManager->getPersistentSet($slideshowAssetId);
         $status->updateStatistics();
         foreach ($properties['slidestep']['slides'] as $slideProperties) {
             // ---- 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);
             $slideOrder->addItem($slideAssetId);
             // ---- Set the additional info ----
             $slideRecord = $slideAsset->createRecord($slideRecordStructId);
             $slideRecord->createPart($textPositionPartStructId, $textPosition);
             $slideRecord->createPart($displayMetadataPartStructId, $displayMetadata);
             $slideRecord->createPart($targetIdPartStructId, $targetId);
             $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("Create Node", "Slideshow added");
             $item->addNodeId($slideshowAssetId);
             $item->addNodeId($exhibitionAsset->getId());
             $log->appendLogWithTypes($item, $formatType, $priorityType);
         }
         $status->updateStatistics();
         return TRUE;
     } else {
         return FALSE;
     }
 }