Beispiel #1
0
 /**
  * Execute
  * 
  * @return void
  * @access public
  * @since 4/3/08
  */
 public function buildContent()
 {
     $db = Harmoni_Db::getDatabase('segue_db');
     printpre(get_class($db));
     // 		$query = $db->select();
     // 		$query->addTable('segue_slot');
     //
     // 		$query->addColumn('*');
     // // 		$query->addColumn('site_id', 'thesite', 'mytablename');
     // //
     // // 		$query->addTable('node', LEFT_JOIN, "site_id = node_id");
     // // 		$subquery = $db->select();
     // // 		$subquery->addTable('type');
     // // 		$subquery->addColumn('*');
     // // 		$query->addDerivedTable($subquery, LEFT_JOIN, "fk_type = mytype.type_id", "mytype");
     //
     // 		$nameKey = $query->addWhereEqual('location_category', 'main');
     // 		var_dump($nameKey);
     //
     // 		$query->addOrderBy('shortname', DESCENDING);
     //
     // 		$query->limitNumberOfRows(5);
     // // 		$query->startFromRow(2);
     //
     // 		printpre(strval($query));
     //
     // 		$stmt = $query->prepare();
     // 		// Execute the query
     // 		$stmt->execute();
     // 		$result = $stmt->fetchAll();
     // 		printpre($result);
     //
     // 		// Execute it again.
     // 		$stmt->bindValue($nameKey, 'main');
     // 		$stmt->execute();
     // 		$result = $stmt->fetchAll();
     // 		printpre($result);
     /*********************************************************
      * Update test
      *********************************************************/
     // 		print "<hr/>";
     // 		$query = $db->update();
     // 		$query->addTable('segue_slot');
     // 		$query->addWhereEqual('shortname', 'simmons');
     // 		$query->addRawValue('media_quota', 'NULL');
     //
     // // 		printpre($query);
     // 		printpre(strval($query));
     // // 		exit;
     //
     // 		$stmt = $query->query();
     // 		$result = $stmt->execute();
     // 		printpre($result);
     /*********************************************************
      * INSERT test
      *********************************************************/
     print "<hr/>";
     $query = $db->insert();
     $query->addTable('test');
     $query->addValue('name', 'ned');
     $query->addValue('color', 'green');
     $query->createRow();
     $query->addValue('name', 'joan');
     $query->addValue('color', 'purple');
     // 		printpre($query);
     // 		printpre(strval($query));
     // 		exit;
     // 		$stmt = $query->query();
     // 		$query = $db->select();
     // 		$query->addTable('test');
     // 		$query->addColumn('*');
     // 		$stmt = $query->query();
     // 		$result = $stmt->fetchAll();
     // 		printpre($result);
     print "\n<h1>The following tests use DBHandler SelectQuery or Harmoni_Db_Select objects</h1>";
     $this->testDbHanderVsHarmoni_Db($db);
     $this->testDbHanderVsHarmoni_Db_fetchAll($db);
     $this->testDbHanderVsHarmoni_Db_preparedSelect($db);
     $this->testDbHanderVsHarmoni_Db_preparedSelectFetchAll($db);
     print "\n<h1>The following tests use string queries rather than the Harmoni_Db_Select objects</h1>";
     $this->testDbHanderVsHarmoni_Db_preparedString($db);
     $this->testSelectWhereEqual($db);
     $this->testSelectWhereEqualJoin($db);
     /*********************************************************
      * Select IN test
      *********************************************************/
     // 		$this->testSelectIN($db);
     /*********************************************************
      * Delete test
      *********************************************************/
     // 		print "<hr/>";
     // 		$query = $db->delete();
     // 		$query->addTable('test');
     // 		$query->addWhereEqual('name', 'adam');
     //
     // // 		printpre($query);
     // 		printpre(strval($query));
     // // 		exit;
     //
     // 		$stmt = $query->query();
     //
     // 		$query = $db->select();
     // 		$query->addTable('test');
     // 		$query->addColumn('*');
     // 		$stmt = $query->query();
     // 		$result = $stmt->fetchAll();
     // 		printpre($result);
 }
 /**
  * Assign the configuration of this Manager. Valid configuration options are as
  * follows:
  *	database_index			integer
  *	database_name			string
  * 
  * @param object Properties $configuration (original type: java.util.Properties)
  * 
  * @throws object OsidException An exception with one of the following
  *		   messages defined in org.osid.OsidException:	{@link
  *		   org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  *		   {@link org.osid.OsidException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.OsidException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link
  *		   org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  * 
  * @access public
  */
 function assignConfiguration(Properties $configuration)
 {
     $this->_configuration = $configuration;
     $dbIndex = $configuration->getProperty('database_index');
     $authzDB = $configuration->getProperty('database_name');
     // ** parameter validation
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     ArgumentValidator::validate($authzDB, StringValidatorRule::getRule(), true);
     // ** end of parameter validation
     // Store the Harmoni_Db adapter if it is configured.
     $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name');
     if (!is_null($harmoni_db_name)) {
         try {
             $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name);
         } catch (UnknownIdException $e) {
         }
     }
     if (isset($this->harmoni_db)) {
         $this->_cache = new AuthZ2_AuthorizationCache($this, $dbIndex, $this->harmoni_db);
     } else {
         $this->_cache = new AuthZ2_AuthorizationCache($this, $dbIndex);
     }
     // do a test to see if our configuration worked.
     try {
         $this->getFunctionTypes();
     } catch (QueryDatabaseException $e) {
         throw new ConfigurationErrorException("Database is not properly set up for AuthZ2.");
     }
 }
 /**
  * Assign the configuration of this OsidManager.
  * 
  * @param object Properties $configuration (original type: java.util.Properties)
  * 
  * @throws object OsidException An exception with one of the following
  *         messages defined in org.osid.OsidException:  {@link
  *         org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  *         {@link org.osid.OsidException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.OsidException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link
  *         org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  * 
  * @access public
  */
 function assignConfiguration(Properties $configuration)
 {
     $this->_configuration = $configuration;
     ArgumentValidator::validate($this->_configuration->getProperty('database_id'), IntegerValidatorRule::getRule());
     // Store the Harmoni_Db adapter if it is configured.
     $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name');
     if (!is_null($harmoni_db_name)) {
         try {
             $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name);
         } catch (UnknownIdException $e) {
         }
     }
     $this->_dbId = $this->_configuration->getProperty('database_id');
     $this->_isInitialized = TRUE;
 }
 /**
  * Assign the configuration of this Manager. Valid configuration options are as
  * follows:
  *	database_index			integer
  *	database_name			string
  * 
  * @param object Properties $configuration (original type: java.util.Properties)
  * 
  * @throws object OsidException An exception with one of the following
  *		   messages defined in org.osid.OsidException:	{@link
  *		   org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  *		   {@link org.osid.OsidException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.OsidException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link
  *		   org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  * 
  * @access public
  */
 function assignConfiguration(Properties $configuration)
 {
     $this->_configuration = $configuration;
     $dbIndex = $configuration->getProperty('database_index');
     $dbName = $configuration->getProperty('database_name');
     // ** parameter validation
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     ArgumentValidator::validate($dbName, StringValidatorRule::getRule(), true);
     // ** end of parameter validation
     $this->_dbIndex = $dbIndex;
     // Store the Harmoni_Db adapter if it is configured.
     $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name');
     if (!is_null($harmoni_db_name)) {
         try {
             $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name);
         } catch (UnknownIdException $e) {
         }
     }
     // do a test to see if our configuration worked.
     try {
         $dbHandler = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addColumn("id");
         $query->addTable("az2_hierarchy");
         $query->limitNumberOfRows(1);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
     } catch (QueryDatabaseException $e) {
         throw new ConfigurationErrorException("Database is not properly set up for AuthZ2.");
     }
 }
