Example #1
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function execute()
 {
     if (RequestContext::value('help') || RequestContext::value('h') || RequestContext::value('?')) {
         throw new HelpRequestedException("This is a command line script that will populate the OAI data tables from the \nrepositories in Concerto. It takes no arguments or parameters.\n");
     }
     $harmoni = Harmoni::instance();
     $config = $harmoni->getAttachedData('OAI_CONFIG');
     if (!defined('OAI_UPDATE_OUTPUT_HTML')) {
         define("OAI_UPDATE_OUTPUT_HTML", TRUE);
     }
     while (ob_get_level()) {
         ob_end_flush();
     }
     $harvesterConfig = $config->getProperty('OAI_HARVESTER_CONFIG');
     if (!isset($_SESSION['oai_table_setup_complete'])) {
         $dbc = Services::getService("DatabaseManager");
         $tables = $dbc->getTableList($config->getProperty('OAI_DBID'));
         foreach ($harvesterConfig as $configArray) {
             $table = 'oai_' . $configArray['name'];
             if (!in_array($table, $tables)) {
                 $queryString = file_get_contents(dirname(__FILE__) . "/phpoai2/doc/oai_records_mysql.sql");
                 $queryString = str_replace('oai_records', $table, $queryString);
                 $query = new GenericSQLQuery();
                 $query->addSQLQuery(SQLUtils::parseSQLString($queryString));
                 $dbc->query($query, $config->getProperty('OAI_DBID'));
             }
         }
         $_SESSION['oai_table_setup_complete'] = true;
     }
     $i = 1;
     foreach ($harvesterConfig as $configArray) {
         $tableMessage = "Updating table oai_" . $configArray['name'] . " (table " . $i . " of " . count($harvesterConfig) . ")";
         if (OAI_UPDATE_OUTPUT_HTML) {
             print "\n<hr/><h2>" . $tableMessage . "</h2>";
         } else {
             print "---------------------------------------------------\n| {$tableMessage}\n---------------------------------------------------\n";
         }
         $this->updateTable($configArray['name'], $configArray['repository_ids'], $configArray['auth_group_ids']);
         $i++;
         print "\n\n";
     }
 }
Example #2
0
 /**
  * Build the content for this action
  * 
  * @return void
  * @access public
  * @since 4/26/05
  */
 function execute()
 {
     if (!isset($_SESSION['oai_table_setup_complete'])) {
         $dbc = Services::getService("DatabaseManager");
         $harmoni = Harmoni::instance();
         $config = $harmoni->getAttachedData('OAI_CONFIG');
         $tables = $dbc->getTableList($config->getProperty('OAI_DBID'));
         $harvesterConfig = $config->getProperty('OAI_HARVESTER_CONFIG');
         foreach ($harvesterConfig as $configArray) {
             $table = 'oai_' . $configArray['name'];
             if (!in_array($table, $tables)) {
                 $queryString = file_get_contents(dirname(__FILE__) . "/phpoai2/doc/oai_records_mysql.sql");
                 $queryString = str_replace('oai_records', $table, $queryString);
                 $query = new GenericSQLQuery();
                 $query->addSQLQuery(SQLUtils::parseSQLString($queryString));
                 $dbc->query($query, $config->getProperty('OAI_DBID'));
             }
         }
         $_SESSION['oai_table_setup_complete'] = true;
     }
     require dirname(__FILE__) . "/phpoai2/oai2.php";
     exit;
 }
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate()
 {
     $dbc = Services::getService("DatabaseManager");
     /*********************************************************
      * Create the new tables
      *********************************************************/
     $type = $dbc->getDatabaseType(IMPORTER_CONNECTION);
     switch ($type) {
         case MYSQL:
             SQLUtils::runSQLfile(MYDIR . "/main/SQL/MySQL/04_SiteThemes.sql", IMPORTER_CONNECTION);
             break;
         case ORACLE:
         case POSTGRESQL:
             SQLUtils::runSQLfile(MYDIR . "/main/SQL/PostgreSQL/04_SiteThemes.sql", IMPORTER_CONNECTION);
             break;
         default:
             throw new Exception("Database schemas are not defined for specified database type.");
     }
     return true;
 }
