コード例 #1
0
 /**
  * Constructor.
  * @param object Id $setId The Id of this set.
  * @param integer $dbIndex The index of the database connection which has
  * 		tables in which to store the set.
  */
 function PersistentOrderedSet($setId, $dbIndex)
 {
     parent::OrderedSet($setId);
     ArgumentValidator::validate($dbIndex, IntegerValidatorRule::getRule(), true);
     // Create our internal array
     $this->_dbIndex = $dbIndex;
     // populate our array with any previously stored items.
     $query = new SelectQuery();
     $query->addColumn("item_order", "item_order");
     $query->addColumn("item_id", "item_id");
     $query->addTable("sets");
     $query->addWhere("id = '" . addslashes($this->_setId->getIdString()) . "'");
     $query->addOrderBy("item_order");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $this->_dbIndex);
     $i = 0;
     $oldItems = array();
     while ($result->hasMoreRows()) {
         // Add the items to our array
         $this->_items[$i] = $result->field("item_id");
         // Store an array of the order-key/value relationships to reference
         // when updating any inconsistancies in order numbering.
         $oldItems[$result->field("item_order")] = $result->field("item_id");
         $i++;
         $result->advanceRow();
     }
     $result->free();
     // Make sure that we have our set is filled from 0 to count()
     reset($oldItems);
     $this->_updateOrders($oldItems);
 }
コード例 #2
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;
 }
コード例 #3
0
 /**
  * Since the agent manager package already has support for filtering agents and
  * groups from traversal info iterators, return our search results as traversal
  * info.
  * 
  * @param string $criteria
  * @return TraversalInfoIterator
  * @access protected
  * @since 1/31/08
  */
 protected function getMatching($criteria)
 {
     $dbc = Services::getService('DatabaseManager');
     $idMgr = Services::getService('Id');
     $query = new SelectQuery();
     $query->addTable('agent_properties');
     $query->addColumn("DISTINCT fk_object_id", "agent_id");
     $query->addWhereLike("property_value", str_replace('*', '%', $criteria));
     $info = array();
     $result = $dbc->query($query, $this->databaseIndex);
     while ($result->hasNext()) {
         $row = $result->next();
         if (!strlen($row['agent_id'])) {
             throw new OperationFailedException("No valid agent_id found in row for query: " . $query->asString());
         }
         $info[] = new HarmoniTraversalInfo($idMgr->getId($row['agent_id']), '', 0);
     }
     return new HarmoniTraversalInfoIterator($info);
 }
コード例 #4
0
 /**
  * Will load the data structures for multiple {@link Schema}s.
  * @param ref object An array containing the list of types IDs to be loaded.
  * @return void
  * @access public
  */
 function loadMultiple($preloadTypes)
 {
     $ids = $preloadTypes;
     if (count($ids)) {
         // let's do it
         $query = new SelectQuery();
         $query->addTable("dm_schema_field");
         $query->addColumn("id", "id", "dm_schema_field");
         $query->addColumn("name", "label", "dm_schema_field");
         $query->addColumn("mult", "mult", "dm_schema_field");
         $query->addColumn("required", "required", "dm_schema_field");
         $query->addColumn("active", "active", "dm_schema_field");
         $query->addColumn("fieldtype", "fieldtype", "dm_schema_field");
         $query->addColumn("fk_schema", "fk_schema", "dm_schema_field");
         $wheres = array();
         foreach ($ids as $id) {
             $wheres[] = "fk_schema='" . addslashes($id) . "'";
         }
         $query->setWhere("(" . implode(" OR ", $wheres) . ")");
         //			print "<PRE>".MySQL_SQLGenerator::generateSQLQuery($query)."</PRE>";
         $dbHandler = Services::getService("DatabaseManager");
         $res = $dbHandler->query($query, DATAMANAGER_DBID);
         $rows = array();
         while ($res->hasMoreRows()) {
             $row = $res->getCurrentRow();
             $res->advanceRow();
             $theID = $row["fk_schema"];
             if (!isset($rows[$theID])) {
                 $rows[$theID] = array();
             }
             $rows[$theID][] = $row;
         }
         $res->free();
         //			printpre($rows);
         // now distribute the rows among their respective objects
         foreach (array_keys($rows) as $id) {
             $obj = $this->getSchema($id);
             if (!$obj->loaded()) {
                 $obj->populate($rows[$id]);
             }
         }
     }
 }
コード例 #5
0
 /**
  * Answer the PartStructure Ids for which Tags should be auto-generated, in
  * the given repository.
  * 
  * @param object Id $repositoryId
  * @return object IdIterator
  * @access public
  * @since 11/21/06
  */
 function getPartStructureIdsForTagGeneration($repositoryId)
 {
     if (!isset($this->_cache[$repositoryId->getIdString()])) {
         $this->_cache[$repositoryId->getIdString()] = array();
         $query = new SelectQuery();
         $query->addColumn('fk_partstruct');
         $query->addTable('tag_part_map');
         $query->addWhere("fk_repository ='" . addslashes($repositoryId->getIdString()) . "'");
         $dbc = Services::getService("DatabaseManager");
         $result = $dbc->query($query, $this->getDatabaseIndex());
         // Add tag objects to an array, still sorted by frequency of usage
         $idManager = Services::getService('Id');
         while ($result->hasNext()) {
             $row = $result->next();
             $this->_cache[$repositoryId->getIdString()][] = $idManager->getId($row['fk_partstruct']);
         }
     }
     $iterator = new HarmoniIterator($this->_cache[$repositoryId->getIdString()]);
     return $iterator;
 }
