Exemplo n.º 1
0
 /**
  * Answer an array of all of the themes known to this source
  * 
  * @return array of Harmoni_Gui2_ThemeInterface
  * @access public
  * @since 5/6/08
  */
 public function getThemes()
 {
     $themes = array();
     $query = new SelectQuery();
     $query->addTable('segue_site_theme');
     $query->addColumn('id');
     $query->addWhereEqual('fk_site', $this->getSiteId());
     $dbMgr = Services::getService("DatabaseManager");
     $result = $dbMgr->query($query, $this->databaseIndex);
     while ($result->hasNext()) {
         $row = $result->next();
         $themes[] = new Segue_Gui2_SiteTheme($this->databaseIndex, $row['id']);
     }
     $result->free();
     return $themes;
 }
Exemplo n.º 2
0
 /**
  * Answer the explicit authorization for this implicit authorization
  * 
  * @return object Authorization
  * @access public
  * @since 4/22/08
  */
 public function getExplicitAZ()
 {
     if ($this->isExplicit()) {
         throw new OperationFailedException("Can not get explicit AZs for an explicit AZ");
     }
     if (isset($this->explicitAZId)) {
         return $this->_cache->getExplicitAZById($this->explicitAZId);
     }
     if (isset($this->_cache->harmoni_db)) {
         if (!isset($this->_cache->_getExplicitAZ_stmt)) {
             $query = $this->_cache->harmoni_db->select();
             $query->addColumn("fk_explicit_az");
             $query->addTable("az2_implicit_az");
             $query->addWhereEqual("id", '?');
             $this->_cache->_getExplicitAZ_stmt = $query->prepare();
         }
         $this->_cache->_getExplicitAZ_stmt->bindValue(1, $this->getIdString());
         $this->_cache->_getExplicitAZ_stmt->execute();
         $result = $this->_cache->_getExplicitAZ_stmt->getResult();
     } else {
         $dbHandler = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addColumn("fk_explicit_az");
         $query->addTable("az2_implicit_az");
         $query->addWhereEqual("id", $this->getIdString());
         // 		printpre($query->asString());
         $result = $dbHandler->query($query, $this->_cache->_dbIndex);
     }
     $this->explicitAZId = $result->field("fk_explicit_az");
     $result->free();
     return $this->_cache->getExplicitAZById($this->explicitAZId);
 }
 /**
  * Add where clauses to the query
  * 
  * @param object SelectQuery $query
  * @return void
  * @access public
  * @since 3/9/06
  */
 function addWhereClauses($query)
 {
     $query->addWhere("log_name = '" . addslashes($this->_logName) . "'");
     $subQuery = new SelectQuery();
     $subQuery->addTable("log_type");
     $subQuery->addColumn("id");
     $subQuery->addWhereEqual("domain", $this->_formatType->getDomain());
     $subQuery->addWhereEqual("authority", $this->_formatType->getAuthority());
     $subQuery->addWhereEqual("keyword", $this->_formatType->getKeyword());
     $query->addWhere("log_entry.fk_format_type = \n(\n" . $subQuery->asString() . ")");
     if ($this->_priorityType && !$this->_priorityType->isEqual(new Type('logging', 'edu.middlebury', 'All'))) {
         $subQuery = new SelectQuery();
         $subQuery->addTable("log_type");
         $subQuery->addColumn("id");
         $subQuery->addWhereEqual("domain", $this->_priorityType->getDomain());
         $subQuery->addWhereEqual("authority", $this->_priorityType->getAuthority());
         $subQuery->addWhereEqual("keyword", $this->_priorityType->getKeyword());
         $query->addWhere("log_entry.fk_priority_type = \n(\n" . $subQuery->asString() . ")");
     }
 }
Exemplo n.º 4
0
 /**
  * Answer the images for this theme
  * 
  * @return array of Harmoni_Filing_FileInterface objects
  * @access public
  * @since 5/15/08
  */
 public function getImages()
 {
     $query = new SelectQuery();
     $query->addTable('segue_site_theme_image');
     $query->addColumn('path');
     $query->addWhereEqual('fk_theme', $this->id);
     $dbMgr = Services::getService("DatabaseManager");
     $result = $dbMgr->query($query, $this->databaseIndex);
     $images = array();
     while ($result->hasNext()) {
         $row = $result->next();
         $images[] = new Segue_Gui2_ThemeImage($this->databaseIndex, $this->id, $row['path']);
     }
     $result->free();
     return $images;
 }
Exemplo n.º 5
0
 /**
  * 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;
 }
Exemplo n.º 6
0
 /**
  * Answer the cached version of the feed Xml
  * 
  * @param string $url
  * @return string The feed XML
  * @access protected
  * @since 7/8/08
  */
 protected function getCachedXmlString($url)
 {
     $dbc = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addTable('segue_plugins_rssfeed_cache');
     $query->addColumn('feed_data');
     $query->addWhereEqual('url', $url);
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     $data = $result->field('feed_data');
     $result->free();
     return $data;
 }
Exemplo n.º 7
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;
 }