Beispiel #5
0
function execute_update(array $types)
{
    if (!array_key_exists($_REQUEST['db_type'], $types)) {
        throw new Exception("Unknown database type, '" . $_REQUEST['db_type'] . "'.");
    }
    switch ($_REQUEST['db_type']) {
        case MYSQL:
            $utilClass = "MySqlUtils";
            break;
        case POSTGRESQL:
            $utilClass = "PostgreSQLUtils";
            break;
        default:
            throw new Exception($types[$_REQUEST['db_type']] . " databases are not currently supported for updates.");
    }
    // Now execute the update.
    $configuration = new ConfigurationProperties();
    $context = new OSIDContext();
    Services::startManagerAsService("DatabaseManager", $context, $configuration);
    $dbc = Services::getService('DBHandler');
    $dbIndex = $dbc->createDatabase($_REQUEST['db_type'], $_REQUEST['db_host'], $_REQUEST['db_name'], $_REQUEST['db_user'], $_REQUEST['db_pass']);
    $dbc->connect($dbIndex);
    // Harmoni_Db
    if ($_REQUEST['use_harmoni_db']) {
        switch ($_REQUEST['db_type']) {
            case MYSQL:
                $dbType = 'Pdo_Mysql';
                break;
            case POSTGRESQL:
                $dbType = 'Pdo_Postgresql';
                break;
            default:
                throw new Exception($types[$_REQUEST['db_type']] . " databases are not currently supported for updates.");
        }
        $db = Harmoni_Db::factory($dbType, array('host' => $_REQUEST['db_host'], 'username' => $_REQUEST['db_user'], 'password' => $_REQUEST['db_pass'], 'dbname' => $_REQUEST['db_name'], 'adapterNamespace' => 'Harmoni_Db_Adapter'));
        Harmoni_Db::registerDatabase('migration_db', $db);
    }
    try {
        $updater = new AuthZ2Updater();
        if ($updater->isInPlace($dbIndex)) {
            print "Update is already in place.";
        } else {
            $updater->runUpdate($dbIndex);
        }
    } catch (Exception $e) {
        // Close our connection
        $dbc->disconnect($dbIndex);
        throw $e;
    }
    $dbc->disconnect($dbIndex);
}
Beispiel #6
0
    ConcertoErrorPrinter::handleException($e, 400);
} catch (PermissionDeniedException $e) {
    ConcertoErrorPrinter::handleException($e, 403);
} catch (UnknownIdException $e) {
    ConcertoErrorPrinter::handleException($e, 404);
} catch (Exception $e) {
    ConcertoErrorPrinter::handleException($e, 500);
}
if (defined('ENABLE_TIMERS') && ENABLE_TIMERS) {
    $execTimer->end();
    $output = ob_get_clean();
    ob_start();
    print "\n<table>\n<tr><th align='right'>Execution Time:</th>\n<td align='right'><pre>";
    printf("%1.6f", $execTimer->printTime());
    print "</pre></td></tr>\n</table>";
    $dbhandler = Services::getService("DBHandler");
    printpre("NumQueries: " . $dbhandler->getTotalNumberOfQueries());
    if (isset($dbhandler->recordQueryCallers) && $dbhandler->recordQueryCallers) {
        print $dbhandler->getQueryCallerStats();
    }
    try {
        $db = Harmoni_Db::getDatabase('concerto_db');
        print "<br/><div>" . $db->getStats() . "</div>";
    } catch (UnknownIdException $e) {
    }
    // 	printpreArrayExcept($_SESSION, array('__temporarySets'));
    // debug::output(session_id());
    // Debug::printAll();
    print "\n\t</body>\n</html>";
    print preg_replace('/<\\/body>\\s*<\\/html>/i', ob_get_clean(), $output);
}
 /**
  * Assign the configuration of this Manager. Valid configuration options are as
  * follows:
  *	database_index			integer
  *	database_name			string
  * 
  * @param object Properties $configuration (original type: java.util.Properties)
  * 
  * @throws object OsidException An exception with one of the following
  *		   messages defined in org.osid.OsidException:	{@link
  *		   org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  *		   {@link org.osid.OsidException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.OsidException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link
  *		   org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  * 
  * @access public
  */
 function assignConfiguration(Properties $configuration)
 {
     $this->_configuration = $configuration;
     $dbIndex = $configuration->getProperty('database_index');
     $authzDB = $configuration->getProperty('database_name');
     // ** parameter validation
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     ArgumentValidator::validate($authzDB, StringValidatorRule::getRule(), true);
     // ** end of parameter validation
     // Store the Harmoni_Db adapter if it is configured.
     $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name');
     if (!is_null($harmoni_db_name)) {
         try {
             $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name);
         } catch (UnknownIdException $e) {
         }
     }
     if (isset($this->harmoni_db)) {
         $this->_cache = new AuthorizationCache($dbIndex, $this->harmoni_db);
     } else {
         $this->_cache = new AuthorizationCache($dbIndex);
     }
 }