コード例 #6
0
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @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}
  * 
  * @access public
  */
 function updateValue($value)
 {
     ArgumentValidator::validate($value, StringValidatorRule::getRule());
     // Store the size in the object in case its asked for again.
     try {
         $size = ByteSize::fromString($value);
     } catch (InvalidArgumentException $e) {
         $size = ByteSize::withValue(0);
     }
     $this->_size = $size->value();
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // Check to see if the name is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("size"));
         $query->setValues(array("'" . addslashes($this->_size) . "'"));
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->setColumns(array("id", "size"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($this->_size) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
コード例 #7
0
ファイル: test.act.php プロジェクト: adamfranco/polyphony
 /**
  * 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);
     }
 }
コード例 #8
0
 /**
  * Sychronize the cache. Remove any nodes from the cache whose AZs may have 
  * changed.
  * 
  * @return void
  * @access public
  * @since 12/20/05
  */
 function _synchronizeCache()
 {
     $dbHandler = Services::getService("DBHandler");
     foreach (array_keys($_SESSION['__isAuthorizedCacheAgents']) as $agentIdString) {
         // Select the nodeIds who's authorization situation may have changed
         // since the cache was last synchronized. Clear these Ids from the cache.
         $query = new SelectQuery();
         $query->addTable("az2_node");
         $query->setColumns(array("id"));
         $dbDate = $dbHandler->toDBDate($_SESSION['__isAuthorizedCacheTime'][$agentIdString], $this->_configuration->getProperty('database_index'));
         $query->addWhere("last_changed > " . $dbDate);
         // 		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
         $result = $dbHandler->query($query, $this->_configuration->getProperty('database_index'));
         while ($result->hasMoreRows()) {
             unset($_SESSION['__isAuthorizedCache'][$agentIdString][$result->field("id")]);
             $result->advanceRow();
         }
         $result->free();
         $_SESSION['__isAuthorizedCacheTime'][$agentIdString] = DateAndTime::now();
     }
 }
コード例 #9
0
 function _getCourseOffering($can, $term, $courseString)
 {
     //$num = substr($courseString,4,4);
     $number = substr($courseString, 0, strlen($courseString) - 5);
     $termId = $term->getId();
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('cm_offer');
     $query->addWhere("number='" . addslashes($number) . "'");
     $query->addWhere("fk_cm_term='" . addslashes($termId->getIdString()) . "'");
     $query->addColumn('id');
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         $deftype1 = new Type("CourseOfferingType", "edu.middlebury", "LDAP");
         $deftype2 = new Type("CourseOfferingStatusType", "edu.middlebury", "LDAP");
         $deftype3 = new Type("GradeType", "edu.middlebury", "LDAP");
         $offer = $can->createCourseOffering($number, $number, "", $termId, $deftype1, $deftype2, $deftype3);
         //	print "<font size=3 color='red'>#</font>\n";
         return $offer;
     } else {
         //print " ";
         $row = $res->getCurrentRow();
         $cm = Services::getService("CourseManagement");
         $idManager = Services::getService("Id");
         $id = $idManager->getId($row['id']);
         $offer = $cm->getCourseOffering($id);
         //print "<font size=3>#</font>\n";
         return $offer;
     }
 }
コード例 #10
0
ファイル: update.act.php プロジェクト: adamfranco/concerto
 /**
  * Update a record table for a set of harvesters and repositories
  * 
  * @param string $table
  * @param array $allowedRepositoryIdStrings
  * @param array $authGroupIdStrings	The ids of the groups to check view authorization for,
  *	May be one of the following or another group Id string:
  *		edu.middlebury.agents.everyone
  *		edu.middlebury.agents.all_agents
  *	If empty, all assets in the specified repositories will be added regardless of
  *	their visibility.
  *
  * @return void
  * @access public
  * @since 3/9/07
  */
 function updateTable($table, $allowedRepositoryIdStrings, $authGroupIdStrings)
 {
     ArgumentValidator::validate($table, StringValidatorRule::getRule());
     ArgumentValidator::validate($allowedRepositoryIdStrings, ArrayValidatorRuleWithRule::getRule(StringValidatorRule::getRule()));
     ArgumentValidator::validate($authGroupIdStrings, ArrayValidatorRuleWithRule::getRule(StringValidatorRule::getRule()));
     $harmoni = Harmoni::instance();
     $config = $harmoni->getAttachedData('OAI_CONFIG');
     $repositoryManager = Services::getService('Repository');
     $authorizationManager = Services::getService('AuthZ');
     $idManager = Services::getService("IdManager");
     $dbc = Services::getService("DatabaseManager");
     $authGroupIds = array();
     foreach ($authGroupIdStrings as $id) {
         $authGroupIds[] = $idManager->getId($id);
     }
     $baseCheckQuery = new SelectQuery();
     $baseCheckQuery->addTable('oai_' . $table);
     $baseCheckQuery->addColumn('datestamp');
     $baseCheckQuery->addColumn('deleted');
     $baseUpdateQuery = new UpdateQuery();
     $baseUpdateQuery->setTable('oai_' . $table);
     $baseUpdateColumns = array('datestamp', 'deleted', 'oai_set', 'dc_title', 'dc_description');
     $dcUpdateColumns = array('datestamp', 'deleted', 'oai_set', 'dc_title', 'dc_description', 'dc_creator', 'dc_subject', 'dc_contributor', 'dc_publisher', 'dc_date', 'dc_type', 'dc_format', 'dc_identifier', 'dc_source', 'dc_language', 'dc_relation', 'dc_coverage', 'dc_rights');
     $baseInsertQuery = new InsertQuery();
     $baseInsertQuery->setTable('oai_' . $table);
     $baseInsertColumns = array('datestamp', 'oai_identifier', 'deleted', 'oai_set', 'dc_title', 'dc_description');
     $dcInsertColumns = array('datestamp', 'oai_identifier', 'deleted', 'oai_set', 'dc_title', 'dc_description', 'dc_creator', 'dc_subject', 'dc_contributor', 'dc_publisher', 'dc_date', 'dc_type', 'dc_format', 'dc_identifier', 'dc_source', 'dc_language', 'dc_relation', 'dc_coverage', 'dc_rights');
     $baseDeleteQuery = new UpdateQuery();
     $baseDeleteQuery->setTable('oai_' . $table);
     $baseDeleteQuery->addValue('deleted', 'true');
     $baseDeleteQuery->addRawValue('datestamp', 'NOW()');
     $baseUndeleteQuery = new UpdateQuery();
     $baseUndeleteQuery->setTable('oai_' . $table);
     $baseUndeleteQuery->addValue('deleted', 'false');
     $baseUndeleteQuery->addRawValue('datestamp', 'NOW()');
     $forceUpdate = false;
     $repositories = $repositoryManager->getRepositories();
     $r = 0;
     if (count($allowedRepositoryIdStrings)) {
         $numR = count($allowedRepositoryIdStrings);
     } else {
         $numR = $repositories->count();
     }
     $numUpdates = 0;
     $numDeleted = 0;
     $message = _('Updating OAI records for repository (%1 of %2) : ');
     $message = str_replace('%2', $numR, $message);
     $instituteId = $idManager->getId('edu.middlebury.agents.users');
     $viewId = $idManager->getId('edu.middlebury.authorization.view');
     require_once HARMONI . "/utilities/Timer.class.php";
     $timer = new Timer();
     $timer->start();
     $existingRepositoryIds = array();
     while ($repositories->hasNext()) {
         $updatesInRepository = 0;
         $repository = $repositories->next();
         $repositoryId = $repository->getId();
         // Only work with allowed repositories
         if (count($allowedRepositoryIdStrings) && !in_array($repositoryId->getIdString(), $allowedRepositoryIdStrings)) {
             continue;
         }
         $r++;
         $existingRepositoryIds[] = $repositoryId->getIdString();
         $assets = $repository->getAssets();
         $status = new CLIStatusStars(str_replace('%1', $r, $message) . $repository->getDisplayName());
         $status->initializeStatistics($assets->count());
         $existingAssetIds = array();
         while ($assets->hasNext()) {
             $asset = $assets->next();
             $assetId = $asset->getId();
             $existingAssetIds[] = $assetId->getIdString();
             try {
                 $modificationDate = $asset->getModificationDate();
             } catch (UnimplementedException $e) {
                 $modificationDate = DateAndTime::now();
             }
             $query = $baseCheckQuery->copy();
             $query->addWhereEqual("oai_set", $repositoryId->getIdString());
             $query->addWhereEqual("oai_identifier", $assetId->getIdString());
             $result = $dbc->query($query, $config->getProperty('OAI_DBID'));
             if (!$result->getNumberOfRows()) {
                 // 					printpre("Doesn't exist:\t".$asset->getDisplayName()."");
                 $query = $baseInsertQuery->copy();
                 $query->addValue('oai_set', $repositoryId->getIdString());
                 $query->addValue('oai_identifier', $assetId->getIdString());
             } else {
                 // 					printpre("Exists:\t".$asset->getDisplayName()."");
                 if ($modificationDate->isGreaterThan(DateAndTime::fromString($result->field('datestamp'))) || $forceUpdate) {
                     // 						printpre("\tUpdating:\t".$asset->getDisplayName());
                     $query = $baseUpdateQuery->copy();
                     $query->addWhereEqual("oai_set", $repositoryId->getIdString());
                     $query->addWhereEqual("oai_identifier", $assetId->getIdString());
                 } else {
                     $query = null;
                 }
             }
             if ($query) {
                 $query->addRawValue('datestamp', 'NOW()');
             }
             $isCurrentlyDeleted = $result->getNumberOfRows() && $result->field('deleted') == 'true' ? true : false;
             $result->free();
             if (!count($authGroupIds)) {
                 $isVisible = true;
             } else {
                 $isVisible = false;
                 try {
                     foreach ($authGroupIds as $id) {
                         if ($authorizationManager->isAuthorized($id, $viewId, $assetId)) {
                             $isVisible = true;
                             break;
                         }
                     }
                 } catch (UnknownIdException $e) {
                     $isVisible = true;
                 }
             }
             if ($query) {
                 //Add the data fields
                 // Deleted
                 if ($isVisible) {
                     $query->addValue('deleted', 'false');
                 } else {
                     $query->addValue('deleted', 'true');
                 }
                 $query->addValue('dc_title', $asset->getDisplayName());
                 $query->addValue('dc_description', $asset->getDescription());
                 $this->addDublinCoreValues($asset, $query);
                 $dbc->query($query, $config->getProperty('OAI_DBID'));
                 $updatesInRepository++;
                 $numUpdates++;
             } else {
                 if ($isCurrentlyDeleted && $isVisible) {
                     $query = $baseUndeleteQuery->copy();
                 } else {
                     if (!$isCurrentlyDeleted && !$isVisible) {
                         $query = $baseDeleteQuery->copy();
                     } else {
                         $query = null;
                     }
                 }
                 if ($query) {
                     $query->addWhereEqual("oai_set", $repositoryId->getIdString());
                     $query->addWhereEqual("oai_identifier", $assetId->getIdString());
                     $dbc->query($query, $config->getProperty('OAI_DBID'));
                     $updatesInRepository++;
                     $numUpdates++;
                 }
             }
             $status->updateStatistics();
         }
         // Update any missing assets as deleted
         $query = $baseDeleteQuery->copy();
         $query->addWhereEqual("oai_set", $repositoryId->getIdString());
         if (count($existingAssetIds)) {
             $query->addWhereEqual("deleted", "false");
             $query->addWhereNotIn("oai_identifier", $existingAssetIds);
         }
         $result = $dbc->query($query, $config->getProperty('OAI_DBID'));
         if ($result->getNumberOfRows()) {
             $updatesInRepository = $updatesInRepository + $result->getNumberOfRows();
             $numUpdates = $numUpdates + $result->getNumberOfRows();
         }
         print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n";
         print "Elapsed Time:\t";
         $timer->end();
         printf("%1.2f", $timer->printTime());
         print " seconds";
         print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : "";
         print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n";
         print "Updates: " . $updatesInRepository;
         print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : "\n";
     }
     // Update any missing repositories as deleted
     $query = $baseDeleteQuery->copy();
     $query->addWhereEqual("deleted", "false");
     if (count($existingRepositoryIds)) {
         $query->addWhereNotIn("oai_set", $existingRepositoryIds);
     }
     $result = $dbc->query($query, $config->getProperty('OAI_DBID'));
     if ($result->getNumberOfRows()) {
         $updatesInRepository = $updatesInRepository + $result->getNumberOfRows();
         $numUpdates = $numUpdates + $result->getNumberOfRows();
     }
     print OAI_UPDATE_OUTPUT_HTML ? "<pre>" : "\n";
     print "Total Updates:\t" . $numUpdates;
     print OAI_UPDATE_OUTPUT_HTML ? "</pre>" : "\n";
 }
コード例 #11
0
 /**
  * Create a select query with table joins.
  * 
  * @return object SelectQuery
  * @access private
  * @since 3/9/05
  */
 function _createSelectQuery()
 {
     $query = new SelectQuery();
     $query->addTable($this->_mappingTable);
     $query->addTable($this->_typeTable, LEFT_JOIN, $this->_mappingTable . '.fk_type=' . $this->_typeTable . '.id');
     $query->addColumn('agent_id');
     $query->addColumn('token_identifier');
     $query->addColumn('domain');
     $query->addColumn('authority');
     $query->addColumn('keyword');
     $query->addColumn('description');
     return $query;
 }
コード例 #12
0
 /**
  * @return array
  * @param string $type The Schema type to look for.
  * Returns an array of DMRecord IDs that are of the Schema type $type.
  */
 function getRecordIDsByType($type)
 {
     // we're going to get all the IDs that match a given type.
     $query = new SelectQuery();
     $query->addTable("dm_record");
     $query->addTable("dm_schema", INNER_JOIN, "dm_schema.id=dm_record.fk_schema");
     $query->addColumn("id", "", "dm_record");
     $query->setWhere("dm_schema.id='" . addslashes($type) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     if (!$result) {
         throwError(new UnknownDBError("RecordManager"));
         return false;
     }
     $array = array();
     while ($result->hasMoreRows()) {
         $array[] = $result->field(0);
         $result->advanceRow();
     }
     $result->free();
     return $array;
 }
コード例 #13
0
 /**
  * Tests the generateSQLQuery() without WHERE clause.
  */
 function test()
 {
     // insert one row
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array("'Spaceboy'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     $lastId = $result->getLastAutoIncrementValue();
     // insert it again, the id must have increased by one
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 1);
     // add several rows at the same time
     $query->addRowOfValues(array("'Astrogirl'"));
     $result = $this->db->query($query);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 3);
     // now insert in the other test table
     $query = new InsertQuery();
     $query->setTable("test");
     $query->setColumns(array("FK", "value"));
     $query->addRowOfValues(array($lastId, "'Ziggy'"));
     $query->addRowOfValues(array($lastId + 1, "'Lost in the Stars'"));
     $query->addRowOfValues(array($lastId + 2, "'Headstar'"));
     $query->addRowOfValues(array($lastId + 3, "'Stardust'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     // join the inserted rows
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addTable("test", INNER_JOIN, "test.FK = test1.id");
     $query->addColumn("id", "dm86_id", "test");
     $query->addColumn("FK", "dm86_fk", "test");
     $query->addColumn("value", "dm86_value", "test");
     $query->addColumn("id", "dm98_id", "test1");
     $query->addColumn("value", "dm98_value", "test1");
     $query->addWhere("test1.id >= " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 4);
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId);
     $this->assertIdentical($result->field("dm86_value"), "Ziggy");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 1);
     $this->assertIdentical($result->field("dm86_value"), "Lost in the Stars");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 1);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 2);
     $this->assertIdentical($result->field("dm86_value"), "Headstar");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 2);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 3);
     $this->assertIdentical($result->field("dm86_value"), "Stardust");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 3);
     $this->assertIdentical($result->field("dm98_value"), "Astrogirl");
     $result->free();
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array("'I changed you MF!'"));
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->field("value"), "I changed you MF!");
     $result->free();
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 0);
     $result->free();
 }