Exemplo n.º 8
0
 /**
  * Attempts to delete the specified node in the database. Only leaf nodes can
  * be deleted.
  * @access public
  * @param mixed idValue The string id of the node to delete.
  * @return void
  **/
 function deleteNode($idValue)
 {
     // ** parameter validation
     ArgumentValidator::validate($idValue, OrValidatorRule::getRule(NonzeroLengthStringValidatorRule::getRule(), IntegerValidatorRule::getRule()), true);
     // ** end of parameter validation
     // get the node
     $node = $this->getNode($idValue);
     // if not a leaf, cannot delete
     if (!$node->isLeaf()) {
         // "Can not delete non-leaf nodes.";
         throw new OperationFailedException("Cannont delete non-leaf nodes.");
     }
     // clear the cache and update the _tree structure
     // detach the node from each of its parents and update the join table
     $parents = $node->getParents();
     while ($parents->hasNext()) {
         $parent = $parents->next();
         $node->removeParent($parent->getId());
     }
     // now delete the tree node
     $treeNode = $this->_tree->getNode($idValue);
     $this->_tree->deleteNode($treeNode);
     // -----------------
     // remove from cache
     unset($this->_cache[$idValue]);
     $node = null;
     // now remove from database
     $dbHandler = Services::getService("DatabaseManager");
     // 1. Get the id of the type associated with the node
     $query = new SelectQuery();
     $query->addTable("az2_node");
     $query->addColumn("fk_type", "type_id", "az2_node");
     $query->addWhereEqual("id", $idValue);
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     if (!$queryResult->hasNext()) {
         $queryResult->free();
         throw new OperationFailedException("No type found for node, '{$idValue}'.");
     }
     $typeIdValue = $queryResult->field("type_id");
     $queryResult->free();
     // 2. Now delete the node
     $query = new DeleteQuery();
     $query->setTable("az2_node");
     $query->addWhereEqual("id", $idValue);
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     // 3. Now see if any other nodes have the same type
     $query = new SelectQuery();
     $query->addTable("az2_node");
     // count the number of nodes using the same type
     $query->addColumn("COUNT(fk_type)", "num");
     $query->addWhereEqual("fk_type", $typeIdValue);
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     $num = $queryResult->field("num");
     $queryResult->free();
     if ($num == 0) {
         // if no other nodes use this type, then delete the type
         $query = new DeleteQuery();
         $query->setTable("az2_node_type");
         $query->addWhereEqual("id", $typeIdValue);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
     }
     // Delete the node's ancestory from the Ancestory table
     $this->clearNodeAncestory($idValue);
 }
 /**
  * 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;
 }
Exemplo n.º 10
0
 /**
  * Answer a list of most recently seen slot-names ordered recent-first.
  * 
  * @return array
  * @access public
  * @since 9/22/08
  */
 public function getRecentSlots()
 {
     $slots = array();
     $dbc = Services::getService('DatabaseManager');
     $query = new SelectQuery();
     $query->addTable('segue_accesslog');
     $query->addColumn('fk_slotname');
     $query->addColumn('tstamp');
     $query->addWhereEqual('agent_id', $this->_getCurrentAgentId());
     $query->addOrderBy('tstamp', DESCENDING);
     $query->limitNumberOfRows(50);
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     while ($result->hasNext()) {
         $row = $result->next();
         $slots[$row['fk_slotname']] = DateAndTime::fromString($row['tstamp'])->asString();
     }
     // Add session-stored slots
     if (isset($_SESSION['segue_access_log'])) {
         foreach ($_SESSION['segue_access_log'] as $slotname => $tstamp) {
             $slots[$slotname] = $tstamp;
         }
         arsort($slots);
     }
     return array_keys($slots);
 }