Example #4
0
 /**
  * Collects the parameters to be used in prepared statement.
  * All the parameters are collected into $this->params and should correspond
  * to the '?' symbols in the given SQL.
  *
  * In case any of the variables where an array, the corresponding '?' symbol
  * in the given SQL clause will be expanded into multiple '?' symbols
  * according to the size of the array.
  *
  * @param string $sql SQL clause
  * @param string $varTypes defines the types of parameters you pass.
  *               @see filter
  * @param string $arg1 the first parameter.
  * @param string $arg2,... the method accepts additional parameters. Number
  *               of arguments should match the length of the string $varTypes.
  * @return string the given SQL clause
  */
 private function collectParams($sql, $varTypes = null, $arg1 = null)
 {
     if ($varTypes) {
         if (func_num_args() - 2 != strlen($varTypes)) {
             throw new IllegalArgumentException("Number of variables must match the length of the varTypes variable: '{$varTypes}'");
         }
         // This map will indicate which of the variables is an array and
         // what its size is.
         $arraySizesMap = array();
         foreach (str_split($varTypes) as $i => $varType) {
             // Get the argument
             $arg = func_get_arg($i + 2);
             // Handle 'array'
             if ($varType == 'a') {
                 if (!is_array($arg)) {
                     throw new IllegalArgumentException("Type of argument number {$i} is expected to be array. Value is {$arg}");
                 }
                 // Add each of the items and their type
                 foreach ($arg as $item) {
                     $this->params['list'][] = $item;
                     $this->params['types'] .= $this->getBindVariableType($item);
                 }
                 // Mark that this arg is an array and keep its size
                 $arraySizesMap[$i] = count($arg);
             } else {
                 if ($varType == 't') {
                     $this->params['list'][] = SQLUtils::convertDate($arg, 'GMT', false);
                     $this->params['types'] .= 's';
                 } else {
                     $this->params['list'][] = $arg;
                     $this->params['types'] .= $varType;
                 }
             }
         }
         // In case of array vars, expand their '?' to a comma-separated list of '?'
         $sql = $this->expandArrayVars($sql, $arraySizesMap);
     }
     return $sql;
 }
Example #5
0
 } else {
     // 		print "<h1>Creating tables and default data set.</h1>";
     /*********************************************************
      * Create the needed database tables
      *********************************************************/
     switch ($dbHandler->getDatabaseType($dbID)) {
         case MYSQL:
             SQLUtils::runSQLdir(HARMONI_BASE . "/SQL/MySQL", $dbID);
             // 				SQLUtils::runSQLdir(MYDIR."/main/SQL/MySQL", $dbID);
             break;
         case POSTGRESQL:
             SQLUtils::runSQLdir(HARMONI_BASE . "/SQL/PostgreSQL", $dbID);
             // 				SQLUtils::runSQLdir(MYDIR."/main/SQL/PostgreSQL", $dbID);
             break;
         case ORACLE:
             SQLUtils::runSQLdir(HARMONI_BASE . "/SQL/PostgreSQL", $dbID);
             // 				SQLUtils::runSQLdir(MYDIR."/main/SQL/PostgreSQL", $dbID);
             break;
         default:
             throw new Exception("Database schemas are not defined for specified database type.");
     }
     /*********************************************************
      * Script for setting up the Authorization Hierarchy
      *********************************************************/
     $hierarchyManager = Services::getService("HierarchyManager");
     $idManager = Services::getService("IdManager");
     // Create the Hierarchy
     $nodeTypes = array();
     $authorizationHierarchyId = $idManager->getId("edu.middlebury.authorization.hierarchy");
     $authorizationHierarchy = $hierarchyManager->createHierarchy("Concerto Qualifier Hierarchy", $nodeTypes, "A Hierarchy to hold all Qualifiers known to Concerto.", TRUE, FALSE, $authorizationHierarchyId);
     // Create nodes for Qualifiers
Example #6
0
 /**
  * Create the cache table.
  * 
  * @return void
  * @access protected
  * @since 7/8/08
  */
 protected function createCacheTable()
 {
     $dbc = Services::getService("DatabaseManager");
     switch ($dbc->getDatabaseType(IMPORTER_CONNECTION)) {
         case MYSQL:
             $dir = dirname(__FILE__) . '/SQL/MySQL';
             break;
         case POSTGRESQL:
         case ORACLE:
             $dir = dirname(__FILE__) . '/SQL/PostgreSQL';
             break;
         default:
             throw new Exception("Database type is not supported.");
     }
     SQLUtils::runSQLdir($dir, IMPORTER_CONNECTION);
 }
Example #7
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;
 }