コード例 #14
0
 /**
  * Answer an array of all of the property keys inexistance
  * 
  * @return array
  * @access public
  * @since 11/1/05
  */
 function getAllPropertyKeys()
 {
     $propertyKeys = array();
     $dbHandler = Services::getService("DBHandler");
     //select the propertykeys
     $query = new SelectQuery();
     $query->addTable("agent_properties");
     $query->addColumn("DISTINCT property_key");
     // 		$query->addTable("type", LEFT_JOIN, "agent_properties.fk_type_id=type.type_id");
     // 		$query->addColumn("property_key");
     // 		$query->addColumn("type_domain");
     // 		$query->addColumn("type_authority");
     // 		$query->addColumn("type_keyword");
     // 		$query->addColumn("type_description");
     $query->addOrderBy("property_key");
     $result = $dbHandler->query($query, $this->_dbIndex);
     while ($result->hasMoreRows()) {
         $propertyKeys[] = $result->field('property_key');
         // 			$propertyKeys[$result->field('property_key')] = new Type(
         // 				$result->field('type_domain'),
         // 				$result->field('type_authority'),
         // 				$result->field('type_keyword'),
         // 				$result->field('type_description'));
         $result->advanceRow();
     }
     $result->free();
     return $propertyKeys;
     //return the properties
 }