Exemplo n.º 11
0
 /**
  * Auxilliary private function that returns Authorizations according to a
  * criteria. Null values are interpreted as wildmarks. Warning: $returnExplicitOnly = false
  * will increase the running time significantly - USE SPARINGLY!
  * @access public
  * @param string aId The string id of an agent.
  * @param string fId The string id of a function.
  * @param string qId The string id of a qualifier. This parameter can not be null
  * and used as a wildmark.
  * @param object fType The type of a function.
  * @param boolean returnExplicitOnly If True, only explicit Authorizations
  *		will be returned.
  * @param boolean searchUp If true, the ancester nodes of the qualifier will
  *		be checked as well
  * @param boolean isActiveNow If True, only active Authorizations will be returned.
  * @return ref object An AuthorizationIterator.
  **/
 function getAZs($aId, $fId, $qId, $fType, $returnExplicitOnly, $searchUp, $isActiveNow, $groupIds = array())
 {
     // 		printpre (func_get_args());
     // ** parameter validation
     $rule = StringValidatorRule::getRule();
     ArgumentValidator::validate($groupIds, ArrayValidatorRuleWithRule::getRule(OptionalRule::getRule($rule)), true);
     ArgumentValidator::validate($aId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($fId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($qId, OptionalRule::getRule($rule), true);
     ArgumentValidator::validate($fType, OptionalRule::getRule(ExtendsValidatorRule::getRule("Type")), true);
     ArgumentValidator::validate($returnExplicitOnly, BooleanValidatorRule::getRule(), true);
     ArgumentValidator::validate($isActiveNow, BooleanValidatorRule::getRule(), true);
     // ** end of parameter validation
     $idManager = Services::getService("Id");
     // the parameter that influences the result most is $returnExplicitOnly
     // 1) If $returnExplicitOnly is TRUE, then we only need to check for Authorizations
     // that have been explicitly created, i.e. no need to look for inherited
     // authorizations
     // 2) If $returnExplicitOnly is FALSE, then we need to include inherited Authorizations
     // as well.
     // this array will store the ids of all qualifiers to be checked for authorizations
     $qualifiers = array();
     // check all ancestors of given qualifier
     $hierarchyManager = Services::getService("Hierarchy");
     if (isset($qId)) {
         $qualifierId = $idManager->getId($qId);
         $node = $hierarchyManager->getNode($qualifierId);
         $hierarchy = $hierarchyManager->getHierarchyForNode($node);
         if ($searchUp) {
             // these are the ancestor nodes
             $nodes = $hierarchy->traverse($qualifierId, Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_UP, Hierarchy::TRAVERSE_LEVELS_ALL);
             // now get the id of each node and store in array
             while ($nodes->hasNext()) {
                 $info = $nodes->next();
                 $id = $info->getNodeId();
                 $qualifiers[] = $id->getIdString();
             }
         } else {
             $qualifiers = array($qId);
         }
     }
     //		print_r($qualifiers);
     // setup the query
     $dbHandler = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     $query->addColumn("authorization_id", "id");
     $query->addColumn("fk_agent", "aid");
     $query->addColumn("fk_function", "fid");
     $query->addColumn("fk_qualifier", "qid");
     $query->addColumn("authorization_effective_date", "eff_date");
     $query->addColumn("authorization_expiration_date", "exp_date");
     $query->addTable("az_authorization");
     // now include criteria
     // the qualifiers criteria
     if (isset($qualifiers) && count($qualifiers)) {
         $query->addWhereIn('az_authorization.fk_qualifier', $qualifiers);
     }
     // Agents/Groups
     if (isset($aId)) {
         $agentIds = array($aId);
     } else {
         $agentIds = array();
     }
     $allAgentIds = array_merge($agentIds, $groupIds);
     // the agent criteria
     if (count($allAgentIds)) {
         $query->addWhereIn('az_authorization.fk_agent', $allAgentIds);
     }
     // the function criteria
     if (isset($fId)) {
         $joinc = "az_authorization.fk_function = az_function.function_id";
         $query->addTable("az_function", INNER_JOIN, $joinc);
         $query->addWhereEqual("az_authorization.fk_function", $fId);
     }
     // the function type criteria
     if (isset($fType)) {
         // do not join with az_function if we did already
         if (!isset($fId)) {
             $joinc = "az_authorization.fk_function = az_function.function_id";
             $query->addTable("az_function", INNER_JOIN, $joinc);
         }
         // now join with type
         $joinc = "az_function.fk_type = type.type_id";
         $query->addTable("type", INNER_JOIN, $joinc);
         $query->addWhereEqual("type.type_domain", $fType->getDomain());
         $query->addWhereEqual("type.type_authority", $fType->getAuthority());
         $query->addWhereEqual("type.type_keyword", $fType->getKeyword());
     }
     // the isActiveNow criteria
     if ($isActiveNow) {
         $where = "(authorization_effective_date IS NULL OR (NOW() >= authorization_effective_date))";
         $query->addWhere($where);
         $where = "(authorization_expiration_date IS NULL OR (NOW() < authorization_expiration_date))";
         $query->addWhere($where);
     }
     $query->addOrderBy("authorization_id");
     //		echo "<pre>\n";
     //		echo MySQL_SQLGenerator::generateSQLQuery($query);
     //		echo "</pre>\n";
     $queryResult = $dbHandler->query($query, $this->_dbIndex);
     // this array will store the authorizations that will be returned
     $authorizations = array();
     // we only want to create one implicitAZ for a given Agent/Function/Qualifier
     // combo, so maintain a list of already created ones to skip
     $createdImplicitAZs = array();
     $i = 0;
     // process all rows and create the explicit authorizations
     while ($queryResult->hasMoreRows()) {
         $row = $queryResult->getCurrentRow();
         // 			printpre($row);
         $idValue = $row['id'];
         $id = $idManager->getId($idValue);
         if (isset($this->_authorizations[$idValue])) {
             $authorization = $this->_authorizations[$idValue];
         } else {
             $agentId = $idManager->getId($row['aid']);
             $functionId = $idManager->getId($row['fid']);
             $explicitQualifierId = $idManager->getId($row['qid']);
             $effectiveDate = $dbHandler->fromDBDate($row['eff_date'], $this->_dbIndex);
             $expirationDate = $dbHandler->fromDBDate($row['exp_date'], $this->_dbIndex);
             // create the explicit authorization (each explicit authorization
             // has a corresponding row in the authorization db table)
             $authorization = new HarmoniAuthorization($idValue, $agentId, $functionId, $explicitQualifierId, true, $this, $effectiveDate, $expirationDate);
             $this->_authorizations[$idValue] = $authorization;
         }
         // Explicit AZ for ancestor qualifiers and groups should have
         // corresponding implicit AZs
         // in decendents, but not appear in their AZs directly.
         // Therefore, only add the explicit AZ if it is for the requested
         // qualifier and agent if we are fetching more than just the explicitAZs.
         if ($row['qid'] == $qId && $row['aid'] == $aId || $returnExplicitOnly) {
             $authorizations[] = $authorization;
         }
         // now create the implicit authorizations
         // the implicit authorizations will be created for all nodes
         // on the hierarchy path(s) between the node with the explicit authorization
         // and the node on which getAZs() was called.
         // If the row's qualifier and agent are what we asked for however,
         // then the AZ is explicit and doesn't need an implicit AZ as well.
         if ((!$returnExplicitOnly || $searchUp) && ($row['qid'] != $qId || $aId && $row['aid'] != $aId)) {
             // 				printpre("Building Implicit AZs...");
             // 				var_dump($returnExplicitOnly);
             // 				var_dump($searchUp);
             // if this is an AZ that is implicit because of a group instead
             // of because of the hierarchy, create it.
             if ($row['qid'] == $qId && $row['aid'] != $aId) {
                 // 					printpre("In first clause (AuthorizationCache)");
                 $qualifierId = $idManager->getId($qId);
                 // If we are getting implicit AZs for a given agent, make sure
                 // that the implicit AZ has their Id.
                 if ($aId) {
                     $agentId = $idManager->getId($aId);
                 } else {
                     $agentId = $authorization->getAgentId();
                 }
                 $function = $authorization->getFunction();
                 $functionId = $function->getId();
                 $effectiveDate = $authorization->getEffectiveDate();
                 $expirationDate = $authorization->getExpirationDate();
                 $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $qualifierId, false, $this, $effectiveDate, $expirationDate);
                 $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $qualifierId->getIdString();
                 if (!in_array($azHash, $createdImplicitAZs)) {
                     $authorizations[] = $implicit;
                     $createdImplicitAZs[] = $azHash;
                 }
             } else {
                 if (!$returnExplicitOnly && $qId) {
                     // 					printpre("In second clause (AuthorizationCache)");
                     // If we are getting implicit AZs for a given agent, make sure
                     // that the implicit AZ has their Id.
                     if ($aId) {
                         $agentId = $idManager->getId($aId);
                     } else {
                         $agentId = $authorization->getAgentId();
                     }
                     $function = $authorization->getFunction();
                     $functionId = $function->getId();
                     $effectiveDate = $authorization->getEffectiveDate();
                     $expirationDate = $authorization->getExpirationDate();
                     $implicitQualifierId = $idManager->getId($qId);
                     $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $implicitQualifierId, false, $this, $effectiveDate, $expirationDate);
                     $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $implicitQualifierId->getIdString();
                     if (!in_array($azHash, $createdImplicitAZs)) {
                         $authorizations[] = $implicit;
                         $createdImplicitAZs[] = $azHash;
                     }
                 } else {
                     if (!$returnExplicitOnly) {
                         printpre($row);
                         printpre("In third clause (AuthorizationCache)");
                         $explicitQualifier = $authorization->getQualifier();
                         $explicitQualifierId = $explicitQualifier->getId();
                         // If we are getting implicit AZs for a given agent, make sure
                         // that the implicit AZ has their Id.
                         if ($aId) {
                             $agentId = $idManager->getId($aId);
                         } else {
                             $agentId = $authorization->getAgentId();
                         }
                         $function = $authorization->getFunction();
                         $functionId = $function->getId();
                         $effectiveDate = $authorization->getEffectiveDate();
                         $expirationDate = $authorization->getExpirationDate();
                         // this is set 2
                         $authZManager = Services::getService("AuthZ");
                         $hierarchies = $authZManager->getQualifierHierarchies();
                         while ($hierarchies->hasNext()) {
                             $hierarchyId = $hierarchies->next();
                             $hierarchy = $hierarchyManager->getHierarchy($hierarchyId);
                             $timer = new Timer();
                             $timer->start();
                             $nodes = $hierarchy->traverse($explicitQualifierId, Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_DOWN, Hierarchy::TRAVERSE_LEVELS_ALL);
                             $timer->end();
                             printf("LoadAZTime: %1.6f <br/>", $timer->printTime());
                             // now get the id of each node and store in array
                             $set2 = array();
                             // skip the first node
                             $nodes->next();
                             while ($nodes->hasNext()) {
                                 $info = $nodes->next();
                                 $nodeId = $info->getNodeId();
                                 $implicit = new HarmoniAuthorization(null, $agentId, $functionId, $nodeId, false, $this, $effectiveDate, $expirationDate);
                                 $azHash = $agentId->getIdString() . "::" . $functionId->getIdString() . "::" . $nodeId->getIdString();
                                 // 							printpre($azHash);
                                 // Weird bugs were happening, with $createdImplicitAZs
                                 // but I can't figure out what is going on.
                                 if (!in_array($azHash, $createdImplicitAZs)) {
                                     $authorizations[] = $implicit;
                                     // 								$createdImplicitAZs[] = $azHash;
                                 }
                             }
                         }
                     }
                 }
             }
         }
         $queryResult->advanceRow();
     }
     $queryResult->free();
     return $authorizations;
 }