Beispiel #8
0
 /**
  * Answer a slot query result for the site id specified
  * 
  * @param string $siteId
  * @return SelectQueryResult or Harmoni_Db_SelectResult
  * @access private
  * @since 4/8/08
  */
 private function getSlotByIdResult_Harmoni_Db($siteId)
 {
     // Look up the slot in the database;
     if (!isset($this->getSlotBySiteId_stmt)) {
         $query = Harmoni_Db::getDatabase('segue_db')->select();
         $query->addTable('segue_slot');
         $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');
         $this->getSlotBySiteId_siteId_key = $query->addWhereEqual('segue_slot.site_id', $siteId);
         $this->getSlotBySiteId_stmt = $query->prepare();
     }
     $this->getSlotBySiteId_stmt->bindParam($this->getSlotBySiteId_siteId_key, $siteId);
     $this->getSlotBySiteId_stmt->execute();
     return $this->getSlotBySiteId_stmt->getResult();
 }
 /**
  * Assign the configuration of this Manager. Valid configuration options are as
  * follows:
  *	database_index			integer
  *	database_name			string
  * 
  * @param object Properties $configuration (original type: java.util.Properties)
  * 
  * @throws object OsidException An exception with one of the following
  *		   messages defined in org.osid.OsidException:	{@link
  *		   org.osid.OsidException#OPERATION_FAILED OPERATION_FAILED},
  *		   {@link org.osid.OsidException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.OsidException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.OsidException#UNIMPLEMENTED UNIMPLEMENTED}, {@link
  *		   org.osid.OsidException#NULL_ARGUMENT NULL_ARGUMENT}
  * 
  * @access public
  */
 function assignConfiguration(Properties $configuration)
 {
     $this->_configuration = $configuration;
     $dbIndex = $configuration->getProperty('database_index');
     $prefix = $configuration->getProperty('id_prefix');
     // ** parameter validation
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     ArgumentValidator::validate($prefix, OptionalRule::getRule(StringValidatorRule::getRule(), true));
     // ** end of parameter validation
     $this->_dbIndex = $dbIndex;
     if ($prefix) {
         $this->_prefix = $prefix;
     }
     $harmoni_db_name = $this->_configuration->getProperty('harmoni_db_name');
     if (!is_null($harmoni_db_name)) {
         try {
             $this->harmoni_db = Harmoni_Db::getDatabase($harmoni_db_name);
             $this->setUpStatements();
         } catch (UnknownIdException $e) {
         }
     }
 }