コード例 #15
0
 /**
  * Delete the log with the specified name.
  * 
  * @param string $logName
  * 
  * @throws object LoggingException An exception with one of the
  *		   following messages defined in org.osid.logging.LoggingException
  *		   may be thrown:  {@link
  *		   org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.logging.LoggingException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.logging.LoggingException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.logging.LoggingException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  * 
  * @access public
  */
 function deleteLog($logName)
 {
     $log = $this->getLogForWriting($logName);
     $log = null;
     $dbc = Services::getService("DatabaseManager");
     // get the entry Ids
     $query = new SelectQuery();
     $query->addColumn("id");
     $query->addTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $result = $dbc->query($query, $this->_dbIndex);
     $entryIds = array();
     while ($result->hasMoreRows()) {
         $entryIds[] = "'" . addslashes($result->field("id")) . "'";
         $result->advanceRow();
     }
     $result->free();
     // delete the agent keys
     $query = new DeleteQuery();
     $query->setTable("log_agent");
     $query->addWhere("fk_entry IN (" . implode(", ", $entryIds) . ")");
     $dbc->query($query, $this->_dbIndex);
     // delete the node keys
     $query->setTable("log_node");
     $dbc->query($query, $this->_dbIndex);
     // delete the entries
     $query = new DeleteQuery();
     $query->setTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $dbc->query($query, $this->_dbIndex);
 }