Exemplo n.º 12
0
 /**
  * Answer a new Segue 2 id for a segue1 id 
  * 
  * @param string $idType 'site', 'section', 'page', 'story', or 'comment'
  * @param string $id
  * @return string or throw an UnknownIdException
  * @access private
  * @since 3/20/08
  */
 private function getSegue2IdForOld($idType, $id)
 {
     $segue1Identifiers = array('story', 'page', 'section', 'site');
     if (!in_array($idType, $segue1Identifiers)) {
         throw new InvalidArgumentException("{$idType} is not one of (" . implode(', ', $segue1Identifiers) . ").");
     }
     $query = new SelectQuery();
     $query->addTable('segue1_id_map');
     $query->addColumn('segue2_slot_name', 'slotName');
     $query->addColumn('segue2_id', 'id');
     $query->addWhereEqual('segue1_id', $idType . "_" . $id);
     $dbc = Services::getService('DatabaseManager');
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     if (!$result->getNumberOfRows()) {
         throw new UnknownIdException("No map matches for Segue 1 {$idType} {$id}.");
     }
     $slotName = $result->field('slotName');
     $newId = $result->field('id');
     // check to see if the new Id is valid.
     try {
         $repositoryMgr = Services::getService('Repository');
         $idMgr = Services::getService('Id');
         $repository = $repositoryMgr->getRepository($idMgr->getId('edu.middlebury.segue.sites_repository'));
         $asset = $repository->getAsset($idMgr->getId($newId));
         return $newId;
     } catch (UnknownIdException $e) {
         $slotMgr = SlotManager::instance();
         $slot = $slotMgr->getSlotByShortname($slotName);
         if ($slot->siteExists()) {
             return $slot->getSiteId()->getIdString();
         }
     }
     // If we still couldn't resolve throw an exception.
     throw new UnknownIdException("A match was found for Segue 1 {$idType} {$id}, but it was not valid.");
 }