Example #8
0
 public function secondsToTime($seconds)
 {
     $timeStr = substr(SQLUtils::convertTime($seconds), 1, -1);
     return $timeStr == "null" ? "" : $timeStr;
 }
 /**
  * Get the '?' variable to represent the given field in an 'insert' or
  * 'update' prepapred statement.
  * In most cases, returned value will simply be '?'.
  * In some other cases, additional SQL functions need to be included.
  * 
  * @param SimpleXMLElement $field
  */
 public function getVariableMarkerForPreparedStatement($field)
 {
     switch ($field["type"]) {
         case "GeomPolygon":
         case "GeomPoint":
             return SQLUtils::convertGeom('?');
         default:
             return "?";
     }
 }
Example #10
0
                 continue;
             }
             foreach (scandir($base . '/' . $pluginAuthor) as $plugin) {
                 if (!is_dir($base . '/' . $pluginAuthor . '/' . $plugin)) {
                     continue;
                 }
                 if (file_exists($base . '/' . $pluginAuthor . '/' . $plugin . '/SQL') && is_dir($base . '/' . $pluginAuthor . '/' . $plugin . '/SQL')) {
                     switch ($dbHandler->getDatabaseType($dbID)) {
                         case MYSQL:
                             SQLUtils::runSQLdirWithExceptions($base . '/' . $pluginAuthor . '/' . $plugin . "/SQL/MySQL", $exceptions, $dbID);
                             break;
                         case POSTGRESQL:
                             SQLUtils::runSQLdirWithExceptions($base . '/' . $pluginAuthor . '/' . $plugin . "/SQL/PostgreSQL", $exceptions, $dbID);
                             break;
                         case ORACLE:
                             SQLUtils::runSQLdirWithExceptions($base . '/' . $pluginAuthor . '/' . $plugin . "/SQL/PostgreSQL", $exceptions, $dbID);
                             break;
                         default:
                             throw new Exception("Database schemas are not defined for specified database type.");
                     }
                 }
             }
         }
     }
     $dbHandler->commitTransaction($dbID);
     // Now that we have added our tables, re-run this script and finish installation
     $_SESSION['installation_underway'] = true;
     RequestContext::locationHeader($_SERVER['REQUEST_URI']);
 }
 // 		$dbHandler->beginTransaction($dbID);
 /*********************************************************
Example #11
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;
 }
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate()
 {
     $dbc = Services::getService("DatabaseManager");
     /*********************************************************
      * Create the new tables
      *********************************************************/
     $type = $dbc->getDatabaseType(IMPORTER_CONNECTION);
     switch ($type) {
         case MYSQL:
             SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/MySQL/AuthN_Visitor_Authentication.sql", IMPORTER_CONNECTION);
             break;
         case POSTGRESQL:
         case ORACLE:
             SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/004_AuthN_Visitor_Authentication.sql", IMPORTER_CONNECTION);
             break;
         default:
             throw new Exception("Database schemas are not defined for specified database type.");
     }
     return true;
 }
Example #13
0
     $db->disconnect();
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLInsertQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLUpdateQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLDeleteQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLSelectQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLDatabaseTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLSelectQueryResultTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLInsertQueryResultTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLComprehensiveTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/MySQLConnectionTestCase.class.php');
     break;
 case 'postgresql':
     $dbIndex = $dbc->createDatabase(POSTGRESQL, "localhost", "harmoniTest", "test", "test");
     $dbc->connect($dbIndex);
     // Build our test database
     SQLUtils::runSQLfile(dirname(__FILE__) . "/test_PostgreSQL.sql", $dbIndex);
     $dbc->disconnect($dbIndex);
     // 	// connect to some database and set up our tables
     // 	$dbIndexB = $dbc->createDatabase(POSTGRESQL, "localhost", "harmoniTestB", "test", "test");
     // 	$db->connect($dbIndexB);
     // 	// Build our test database
     // 	SQLUtils::runSQLfile(dirname(__FILE__)."/testB.sql", $dbIndexB);
     // 	$db->disconnect($dbIndexB);
     //
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLDatabaseTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLDeleteQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLUpdateQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLInsertQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLSelectQueryTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLInsertQueryResultTestCase.class.php');
     $test->addTestFile(HARMONI . 'DBHandler/tests/PostgreSQLSelectQueryResultTestCase.class.php');