コード例 #16
0
ファイル: remote_feed.act.php プロジェクト: adamfranco/segue
 /**
  * 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;
 }
コード例 #17
0
ファイル: Tag.class.php プロジェクト: adamfranco/harmoni
 /**
  * Answer true if the current agent has tagged the item
  * 
  * @param object TaggedItem $item
  * @return boolean
  * @access public
  * @since 11/13/06
  */
 function isItemTagged($item)
 {
     $query = new SelectQuery();
     $query->addColumn('COUNT(*)', 'count');
     $query->addTable('tag');
     $query->addTable('tag_item', INNER_JOIN, "tag.fk_item = tag_item.db_id");
     $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'");
     $query->addWhere("tag.user_id='" . addslashes($this->getCurrentUserIdString()) . "'");
     $query->addWhere("tag_item.id='" . addslashes($item->getIdString()) . "'");
     $query->addWhere("tag_item.system='" . addslashes($item->getSystem()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     if (intval($result->field('count')) > 0) {
         return true;
     } else {
         return false;
     }
 }
コード例 #18
0
 function _getCanonicalCourse($courseString)
 {
     $cm = Services::getService("CourseManagement");
     //$num = substr($courseString,4,4);
     $number = substr($courseString, 0, strlen($courseString) - 5);
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable('cm_can');
     $query->addWhere("number='" . addslashes($number) . "'");
     $query->addColumn('id');
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         //$termType = new Type("Coursemanagement","edu.middlebury",$season);
         //$index = $cm->_typeToIndex('term',$termType);
         $dept = substr($courseString, 0, strlen($courseString) - 9);
         $type = new Type("Coursemanagement", "edu.middlebury", $dept);
         $stattype = new Type("Coursemanagement", "edu.middlebury", "default");
         $can = $cm->createCanonicalCourse($number, $number, "", $type, $stattype, 1);
         print "<font size=4><b>" . $number . "</b> </font>\n";
         return $can;
         //$canId =$can->getId();
         //return $canId->getIdString();
     } else {
         $row = $res->getCurrentRow();
         //$the_index = $row['id'];
         $idManager = Services::getService("Id");
         $id = $idManager->getId($row['id']);
         $can = $cm->getCanonicalCourse($id);
         print "<font size=4>" . $number . " </font>\n";
         return $can;
         //return $the_index;
     }
 }
コード例 #19
0
 /**
  * Answer agentIds that have stored tags
  * 
  * @return object IdIterator
  * @access public
  * @since 11/1/06
  */
 function getAgentIds()
 {
     $query = new SelectQuery();
     $query->addColumn('user_id');
     $query->addColumn('COUNT(user_id)', 'occurances');
     $query->addTable('tag');
     $query->setGroupBy(array('user_id'));
     $query->addOrderBy('occurances', DESCENDING);
     $dbc = Services::getService("DatabaseManager");
     $result = $dbc->query($query, $this->getDatabaseIndex());
     // Add tag objects to an array, still sorted by frequency of usage
     $agentIds = array();
     $idManager = Services::getService('Id');
     while ($result->hasNext()) {
         $row = $result->next();
         $agentIds[] = $idManager->getId($row['user_id']);
     }
     $iterator = new HarmoniIterator($agentIds);
     return $iterator;
 }
コード例 #20
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;
 }
コード例 #21
0
 /**
  * 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() . ")");
     }
 }
コード例 #22
0
 /**
  * Returns a list of the tables that exist in the currently connected database.
  * @return array
  * @access public
  */
 function getTableList()
 {
     $query = new SelectQuery();
     $query->addTable("all_tables");
     $query->addColumn("table_name");
     $res = $this->query($query);
     $list = array();
     while ($res->hasMoreRows()) {
         $list[] = $res->field(0);
         $res->advanceRow();
     }
     $res->free();
     return $list;
 }