Exemplo n.º 13
0
 /**
  * Load all user preferences for the current user
  * 
  * @return void
  * @access protected
  * @since 9/16/08
  */
 protected function _loadUserPrefs()
 {
     if (!isset($_SESSION['harmoni_user_prefs_persistant']) || $_SESSION['harmoni_user_prefs_user'] != $this->_getCurrentAgentId()) {
         unset($_SESSION['harmoni_user_prefs_user']);
         unset($_SESSION['harmoni_user_prefs_persistant']);
         // Do not load preferences for anonymous.
         if ($this->_getCurrentAgentId() == 'edu.middlebury.agents.anonymous') {
             return;
         }
         $query = new SelectQuery();
         $query->addTable('user_prefs');
         $query->addColumn('pref_key');
         $query->addColumn('pref_val');
         $query->addWhereEqual('agent_id', $this->_getCurrentAgentId());
         $dbc = Services::getService('DatabaseManager');
         $result = $dbc->query($query);
         $_SESSION['harmoni_user_prefs_user'] = $this->_getCurrentAgentId();
         $_SESSION['harmoni_user_prefs_persistant'] = array();
         while ($result->hasNext()) {
             $row = $result->next();
             $_SESSION['harmoni_user_prefs_persistant'][$row['pref_key']] = $row['pref_val'];
         }
     }
 }