Beispiel #10
0
    SegueErrorPrinter::handleException($e, 400);
} catch (PermissionDeniedException $e) {
    SegueErrorPrinter::handleException($e, 403);
} catch (UnknownIdException $e) {
    SegueErrorPrinter::handleException($e, 404);
} catch (Exception $e) {
    SegueErrorPrinter::handleException($e, 500);
}
if (defined('ENABLE_TIMERS') && ENABLE_TIMERS) {
    $execTimer->end();
    $output = ob_get_clean();
    ob_start();
    print "\n<table>\n<tr><th align='right'>Execution Time:</th>\n<td align='right'><pre>";
    printf("%1.6f", $execTimer->printTime());
    print "</pre></td></tr>\n</table>";
    $dbhandler = Services::getService("DBHandler");
    printpre("NumQueries: " . $dbhandler->getTotalNumberOfQueries());
    if (isset($dbhandler->recordQueryCallers) && $dbhandler->recordQueryCallers) {
        print $dbhandler->getQueryCallerStats();
    }
    try {
        $db = Harmoni_Db::getDatabase('segue_db');
        print "<br/><div>" . $db->getStats() . "</div>";
    } catch (UnknownIdException $e) {
    }
    // 	printpreArrayExcept($_SESSION, array('__temporarySets'));
    // debug::output(session_id());
    // Debug::printAll();
    print "\n\t</body>\n</html>";
    print preg_replace('/<\\/body>\\s*<\\/html>/i', ob_get_clean(), $output);
}