コード例 #23
0
ファイル: ThemeImage.class.php プロジェクト: adamfranco/segue
 /**
  * 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']);
 }
コード例 #24
0
ファイル: migration.php プロジェクト: adamfranco/harmoni
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/24/08
  */
 function runUpdate($dbIndex)
 {
     $prepStatus = new StatusStars("Preparing Migration");
     $prepStatus->initializeStatistics(3);
     // Configure the original Hierarchy and AZ services
     $context = new OsidContext();
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("IdManager", $context, $configuration);
     Services::startManagerAsService("HierarchyManager", $context, $configuration);
     Services::startManagerAsService("AuthorizationManager", $context, $configuration);
     // Agent Manager
     $configuration = new ConfigurationProperties();
     // default agent Flavor is one that can be editted
     $agentFlavor = "HarmoniEditableAgent";
     $agentHierarchyId = "edu.middlebury.authorization.hierarchy";
     $configuration->addProperty('hierarchy_id', $agentHierarchyId);
     $configuration->addProperty('defaultAgentFlavor', $agentFlavor);
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("AgentManager", $context, $configuration);
     // :: Set up PropertyManager ::
     //the property manager operates in the same context as the AgentManager and is more or less an adjunct to it
     $configuration->addProperty('database_index', $dbIndex);
     $configuration->addProperty('database_name', $_REQUEST['db_name']);
     Services::startManagerAsService("PropertyManager", $context, $configuration);
     // :: Start the AuthenticationManager OSID Impl.
     $configuration = new ConfigurationProperties();
     $tokenCollectors = array(serialize(new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB")) => new FormActionNamePassTokenCollector('does not exist'));
     $configuration->addProperty('token_collectors', $tokenCollectors);
     Services::startManagerAsService("AuthenticationManager", $context, $configuration);
     // :: Start and configure the AuthenticationMethodManager
     $configuration = new ConfigurationProperties();
     // set up a Database Authentication Method
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseAuthNMethod.class.php";
     require_once HARMONI . "/oki2/agentmanagement/AuthNMethods/SQLDatabaseMD5UsernamePasswordAuthNTokens.class.php";
     $dbAuthType = new Type("Authentication", "edu.middlebury.harmoni", "Harmoni DB");
     $dbMethodConfiguration = new ConfigurationProperties();
     $dbMethodConfiguration->addProperty('tokens_class', 'SQLDatabaseMD5UsernamePasswordAuthNTokens');
     $dbMethodConfiguration->addProperty('database_id', $dbIndex);
     $dbMethodConfiguration->addProperty('authentication_table', 'auth_db_user');
     $dbMethodConfiguration->addProperty('username_field', 'username');
     $dbMethodConfiguration->addProperty('password_field', 'password');
     $propertiesFields = array('username' => 'username');
     $dbMethodConfiguration->addProperty('properties_fields', $propertiesFields);
     $dbAuthNMethod = new SQLDatabaseAuthNMethod();
     $dbAuthNMethod->assignConfiguration($dbMethodConfiguration);
     $configuration->addProperty($dbAuthType, $dbAuthNMethod);
     Services::startManagerAsService("AuthNMethodManager", $context, $configuration);
     // :: Agent-Token Mapping Manager ::
     $configuration = new ConfigurationProperties();
     $configuration->addProperty('database_id', $dbIndex);
     $configuration->addProperty('harmoni_db_name', 'migration_db');
     Services::startManagerAsService("AgentTokenMappingManager", $context, $configuration);
     $prepStatus->updateStatistics();
     $dbc = Services::getService("DatabaseManager");
     try {
         /*********************************************************
          * Check for the old tables. They must exist for us to run
          *********************************************************/
         $azTables = array('az_authorization', 'az_function', 'hierarchy', 'j_node_node', 'node', 'node_ancestry');
         // Check for old tables
         $tables = $dbc->getTableList($dbIndex);
         foreach ($azTables as $table) {
             if (!in_array($table, $tables)) {
                 throw new Exception("Old AZ table, {$table}, is missing. Can not run Update.");
             }
         }
         /*********************************************************
          * Create the new tables
          *********************************************************/
         $type = $dbc->getDatabaseType($dbIndex);
         switch ($type) {
             case MYSQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/MySQL/AuthZ2.sql", $dbIndex);
                 break;
             case POSTGRESQL:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             case ORACLE:
                 SQLUtils::runSQLfile(HARMONI_BASE . "/SQL/PostgreSQL/AuthZ2.sql", $dbIndex);
                 break;
             default:
                 throw new Exception("Database schemas are not defined for specified database type.");
         }
         /*********************************************************
          * Hierarchy
          *********************************************************/
         $hierarchyMgr1 = Services::getService("Hierarchy");
         if (get_class($hierarchyMgr1) == "AuthZ2_HierarchyManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $hierarchyMgr2 = new AuthZ2_HierarchyManager();
         $azMgr2 = new AuthZ2_AuthorizationManager();
         $azMgr2->setHierarchyManager($hierarchyMgr2);
         $hierarchyMgr2->assignConfiguration($hierarchyMgr1->_configuration);
         /*********************************************************
          * Authorization
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         $azMgr2->assignConfiguration($azMgr1->_configuration);
         $prepStatus->updateStatistics();
         /*********************************************************
          * Hierarchies
          *********************************************************/
         $hierarchies = $hierarchyMgr1->getHierarchies();
         $prepStatus->updateStatistics();
         while ($hierarchies->hasNext()) {
             $hierarchy = $hierarchies->next();
             try {
                 $newHierarchy = $hierarchyMgr2->getHierarchy($hierarchy->getId());
             } catch (UnknownIdException $e) {
                 $newHierarchy = $hierarchyMgr2->createHierarchy($hierarchy->getDisplayName(), array(), $hierarchy->getDescription(), $hierarchy->allowsMultipleParents(), $hierarchy->allowsRecursion(), $hierarchy->getId());
             }
             $query = new SelectQuery();
             $query->addTable("node");
             $query->addColumn("COUNT(*)", "num");
             $query->addWhereEqual("fk_hierarchy", $hierarchy->getId()->getIdString());
             $dbc = Services::getService("DatabaseManager");
             $result = $dbc->query($query);
             $this->nodeStatus = new StatusStars("Migrating nodes in the '" . $hierarchy->getDisplayName() . "' Hierarchy.");
             $this->nodeStatus->initializeStatistics($result->field("num"));
             // Add all of the nodes
             $nodes = $hierarchy->getRootNodes();
             while ($nodes->hasNext()) {
                 $this->addNode($newHierarchy, $nodes->next());
             }
         }
         /*********************************************************
          * Authorizations
          *********************************************************/
         $azMgr1 = Services::getService("AuthZ");
         if (get_class($hierarchyMgr1) == "AuthZ2_AuthorizationManager") {
             throw new OperationFailedException("Original HierarchyManager not configured.");
         }
         // Add all of the Authorization functions
         $functionTypes = $azMgr1->getFunctionTypes();
         while ($functionTypes->hasNext()) {
             $oldFunctions = $azMgr1->getFunctions($functionTypes->next());
             while ($oldFunctions->hasNext()) {
                 $oldFunction = $oldFunctions->next();
                 // Get or create the function
                 try {
                     $newFunction = $azMgr2->getFunction($oldFunction->getId());
                 } catch (UnknownIdException $e) {
                     $newFunction = $azMgr2->createFunction($oldFunction->getId(), $oldFunction->getReferenceName(), $oldFunction->getDescription(), $oldFunction->getFunctionType(), $oldFunction->getQualifierHierarchyId());
                 }
                 // Get all authorizations for this function.
                 $oldAZs = $azMgr1->getExplicitAZs(null, $oldFunction->getId(), null, false);
                 $status = new StatusStars("Migrating '" . $newFunction->getReferenceName() . "' Authorizations (" . $oldAZs->count() . ")");
                 $status->initializeStatistics($oldAZs->count());
                 while ($oldAZs->hasNext()) {
                     $oldAZ = $oldAZs->next();
                     $status->updateStatistics();
                     try {
                         $oldQualifier = $oldAZ->getQualifier();
                     } catch (UnknownIdException $e) {
                         // continue if the qualifier no longer exists.
                         continue;
                     }
                     // Add the new authorization
                     try {
                         $newAZ = $azMgr2->createAuthorization($oldAZ->getAgentId(), $oldAZ->getFunction()->getId(), $oldQualifier->getId());
                         if ($oldAZ->getExpirationDate()) {
                             $newAZ->updateExpirationDate($oldAZ->getExpirationDate());
                         }
                         if ($oldAZ->getEffectiveDate()) {
                             $newAZ->updateEffectiveDate($oldAZ->getEffectiveDate());
                         }
                     } catch (OperationFailedException $e) {
                     }
                 }
             }
         }
     } catch (Exception $e) {
         printpre($e->getMessage());
         HarmoniErrorHandler::printDebugBacktrace($e->getTrace());
         printpre("An error has occurred. Removing new tables.");
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_implicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_explicit_az');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_ancestry');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_j_node_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_function_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_node_type');
         } catch (DatabaseException $e) {
         }
         try {
             $query = new GenericSQLQuery('TRUNCATE az2_hierarchy');
         } catch (DatabaseException $e) {
         }
         $query = new GenericSQLQuery('DROP TABLE az2_implicit_az, az2_explicit_az, az2_function, az2_function_type, az2_node_ancestry, az2_j_node_node, az2_node, az2_node_type,  az2_hierarchy;');
         $dbc->query($query, $dbIndex);
         return false;
     }
     /*********************************************************
      * If we have successfully gotten this far, drop the old 
      * hierarchy and AuthZ tables to prevent confusion.
      *********************************************************/
     $query = new GenericSQLQuery('DROP TABLE az_authorization, az_function, hierarchy, j_node_node, node, node_ancestry;');
     $dbc->query($query, $dbIndex);
     print "Success!";
     return true;
 }
コード例 #25
0
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @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}
  * 
  * @access public
  */
 function updateValue($value)
 {
     //		ArgumentValidator::validate($value, StringValidatorRule::getRule());
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the row if we are setting the value to null
     if (is_null($value)) {
         $query = new DeleteQuery();
         $query->setTable("dr_file_data");
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         $this->_asset->updateModificationDate();
         return;
     }
     // Store the data in the object in case its asked for again.
     //		$this->_data = $value;
     // Make sure that the dr_file row is inserted.
     $query = new InsertQuery();
     $query->setTable("dr_file");
     $query->addValue("id", $this->_recordId->getIdString());
     try {
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     } catch (QueryDatabaseException $e) {
         // If an error is thrown inserting (because the file already exists)
         // ignore it.
     }
     $dbHandler->beginTransaction($this->_configuration->getProperty("database_index"));
     // Base64 encode the data to preserve it,
     // then write it to the database.
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_data");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("data"));
         $query->setValues(array("'" . base64_encode($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("fk_file", "data"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . base64_encode($value) . "'"));
     }
     $result->free();
     //		printpre($query);
     //		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // Update the size row.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->addValue("size", strval(strlen($value)));
     $query->addWhereEqual("id", $this->_recordId->getIdString());
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $dbHandler->commitTransaction($this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
コード例 #26
0
 /**
  * Loads dates from the database and sets the _datesInDB flag
  * 
  * @return void
  * @access public
  * @since 8/10/04
  */
 function _loadDates()
 {
     $dbHandler = Services::getService("DatabaseManager");
     // Get the content DataSet.
     $id = $this->_node->getId();
     $query = new SelectQuery();
     $query->addTable("dr_asset_info");
     $query->addColumn("effective_date");
     $query->addColumn("expiration_date");
     $query->addColumn("create_timestamp");
     $query->addColumn("creator");
     $query->addColumn("modify_timestamp");
     $query->addWhere("asset_id='" . $id->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_dbIndex);
     // If we have stored dates for this asset set them
     if ($result->getNumberOfRows()) {
         $this->_effectiveDate = $dbHandler->fromDBDate($result->field("effective_date"), $this->_dbIndex);
         $this->_expirationDate = $dbHandler->fromDBDate($result->field("expiration_date"), $this->_dbIndex);
         $this->_createDate = $dbHandler->fromDBDate($result->field("create_timestamp"), $this->_dbIndex);
         $this->_creator = $result->field("creator");
         $this->_modifyDate = $dbHandler->fromDBDate($result->field("modify_timestamp"), $this->_dbIndex);
         $this->_datesInDB = TRUE;
         if (!$this->_createDate) {
             $this->_createDate = DateAndTime::epoch();
         }
         if (!$this->_modifyDate) {
             $this->_modifyDate = DateAndTime::epoch();
         }
     } else {
         $this->_effectiveDate = NULL;
         $this->_expirationDate = NULL;
         $this->_createDate = DateAndTime::epoch();
         $this->_modifyDate = DateAndTime::epoch();
         $this->_creator = NULL;
         $this->_datesInDB = FALSE;
     }
     $result->free();
 }
コード例 #27
0
ファイル: SiteTheme.class.php プロジェクト: adamfranco/segue
 /**
  * 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;
 }
コード例 #28
0
 /**
  * Answer the Hierarchy-based parent-group for an external group Id.
  * 
  * @param array $groupIds An array of Ids
  * @return array an array of parent group Ids
  * @access public
  * @since 11/6/07
  */
 public function getHierarchyParentIdsForExternalGroups(array $groupIds)
 {
     if (!count($groupIds)) {
         return array();
     }
     $query = new SelectQuery();
     $query->addTable('agent_external_children');
     $query->addColumn('DISTINCT fk_parent', 'parent');
     // Before PHP 5.2.0, __toString() was only called automatically
     // in print() statements, not in concatinations.
     if (version_compare(phpversion(), '5.2.0', '<')) {
         foreach ($groupIds as $key => $val) {
             if (is_object($val)) {
                 $groupIds[$key] = $val->__toString();
             }
         }
     }
     $query->addWhereIn('fk_child', $groupIds);
     $dbc = Services::getService("DBHandler");
     $result = $dbc->query($query, $this->_configuration->getProperty('database_index'));
     $idMgr = Services::getService("Id");
     $parents = array();
     while ($result->hasMoreRows()) {
         $parents[] = $idMgr->getId($result->field('parent'));
         $result->advanceRow();
     }
     return $parents;
 }
コード例 #29
0
 /**
  * Do a single query to load all of the small-valued parts for the record;
  * that is, everything but the file and thumb data.
  * 
  * @return void
  * @access private
  * @since 11/17/05
  */
 function _loadParts()
 {
     if ($this->_partsLoaded) {
         return;
     }
     $dbHandler = Services::getService("DBHandler");
     $query = new SelectQuery();
     $query->addTable("dr_file");
     $query->addTable("dr_file_url", LEFT_JOIN, "dr_file.id = dr_file_url.fk_file");
     $query->addTable("dr_thumbnail", LEFT_JOIN, "dr_file.id = dr_thumbnail.fk_file");
     $query->addTable("dr_mime_type", LEFT_JOIN, "dr_file.fk_mime_type = file_mime_type.id", "file_mime_type");
     $query->addTable("dr_mime_type", LEFT_JOIN, "dr_thumbnail.fk_mime_type = thumbnail_mime_type.id", "thumbnail_mime_type");
     $query->addColumn("filename");
     $query->addColumn("size");
     $query->addColumn("dr_file.width", "file_width");
     $query->addColumn("dr_file.height", "file_height");
     $query->addColumn("dr_file_url.url", "url");
     $query->addColumn("file_mime_type.type", "file_type");
     $query->addColumn("thumbnail_mime_type.type", "thumbnail_type");
     $query->addColumn("dr_thumbnail.width", "thumb_width");
     $query->addColumn("dr_thumbnail.height", "thumb_height");
     $query->addWhere("dr_file.id = '" . $this->_id->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     if ($result->getNumberOfRows()) {
         $this->_parts['FILE_NAME']->_updateValue($result->field('filename'));
         $this->_parts['FILE_URL']->_updateValue($result->field('url'));
         $this->_parts['FILE_SIZE']->_updateValue($result->field('size'));
         $this->_parts['MIME_TYPE']->_updateValue($result->field('file_type'));
         $this->_parts['DIMENSIONS']->_updateValue(array($result->field('file_width'), $result->field('file_height')));
         $this->_parts['THUMBNAIL_MIME_TYPE']->_updateValue($result->field('thumbnail_type'));
         $this->_parts['THUMBNAIL_DIMENSIONS']->_updateValue(array($result->field('thumb_width'), $result->field('thumb_height')));
     }
     $this->_partsLoaded = true;
 }
コード例 #30
0
 /**
  * Populate the info for this item
  * 
  * @return void
  * @access public
  * @since 11/8/06
  */
 function _loadInfo()
 {
     if (!isset($this->_displayName) || !isset($this->_description)) {
         $query = new SelectQuery();
         $query->addColumn('db_id');
         $query->addColumn('display_name');
         $query->addColumn('description');
         $query->addTable('tag_item');
         $query->addWhere("id='" . addslashes($this->getIdString()) . "'");
         $dbc = Services::getService("DatabaseManager");
         $result = $dbc->query($query, $this->getDatabaseIndex());
         $this->_dbId = intval($result->field('db_id'));
         $this->_displayName = $result->field('display_name');
         $this->_description = $result->field('description');
     }
 }