Exemplo n.º 14
0
 /**
  * Answer true if this version is the current version.
  *
  * @return boolean
  * @access public
  * @since 1/8/08
  */
 public function isCurrent()
 {
     $query = new SelectQuery();
     $query->addTable('segue_plugin_version');
     $query->addColumn('version_id');
     $query->addWhereEqual('node_id', $this->pluginInstance->getId());
     $query->addOrderBy('tstamp', SORT_DESC);
     $query->limitNumberOfRows(1);
     $dbc = Services::getService('DBHandler');
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     if ($result->field('version_id') == $this->getVersionId()) {
         return true;
     } else {
         return false;
     }
 }
 /**
  * Answer an array of the versions for this plugin instance with the most 
  * recent version first.
  *
  * @return array of SeguePluginVersion objects
  * @access public
  * @since 1/7/08
  */
 public function getVersions()
 {
     if (!isset($this->versions)) {
         $this->versions = array();
         $query = new SelectQuery();
         $query->addTable('segue_plugin_version');
         $query->addColumn('version_id');
         $query->addColumn('tstamp');
         $query->addColumn('comment');
         $query->addColumn('agent_id');
         $query->addWhereEqual('node_id', $this->getId());
         $query->addOrderBy('tstamp', SORT_DESC);
         $dbc = Services::getService('DBHandler');
         $result = $dbc->query($query, IMPORTER_CONNECTION);
         $idMgr = Services::getService("Id");
         $number = $result->getNumberOfRows();
         while ($result->hasNext()) {
             $row = $result->next();
             $this->versions[] = new SeguePluginVersion($this, $row['version_id'], DateAndTime::fromString($row['tstamp']), $idMgr->getId($row['agent_id']), $number, $row['comment']);
             $number--;
         }
     }
     return $this->versions;
 }
 /**
  * Get the Asset with the specified unique Id.
  * 
  * @param object Id $assetId
  *  
  * @return object Asset
  * 
  * @throws object RepositoryException An exception with one of
  *         the following messages defined in
  *         org.osid.repository.RepositoryException may be thrown: {@link
  *         org.osid.repository.RepositoryException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.repository.RepositoryException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.repository.RepositoryException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.repository.RepositoryException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function getAsset(Id $assetId)
 {
     $query = new SelectQuery();
     $query->addTable($this->config['table']);
     $query->addColumn($this->config['id_column']);
     foreach ($this->config['columns'] as $column) {
         $query->addColumn($column);
     }
     $query->addWhereEqual($this->config['id_column'], substr($assetId->getIdString(), strlen($this->getId()->getIdString() . ".")));
     $assets = new SimpleTableAssetIterator($this, $this->config, $this->dbc->query($query, $this->dbIndex));
     if (!$assets->hasNext()) {
         throw new UnknownIdException();
     }
     return $assets->next();
 }
Exemplo n.º 17
0
 /**
  * Answer the internal slots for the current user
  * 
  * @return array
  * @access private
  * @since 8/14/07
  */
 private function getInternalSlotDefinitionsForUserByType($slotType)
 {
     $query = new SelectQuery();
     $query->addTable('segue_slot_owner AS search_owner');
     $query->addTable('segue_slot', LEFT_JOIN, 'segue_slot.shortname = search_owner.shortname');
     $query->addTable('segue_slot_owner AS all_owners', LEFT_JOIN, 'segue_slot.shortname = all_owners.shortname');
     $query->addColumn('segue_slot.shortname', 'shortname');
     $query->addColumn('segue_slot.site_id', 'site_id');
     $query->addColumn('segue_slot.alias_target', 'alias_target');
     $query->addColumn('segue_slot.type', 'type');
     $query->addColumn('segue_slot.location_category', 'location_category');
     $query->addColumn('segue_slot.media_quota', 'media_quota');
     $query->addColumn('all_owners.owner_id', 'owner_id');
     $query->addColumn('all_owners.removed', 'removed');
     $query->addWhereEqual('segue_slot.type', $slotType);
     $authN = Services::getService("AuthN");
     $userId = $authN->getFirstUserId();
     // 		$idManager = Services::getService("Id");
     // 		$userId = $idManager->getId("3"); // jadministrator
     $query->addWhereEqual('search_owner.owner_id', $userId->getIdString());
     $query->addWhereEqual('search_owner.removed', '0');
     // 		print $query->asString();
     $dbc = Services::getService('DBHandler');
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     return $this->getSlotsFromQueryResult($result);
 }
Exemplo n.º 18
0
 /**
  * Get all NodeTypes used in this Hierarchy.
  *	
  * @return object TypeIterator
  * 
  * @throws object HierarchyException An exception with one of
  *		   the following messages defined in
  *		   org.osid.hierarchy.HierarchyException may be thrown:	 {@link
  *		   org.osid.hierarchy.HierarchyException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.hierarchy.HierarchyException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.hierarchy.HierarchyException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.hierarchy.HierarchyException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}
  * 
  * @access public
  */
 function getNodeTypes()
 {
     $dbHandler = Services::getService("DatabaseManager");
     $query = new SelectQuery();
     // set the tables
     $query->addTable("az2_node");
     $joinc = "az2_node.fk_type = az2_node_type.id";
     $query->addTable("az2_node_type", INNER_JOIN, $joinc);
     $hierarchyIdValue = $this->_id->getIdString();
     $query->addWhereEqual("az2_node.fk_hierarchy", $hierarchyIdValue);
     // set the columns to select
     $query->setDistinct(true);
     $query->addColumn("id", "id", "az2_node_type");
     $query->addColumn("domain", "domain", "az2_node_type");
     $query->addColumn("authority", "authority", "az2_node_type");
     $query->addColumn("keyword", "keyword", "az2_node_type");
     $query->addColumn("description", "description", "az2_node_type");
     $queryResult = $dbHandler->query($query, $this->_cache->_dbIndex);
     $types = array();
     while ($queryResult->hasMoreRows()) {
         // fetch current row
         $arr = $queryResult->getCurrentRow();
         // create type object
         $type = new HarmoniType($arr['domain'], $arr['authority'], $arr['keyword'], $arr['description']);
         // add it to array
         $types[] = $type;
         $queryResult->advanceRow();
     }
     $queryResult->free();
     $result = new HarmoniTypeIterator($types);
     return $result;
 }
Exemplo n.º 19
0
 /**
  * Answer a list of categories in this log.
  * 
  * Warning: NOT IN OSID
  * 
  * @return array
  * @access public
  * @since 6/10/08
  */
 public function getCategories()
 {
     $query = new SelectQuery();
     $query->addTable('log_entry');
     $query->addColumn('DISTINCT (category)', 'cat');
     $query->addWhereEqual('log_name', $this->_name);
     $query->addOrderBy('category');
     $dbc = Services::getService('DatabaseManager');
     $result = $dbc->query($query, $this->_dbIndex);
     $categories = array();
     while ($result->hasNext()) {
         $row = $result->next();
         $categories[] = $row['cat'];
     }
     return $categories;
 }
 /**
  * Answer the Externally-defined group Ids that are the children of the group id passed.
  * 
  * @param object Id $hierarchyParentId
  * @return array
  * @access public
  * @since 11/6/07
  */
 public function getExternalChildGroupIds(Id $hierarchyParentId)
 {
     $query = new SelectQuery();
     $query->addTable('agent_external_children');
     $query->addColumn('fk_child');
     $query->addWhereEqual('fk_parent', $hierarchyParentId->getIdString());
     $dbc = Services::getService("DBHandler");
     $result = $dbc->query($query, $this->_configuration->getProperty('database_index'));
     $idMgr = Services::getService("Id");
     $children = array();
     while ($result->hasMoreRows()) {
         $children[] = $idMgr->getId($result->field('fk_child'));
         $result->advanceRow();
     }
     return $children;
 }
Exemplo n.º 21
0
 /**
  * Answer migration status info about this slot
  * 
  * @return array
  */
 public function getMigrationStatus()
 {
     $dbc = Services::getService('DBHandler');
     $query = new SelectQuery();
     $query->addTable('segue_slot_migration_status', NO_JOIN, '', 'm');
     $query->addColumn('status');
     $query->addColumn('redirect_url');
     $query->addTable('segue_slot', LEFT_JOIN, 's.shortname = m.shortname', 's');
     $query->addColumn('shortname', 'slot_exists', 's');
     $query->addWhereEqual('m.shortname', $this->getShortname());
     $result = $dbc->query($query, IMPORTER_CONNECTION);
     if ($result->hasMoreRows()) {
         // If there is no site anymore and no valid migration status, mark as unneeded.
         if (is_null($result->field('slot_exists')) && $result->field('status') == 'incomplete') {
             return array('type' => 'unneeded', 'url' => '');
         }
         return array('type' => $result->field('status'), 'url' => $result->field('redirect_url'));
     }
     // Defaults
     if ($this->siteExists()) {
         return array('type' => 'incomplete', 'url' => '');
     } else {
         return array('type' => 'unneeded', 'url' => '');
     }
 }
Exemplo n.º 22
0
 /**
  * Answer an TagInfoIterator that lists information on tags attached to an item.
  * 
  * @param object TaggedItem $item
  * @return object TagInfoIterator
  * @access public
  * @since 4/18/08
  */
 public function getTagInfoForItem(TaggedItem $item)
 {
     $query = new SelectQuery();
     $query->addTable('tag');
     $query->addColumn('value');
     $query->addColumn('user_id');
     $query->addColumn('tstamp');
     $query->addWhereEqual("fk_item", $item->getDatabaseId());
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     $iterator = new HarmoniIterator(array());
     $idManager = Services::getService("Id");
     while ($result->hasNext()) {
         $row = $result->next();
         $iterator->add(new TagInfo(new Tag($row['value']), $item, $idManager->getId($row['user_id']), DateAndTime::fromString($row['tstamp'])));
     }
     return $iterator;
 }
Exemplo n.º 23
0
 /**
  * Returns the hierarchy Node with the specified Id.
  *
  * WARNING: NOT IN OSID - As of Version 2.0, this method has been removed
  * from the OSID.
  *
  * @access public
  * @param ref object id The Id object.
  * @return ref object The Node with the given Id.
  **/
 function getNode(Id $id)
 {
     // Use Harmoni_Db method for greater performance if it is configured
     if (isset($this->harmoni_db)) {
         return $this->getNode_Harmoni_Db($id);
     }
     // Otherwise use original method
     $idValue = $id->getIdString();
     $dbHandler = Services::getService("DatabaseManager");
     // find the hierarchy id for this node
     $query = new SelectQuery();
     $query->addColumn("fk_hierarchy", "hierarchy_id", "az2_node");
     $query->addTable("az2_node");
     $joinc = "fk_hierarchy = az2_hierarchy.id";
     $query->addTable("az2_hierarchy", INNER_JOIN, $joinc);
     $query->addWhereEqual("az2_node.id", $idValue);
     $nodeQueryResult = $dbHandler->query($query, $this->_dbIndex);
     if ($nodeQueryResult->getNumberOfRows() != 1) {
         $nodeQueryResult->free();
         throw new UnknownIdException("Could not find node of id, '" . $id->getIdString() . "'.");
     }
     $nodeRow = $nodeQueryResult->getCurrentRow();
     $nodeQueryResult->free();
     $idManager = Services::getService("Id");
     $hierarchyId = $nodeRow['hierarchy_id'];
     // get the hierarchy
     $hierarchy = $this->getHierarchy($idManager->getId($hierarchyId));
     $node = $hierarchy->getNode($id);
     return $node;
 }
Exemplo n.º 24
0
 /**
  * load the info for this file
  * 
  * @return null
  * @access protected
  * @since 5/15/08
  */
 protected function loadInfo()
 {
     $query = new SelectQuery();
     $query->addTable('segue_site_theme_image');
     $query->addColumn('size');
     $query->addColumn('mime_type');
     $query->addColumn('modify_timestamp');
     $query->addWhereEqual('fk_theme', $this->themeId);
     $query->addWhereEqual('path', $this->path);
     $dbMgr = Services::getService("DatabaseManager");
     $result = $dbMgr->query($query, $this->databaseIndex);
     if (!$result->hasNext()) {
         throw new UnknownIdException("Theme image '" . $this->path . "' for theme '" . $this->themeId . "' does not exist.");
     }
     $row = $result->next();
     $this->size = $row['size'];
     $this->mimeType = $row['mime_type'];
     $this->modificationDate = DateAndTime::fromString($row['modify_timestamp']);
 }
 /**
  * Answer true if an email address is confirmed
  * 
  * @param object AuthNTokens $email
  * @return boolean
  * @access public
  * @since 6/4/08
  */
 public function isEmailConfirmed(AuthNTokens $authNTokens)
 {
     $dbc = Services::getService("DatabaseManager");
     $dbId = $this->_configuration->getProperty('database_id');
     $authenticationTable = $this->_configuration->getProperty('authentication_table');
     $usernameField = $this->_configuration->getProperty('username_field');
     $passwordField = $this->_configuration->getProperty('password_field');
     $query = new SelectQuery();
     $query->addTable($authenticationTable);
     $query->addColumn("email_confirmed");
     $query->addWhereEqual($usernameField, $authNTokens->getUsername());
     $result = $dbc->query($query, $dbId);
     if ($result->hasNext()) {
         $row = $result->next();
         $result->free();
         if ($row['email_confirmed'] == '1') {
             return true;
         } else {
             return false;
         }
     } else {
         $result->free();
         throw new UnknownIdException("Unknown login, '" . $authNTokens->getUsername() . "'.");
     }
 }
Exemplo n.º 26
0
 /**
  * Test dynamic SELECT WHERE IN queries
  * 
  * @param object $db
  * @param array $testSet
  * @return void
  * @access public
  * @since 4/7/08
  */
 public function testDBHandler($dbHandler, array $testSet)
 {
     foreach ($testSet as $id) {
         $query = new SelectQuery();
         $query->addColumn('*');
         $query->addTable('log_entry');
         $query->addWhereEqual('id', $id);
         $result = $dbHandler->query($query);
         while ($result->hasNext()) {
             $row = $result->next();
         }
         $result->free();
         // 			printpre($result);
     }
 }
Exemplo n.º 27
0
 /**
  * Answer An AZ query for implicit AZs
  * 
  * @param array $agentIds The agent Ids to match
  * @param string fId The string id of a function.
  * @param string qId The string id of a qualifier. This parameter can not be null
  * and used as a wildmark.
  * @param object fType The type of a function.
  * @param boolean isActiveNow If True, only active Authorizations will be returned.
  * @return SelectQueryInterface 
  * @access protected
  * @since 4/23/08
  */
 protected function getImplicitAZQuery(array $agentIds, $fId, $qId, $fType, $isActiveNow)
 {
     $query = new SelectQuery();
     $query->addColumn("fk_explicit_az");
     $query->addColumn("id", "id", "az2_implicit_az");
     $query->addColumn("fk_agent", "aid");
     $query->addColumn("fk_function", "fid");
     $query->addColumn("fk_qualifier", "qid");
     $query->addColumn("effective_date", "eff_date");
     $query->addColumn("expiration_date", "exp_date");
     $query->addTable("az2_implicit_az");
     // now include criteria
     // the qualifiers criteria
     if (isset($qId)) {
         $query->addWhereEqual('fk_qualifier', $qId);
     }
     // the agent criteria
     if (count($agentIds)) {
         $query->addWhereIn('fk_agent', $agentIds);
     }
     // the function criteria
     if (isset($fId)) {
         $joinc = "az2_implicit_az.fk_function = az2_function.id";
         $query->addTable("az2_function", INNER_JOIN, $joinc);
         $query->addWhereEqual("fk_function", $fId);
     }
     // the function type criteria
     if (isset($fType)) {
         // do not join with az_function if we did already
         if (!isset($fId)) {
             $joinc = "az2_implicit_az.fk_function = az2_function.id";
             $query->addTable("az2_function", INNER_JOIN, $joinc);
         }
         // now join with type
         $joinc = "az2_function.fk_type = az2_function_type.id";
         $query->addTable("az2_function_type", INNER_JOIN, $joinc);
         $query->addWhereEqual("domain", $fType->getDomain());
         $query->addWhereEqual("authority", $fType->getAuthority());
         $query->addWhereEqual("keyword", $fType->getKeyword());
     }
     // the isActiveNow criteria
     if ($isActiveNow) {
         $where = "(effective_date IS NULL OR (NOW() >= effective_date))";
         $query->addWhere($where);
         $where = "(expiration_date IS NULL OR (NOW() < expiration_date))";
         $query->addWhere($where);
     }
     $query->addOrderBy("az2_implicit_az.id");
     return $query;
 }