/** * Inserts a new row into the Database with the data contained in the object. * @param integer $dbID The {@link DBHandler} database ID to query. * @access public * @return integer Returns the new ID of the data stored. */ function insert($dbID) { $idManager = Services::getService("Id"); $newID = $idManager->createId(); $query = new InsertQuery(); $query->setTable($this->_table); $query->setColumns(array("id", "data")); $query->addRowOfValues(array("'" . addslashes($newID->getIdString()) . "'", "'" . addslashes($this->asString()) . "'")); $dbHandler = Services::getService("DatabaseManager"); $result = $dbHandler->query($query, $dbID); if (!$result || $result->getNumberOfRows() != 1) { throwError(new UnknownDBError("StorableString")); return false; } return $newID->getIdString(); }
/** * Takes a {@link DMRecord} and an optional date and creates a {@link RecordTag} in the database based * on the current active versions of values within the {@link DMRecord}. * @param ref object $record The {@link DMRecord} to be tagged. * @param optional object $date An optional {@link DateAndTime} object to attach to the tag instead of the current date/time. * @return int The new tag's ID in the database. * @access public */ function tagRecord($record, $date = null) { // if the dataset is not versionControlled, there's no point in tagging if (!$record->isVersionControlled()) { return null; } $id = $record->getID(); if (!$date) { $date = DateAndTime::now(); } // spider through the record and get the IDs of the active versions. $ids = array(); $schema = $record->getSchema(); foreach ($schema->getAllIDs() as $id) { $values = $record->getRecordFieldValues($id); foreach (array_keys($values) as $key) { if ($values[$key]->hasActiveValue()) { $actVer = $values[$key]->getActiveVersion(); $ids[] = $actVer->getID(); } } } // now let's dump it all to the DB $query = new InsertQuery(); $query->setTable("dm_tag"); $query->setColumns(array("id", "fk_record", "date")); $idManager = Services::getService("Id"); $dbHandler = Services::getService("DBHandler"); $newID = $idManager->createId(); $query->addRowOfValues(array($newID->getIdString(), $id, $dbHandler->toDBDate($date, DATAMANAGER_DBID))); $query2 = new InsertQuery(); $query2->setTable("dm_tag_map"); $query2->setColumns(array("fk_tag", "fk_record_field")); foreach ($ids as $id) { $query2->addRowOfValues(array("'" . addslashes($newID->getIdString()) . "'", $id)); } $result = $dbHandler->query($query, DATAMANAGER_DBID); $result2 = $dbHandler->query($query2, DATAMANAGER_DBID); if (!$result || !$result2) { throwError(new UnknownDBError("RecordTagManager")); } // we're done. return $newID->getIdString(); }
/** * Write the cache * * @return void * @access public * @since 2/13/06 */ function writeCache() { $dbc = Services::getService('DatabaseManager'); $query = new DeleteQuery(); $query->setTable('dr_resized_cache'); $query->addWhere("dr_resized_cache.fk_file = '" . addslashes($this->_id->getIdString()) . "'"); $query->addWhere("dr_resized_cache.size = '" . addslashes($this->_size) . "'"); $query->addWhere("dr_resized_cache.websafe = " . ($this->_websafe ? '1' : '0')); $dbc->query($query, $this->getDBIndex()); $query = new InsertQuery(); $query->setTable('dr_resized_cache'); $query->setColumns(array('fk_file', 'size', 'websafe', 'cache_time', 'fk_mime_type', 'data')); $values = array(); $values[] = "'" . addslashes($this->_id->getIdString()) . "'"; $values[] = "'" . addslashes($this->_size) . "'"; $values[] = $this->_websafe ? '1' : '0'; $values[] = "NOW()"; $imgProcessor = Services::getService("ImageProcessor"); if ($this->_websafe) { $this->_mimeType = $imgProcessor->getWebsafeFormat($this->_parts['MIME_TYPE']->getValue()); $values[] = $this->getMimeKey(); $values[] = "'" . addslashes($imgProcessor->getWebsafeData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'"; } else { $this->_mimeType = $imgProcessor->getResizedFormat($this->_parts['MIME_TYPE']->getValue()); $values[] = $this->getMimeKey(); $values[] = "'" . addslashes($imgProcessor->getResizedData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'"; } $query->addRowOfValues($values); $dbc->query($query, $this->getDBIndex()); }
/** * Attempts to commit our {@link DMRecord}s to the database and update our mapping. * @param boolean optional $ignoreMandatory If true, doesn't fail if mandatory * fields don't have values. * @return void */ function commit($ignoreMandatory = false) { $ids = array(); if (count($this->_records)) { for ($i = 0; $i < count($this->_records); $i++) { $this->_records[$i]->commit($ignoreMandatory); $ids[] = $this->_records[$i]->getID(); } $this->_records = array(); $this->_fetchMode = -1; } if ($this->_dirty) { // syncrhonize the database $ids = array_merge($ids, $this->_storedRecordIDs); // Make sure that we only have one ID for each record. $ids = array_unique($ids); $dbHandler = Services::getService("DatabaseManager"); // first delete all the old mappings $query = new DeleteQuery(); $query->setTable("dm_record_set"); $query->setWhere("dm_record_set.id='" . addslashes($this->_myID) . "'"); // printpre(MySQL_SQLGenerator::generateSQLQuery($query)); $dbHandler->query($query, DATAMANAGER_DBID); if (count($ids)) { // next insert all our mappings back in. $query = new InsertQuery(); $query->setTable("dm_record_set"); $query->setColumns(array("id", "fk_record")); foreach ($ids as $id) { $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($id) . "'")); if (!in_array($id, $this->_storedRecordIDs)) { $this->_storedRecordIDs[] = $id; } } // printpre(MySQL_SQLGenerator::generateSQLQuery($query)); $dbHandler->query($query, DATAMANAGER_DBID); // done! } } }
/** * Commits any changes that have been made to the database. If neither update() nor prune() have been * called, even if changes have been made, they will not be reflected in the database. * @return bool * @access public */ function commit() { $dbHandler = Services::getService("DatabaseManager"); if ($this->_update) { // let's re-cast our primitive to a storablePrimitive $this->recastAsStorable(); // first we need to commit the actual Primitive value // so that we can get its ID if (!$this->_dataID) { $this->_dataID = $this->_primitive->insert(DATAMANAGER_DBID); } else { $this->_primitive->update(DATAMANAGER_DBID, $this->_dataID); } $this->_date = DateAndTime::now(); if ($this->_myID) { // we're already in the DB. just update the entry $query = new UpdateQuery(); $query->setWhere("id='" . addslashes($this->_myID) . "'"); $query->setColumns(array("value_index", "active", "modified")); $query->setValues(array($this->_parent->getIndex(), $this->_active ? 1 : 0, $dbHandler->toDBDate($this->_date, DATAMANAGER_DBID))); } else { // we have to insert a new one $query = new InsertQuery(); $idManager = Services::getService("Id"); $newID = $idManager->createId(); $this->_myID = $newID->getIdString(); $query->setColumns(array("id", "fk_record", "fk_schema_field", "value_index", "fk_data", "active", "modified")); $schema = $this->_parent->_parent->_parent->getSchema(); $schemaField = $this->_parent->_parent->getSchemaField(); $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($this->_parent->_parent->_parent->getID()) . "'", "'" . addslashes($schemaField->getID()) . "'", $this->_parent->getIndex(), "'" . addslashes($this->_dataID) . "'", $this->_active ? 1 : 0, $dbHandler->toDBDate($this->_date, DATAMANAGER_DBID))); } $query->setTable("dm_record_field"); $result = $dbHandler->query($query, DATAMANAGER_DBID); if (!$result) { throwError(new UnknownDBError("DMRecord")); return false; } } if ($this->_prune && $this->_dataID) { if ($id = $this->getID()) { // ok, let's get rid of ourselves... completely! $query = new DeleteQuery(); $query->setTable("dm_record_field"); $query->setWhere("id='" . addslashes($id) . "'"); $res = $dbHandler->query($query, DATAMANAGER_DBID); if (!$res) { throwError(new UnknownDBError("DMRecord")); } // now tell the data object to prune itself $this->recastAsStorable(); $this->_primitive->prune(DATAMANAGER_DBID, $this->_dataID); // and we have to get rid of any tag mappings where we are included. $query = new DeleteQuery(); $query->setTable("dm_tag_map"); $query->setWhere("fk_record_field='" . addslashes($id) . "'"); $res = $dbHandler->query($query, DATAMANAGER_DBID); if (!$res) { throwError(new UnknownDBError("DMRecord")); } } } // reset the prune flag $this->_prune = false; // reset the update flag $this->_update = false; return true; }
/** * Add a Topic for this CanonicalCourse. * * @param string $topic * * @throws object CourseManagementException An exception * with one of the following messages defined in * org.osid.coursemanagement.CourseManagementException may be * thrown: {@link * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED * ALREADY_ADDED} * * @access public */ function addTopic($topic) { $dbManager = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable('cm_topics'); $query->addWhere("fk_cm_can='" . $this->_id->getIdString() . "'"); $query->addWhere("topic='" . addslashes($topic) . "'"); //not really needed, but it keeps this from crashing. $query->addColumn('topic'); $res = $dbManager->query($query); if ($res->getNumberOfRows() == 0) { $query = new InsertQuery(); $query->setTable('cm_topics'); $values[] = "'" . addslashes($this->_id->getIdString()) . "'"; $values[] = "'" . addslashes($topic) . "'"; $query->setColumns(array('fk_cm_can', 'topic')); $query->addRowOfValues($values); $result = $dbManager->query($query); } elseif ($res->getNumberOfRows() == 1) { //do nothing } else { print "\n<b>Warning!<\\b> The Topic with course " . $this->getDisplayName() . " and description " . $topic . " is not unique--there are " . $res->getNumberOfRows() . " copies.\n"; } }
/** * Create a new unique identifier. * * @return object Id * * @throws object IdException An exception with one of the following * messages defined in org.osid.id.IdException: {@link * org.osid.id.IdException#OPERATION_FAILED OPERATION_FAILED}, * {@link org.osid.id.IdException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.id.IdException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.id.IdException#UNIMPLEMENTED UNIMPLEMENTED} * * @access public */ function createId() { if (isset($this->createId_stmt)) { $this->createId_stmt->execute(); $newID = $this->harmoni_db->lastInsertId('id', 'id_value'); $this->deleteId_stmt->bindValue(1, $newID); $this->deleteId_stmt->execute(); } else { debug::output("Attempting to generate new id.", 20, "IdManager"); $dbHandler = Services::getService("DatabaseManager"); $query = new InsertQuery(); $query->setAutoIncrementColumn("id_value", "id_id_value_seq"); $query->setTable("id"); $query->addRowOfValues(array()); $result = $dbHandler->query($query, $this->_dbIndex); if ($result->getNumberOfRows() != 1) { throwError(new Error(IdException::CONFIGURATION_ERROR(), "IdManager", true)); } $newID = $result->getLastAutoIncrementValue(); // Clear out any values smaller than our last one to keep the table from // exploding size. $query = new DeleteQuery(); $query->setTable("id"); $query->setWhere("id_value < '" . $newID . "'"); $result = $dbHandler->query($query, $this->_dbIndex); } $newID = $this->_prefix . strval($newID); debug::output("Successfully created new id '{$newID}'.", DEBUG_SYS5, "IdManager"); $id = new HarmoniId($newID); // cache the id // $this->_ids[$newID] = $id; return $id; }
/** * Installs a plugin * * @param object HarmoniType $type gives us the location of plugin to be * installed * @access public * @since 3/6/06 */ function installPlugin($type) { // @todo deal with new plugin readiness structure, and database tables $authZ = Services::getService("AuthZ"); // if ($authZ->isUserAuthorized("edu.middlebury.authorization.add_children", ??)) { $dr = Services::getService("Repository"); $dm = Services::getService("DataTypeManager"); $db = Services::getService("DBHandler"); $id = Services::getService("Id"); // a few things we need $site_rep = $dr->getRepository($id->getId("edu.middlebury.segue.sites_repository")); $pluginDir = $this->getConfiguration('plugin_dir'); $types = $dm->getRegisteredTypes(); // for partstructures // use the plugin type to get through the filesystem $domain = $type->getDomain(); $authority = $type->getAuthority(); $keyword = $type->getKeyword(); $description = "The type for a {$domain} {$authority} {$keyword} plugin."; // write the type to the database $query = new InsertQuery(); $query->setTable('plugin_type'); $query->setColumns(array("type_domain", "type_authority", "type_keyword", "type_description", "type_enabled")); $query->addRowOfValues(array("'" . addslashes($domain) . "'", "'" . addslashes($authority) . "'", "'" . addslashes($keyword) . "'", "'" . addslashes($description) . "'", '0')); $db->query($query, IMPORTER_CONNECTION); // grab the xml file $xmlFile = $pluginDir . "/" . $domain . "/" . $authority . "/" . $keyword . "/" . $authority . $keyword . "Plugin.xml"; // if there is no file then the plugin has no data structures if (is_file($xmlFile)) { $document = new DOMDocument(); $document->loadXML($xmlFile); $recordStructures = $document->documentElement->childNodes; // first create the recordstructure(s) foreach ($recordStructures as $rs) { if ($rs->hasAttribute("name")) { $rsName = $rs->getAttribute("name"); $plugStruct = $site_rep->createRecordStructure($rsName, "This is the {$rsName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", "", ""); $pSId = $plugStruct->getId(); $partStructures = $rs->childNodes; // now create the partstructure(s) foreach ($partStructures as $ps) { if ($ps->hasAttribute("name") && $ps->hasAttribute("type")) { $psName = $ps->getAttribute("name"); $psType = $ps->getAttribute("type"); if (in_array($psType, $types)) { $plugStruct->createPartStructure($psName, "This is the {$psName} structure for holding data of the {$domain} {$authority} {$keyword} plugin", new Type("Repository", "edu.middlebury.segue", $psType), false, true, false); } } } // write to the DB the plugin and its structures $typeId = null; $query2 = new SelectQuery(); $query2->addTable("plugin_type"); $query2->addColumn("*"); $query2->addWhere("type_domain = '" . addslashes($domain) . "'"); $query2->addWhere("type_authority = '" . addslashes($authority) . "'"); $query2->addWhere("type_keyword = '" . addslashes($keyword) . "'"); $results = $db->query($query2, IMPORTER_CONNECTION); if ($results->getNumberOfRows() == 1) { $result = $results->next(); $typeId = $result['type_id']; $results->free(); $query3 = new InsertQuery(); $query3->setTable("plugin_manager"); $query3->setColumns(array("fk_plugin_type", "fk_schema")); $query3->addRowOfValues(array("'" . addslashes($typeId) . "'", "'" . addslashes($pSId->getIdString()) . "'")); $db->query($query3, IMPORTER_CONNECTION); } else { $results->free(); throwError(new Error("PluginType not found", "Plugins", false)); } } } } if (!in_array($type->asString(), array_keys($this->getInstalledPlugins()))) { $this->addPluginToArray($type); } // } }
/** * Does what is necessary to the temporary table for internal id association * * @access public * @since 10/6/05 */ function doIdMatrix() { $dbHandler = Services::getService("DBHandler"); // $dbIndexConcerto =$dbHandler->addDatabase(new // MySQLDatabase("localhost", "whitey_concerto", "test", "test")); $query = new InsertQuery(); $query->setTable("xml_id_matrix"); $query->setColumns(array("xml_id", "conc_id")); $xmlid = $this->_node->getAttribute("xml:id"); $query->addRowOfValues(array("'" . addslashes($xmlid) . "'", "'" . addslashes($this->_myId->getIdString()) . "'")); //$dbHandler->connect($dbIndexConcerto); $dbHandler->query($query, IMPORTER_CONNECTION); }
/** * Reflects any changes made locally to the database. * @param optional int $id The ID in the database to update (if not adding...). * @return int Returns our ID in the database or NULL upon error. * @access public */ function commit($id = null) { if (!$this->_schema->getID() || !$this->_addToDB && !$id) { // we have no ID, we probably can't commit...unless we're going to be added to the DB. // we'll also fail if our dataSetTypeDef doesn't have an ID. that meaning it wasn't meant to be // synchronized into the database. throwError(new Error("Could not commit() to database because either: 1) we don't have a local ID, \n\t\t\tmeaning we were not meant to be synchronized with the database, or 2) the Schema to which we \n\t\t\tbelong is not linked with the database. (label: " . $this->_label . ", schema name: " . $this->_schema->getDisplayName() . ")", "DataManager", true)); return null; } $dbHandler = Services::getService("DatabaseManager"); if ($this->_addToDB) { $query = new InsertQuery(); $query->setTable("dm_schema_field"); $query->setColumns(array("id", "fk_schema", "name", "mult", "fieldtype", "active", "required", "description")); $query->addRowOfValues(array("'" . addslashes($id) . "'", "'" . addslashes($this->_schema->getID()) . "'", "'" . addslashes($this->_displayName) . "'", $this->_mult ? 1 : 0, "'" . addslashes($this->_type) . "'", 1, $this->_required ? 1 : 0, "'" . addslashes($this->_description) . "'")); $this->_addToDB = false; $result = $dbHandler->query($query, DATAMANAGER_DBID); if (!$result || $result->getNumberOfRows() != 1) { throwError(new UnknownDBError("DataManager")); return false; } return $id; } if ($this->_update) { // do some updating $query = new UpdateQuery(); $query->setTable("dm_schema_field"); $query->setColumns(array("name", "mult", "active", "required", "description")); $query->setWhere("id='" . addslashes($id) . "'"); $query->setValues(array("'" . addslashes($this->_displayName) . "'", $this->_mult ? 1 : 0, $this->_active ? 1 : 0, $this->_required ? 1 : 0, "'" . addslashes($this->_description) . "'")); $this->_update = false; $result = $dbHandler->query($query, DATAMANAGER_DBID); if (!$result || $result->getNumberOfRows() != 1) { throwError(new UnknownDBError("DataManager")); return null; } return $id; } if ($this->_delete) { // let's get rid of this bad-boy $query = new UpdateQuery(); $query->setTable("dm_schema_field"); $query->setWhere("id='" . addslashes($id) . "'"); $query->setColumns(array("active")); $query->setValues(array(0)); $this->_delete = false; $result = $dbHandler->query($query, DATAMANAGER_DBID); // if (!$result || $result->getNumberOfRows() != 1) { // throwError( new UnknownDBError("DataManager") ); // return false; // } return $id; } // if we're here... nothing happened... no problems return $id; }
/** * Add an Agent commitment to this ScheduleItem. * * @param object Id $agentId * @param object Type $agentStatus * * @throws object SchedulingException An exception with one of * the following messages defined in * org.osid.scheduling.SchedulingException may be thrown: {@link * org.osid.scheduling.SchedulingException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.scheduling.SchedulingException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.scheduling.SchedulingException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.scheduling.SchedulingException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.scheduling.SchedulingException#UNKNOWN_ID UNKNOWN_ID}, * {@link org.osid.scheduling.SchedulingException#UNKNOWN_TYPE * UNKNOWN_TYPE}, {@link * org.osid.shared.SharedException#ALREADY_ADDED ALREADY_ADDED} * * @access public */ function addAgentCommitment(Id $agentId, Type $agentStatus) { $dbHandler = Services::getService("DBHandler"); $query = new SelectQuery(); $query->addTable('sc_commit'); $query->addWhere("fk_sc_item='" . addslashes($this->_id->getIdString()) . "'"); $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'"); $query->addColumn('id'); //@TODO id is not really needed here--a count should probably be returned. $res = $dbHandler->query($query); if ($res->getNumberOfRows() == 0) { $typeIndex = $this->_typeToIndex('commit_stat', $agentStatus); $query = new InsertQuery(); $query->setTable('sc_commit'); $values[] = "'" . addslashes($agentId->getIdString()) . "'"; $values[] = "'" . addslashes($typeIndex) . "'"; $values[] = "'" . addslashes($this->_id->getIdString()) . "'"; $query->setColumns(array('fk_agent_id', 'fk_sc_commit_stat_type', 'fk_sc_item')); $query->addRowOfValues($values); $query->setAutoIncrementColumn('id', 'id_sequence'); $dbHandler->query($query); } else { print "<b>Warning!</b> Agent with id " . $agentId->getIdString() . "is already added to ScheduleItem " . $this->getDisplayName() . ". Use changeAgentCommitment() to change the commitment status."; } }
/** * Answer the database id for the type passed. * * @param object Type $type * @return string * @access public * @since 3/1/06 */ function _getTypeId(Type $type) { if (!isset($this->_typeIds)) { $this->_typeIds = array(); } if (!isset($this->_typeIds[$type->asString()])) { $dbc = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addColumn("id"); $query->addTable("log_type"); $query->addWhere("domain = '" . addslashes($type->getDomain()) . "'"); $query->addWhere("authority = '" . addslashes($type->getAuthority()) . "'"); $query->addWhere("keyword = '" . addslashes($type->getKeyword()) . "'"); $results = $dbc->query($query, $this->_dbIndex); if ($results->getNumberOfRows()) { $this->_typeIds[$type->asString()] = $results->field("id"); $results->free(); } else { $results->free(); $query = new InsertQuery(); $query->setTable("log_type"); $query->setAutoIncrementColumn("id", "log_type_id_seq"); $query->setColumns(array("domain", "authority", "keyword", "description")); $query->addRowOfValues(array("'" . addslashes($type->getDomain()) . "'", "'" . addslashes($type->getAuthority()) . "'", "'" . addslashes($type->getKeyword()) . "'", "'" . addslashes($type->getDescription()) . "'")); $results = $dbc->query($query, $this->_dbIndex); $this->_typeIds[$type->asString()] = $results->getLastAutoIncrementValue(); } } return $this->_typeIds[$type->asString()]; }
/** * Add a PartStructureId for which Tags should be auto-generated, in the * given repository * * @param object Id $repositoryId * @param object Id $partStructureId * @return void * @access public * @since 11/21/06 */ function addPartStructureIdForTagGeneration($repositoryId, $partStructureId) { if ($this->shouldGenerateTagsForPartStructure($repositoryId, $partStructureId)) { return; } // Insert it into the database $query = new InsertQuery(); $query->setColumns(array('fk_repository', 'fk_partstruct')); $query->addRowOfValues(array("'" . addslashes($repositoryId->getIdString()) . "'", "'" . addslashes($partStructureId->getIdString()) . "'")); $query->setTable('tag_part_map'); $dbc = Services::getService("DatabaseManager"); $result = $dbc->query($query, $this->getDatabaseIndex()); // Add it to the cache $this->_cache[$repositoryId->getIdString()][] = $partStructureId; }
/** * Adds a {@link Schema} to the list of registered types, and * makes sure that it is reference in the database as well. * @param string $type A DNS-style unique ID. Example: "edu.middlebury.schemas.person" * @param string $displayName This Schema's display name. * @param int $revision The revision of this schema, useful for updating data structures. (default=1) * @param string $description A longer description of this Schema. * @return ref object The new Schema object. * @access private */ function _addSchema($type, $displayName, $revision, $description) { debug::output("Adding Schema type '" . $type . "' to database.", DEBUG_SYS1, "DataManager"); if ($this->schemaExists($type)) { throwError(new Error("A Schema for this Type already exists, so the existing one has been returned.", "DataManager", false)); debug::output("Returning existing Schema for '" . $type . "'", DEBUG_SYS5, "DataManager"); return $this->_schemas[$id]; } $query = new InsertQuery(); $query->setTable("dm_schema"); $query->setColumns(array("id", "displayname", "description", "revision")); $query->addRowOfValues(array("'" . addslashes($type) . "'", "'" . addslashes($displayName) . "'", "'" . addslashes($description) . "'", $revision)); $dbHandler = Services::getService("DatabaseManager"); $result = $dbHandler->query($query, DATAMANAGER_DBID); if (!$result || $result->getNumberOfRows() != 1) { throwError(new UnknownDBError("DataManager")); } $newSchema = new Schema($type, $displayName, $revision, $description); $newSchema->setManagerFlag(); // add it to our local arrays $this->_schemas[$type] = $newSchema; debug::output("Created new Schema object for '" . $type . "', revision {$revision}.", DEBUG_SYS5, "DataManager"); return $newSchema; }
/** * Add an authoritative value * * WARNING: NOT in OSID * * @param object $value * @return void * @access public * @since 4/25/06 */ function addAuthoritativeValue($value) { if (!$this->isAuthoritativeValue($value)) { // add the object to our objects array $this->_authoritativeValueObjects[$value->asString()] = $value; // add the string to our strings array $this->_authoritativeValueStrings[] = $value->asString(); // add the value to our database $query = new InsertQuery(); $query->setTable('dr_authoritative_values'); $query->setColumns(array('fk_partstructure', 'fk_repository', 'value')); $id = $this->getId(); $query->addRowOfValues(array("'" . addslashes($id->getIdString()) . "'", "'" . addslashes($this->_repositoryId->getIdString()) . "'", "'" . addslashes($value->asString()) . "'")); $dbc = Services::getService("DBHandler"); $configuration = $this->manager->_configuration; $dbc->query($query, $configuration->getProperty('database_index')); } }
/** * Inserts a new row into the Database with the data contained in the object. * @param integer $dbID The {@link DBHandler} database ID to query. * @access public * @return integer Returns the new ID of the data stored. */ function insert($dbID) { $idManager = Services::getService("Id"); $newID = $idManager->createId(); $query = new InsertQuery(); $query->setTable("dm_time"); $query->setColumns(array("id", "jdn", "seconds")); $dbHandler = Services::getService("DatabaseManager"); // Convert to UTC for storage $utc = $this->asUTC(); $utcTime = $utc->asTime(); $query->addRowOfValues(array("'" . addslashes($newID->getIdString()) . "'", "'" . addslashes($utc->julianDayNumber()) . "'", "'" . addslashes($utcTime->asSeconds()) . "'")); $result = $dbHandler->query($query, $dbID); if (!$result || $result->getNumberOfRows() != 1) { throwError(new UnknownDBError("StorableTime")); return false; } return $newID->getIdString(); }
/** * Add a student to the roster and assign the specified Enrollment Status * Type. * * @param object Id $agentId * @param object Type $enrollmentStatusType * * @throws object CourseManagementException An exception * with one of the following messages defined in * org.osid.coursemanagement.CourseManagementException may be * thrown: {@link * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.coursemanagement.CourseManagementException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.coursemanagement.CourseManagementException#UNKNOWN_TYPE * UNKNOWN_TYPE}, {@link * org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED * ALREADY_ADDED} * * @access public */ function addStudent(Id $agentId, Type $enrollmentStatusType) { $dbManager = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable('cm_enroll'); $query->addWhere("fk_cm_section='" . addslashes($this->_id->getIdString()) . "'"); $query->addWhere("fk_student_id='" . addslashes($agentId->getIdString()) . "'"); //I don't need Id, but I need to select something for the query to work $query->addColumn('id'); $res = $dbManager->query($query); if ($res->getNumberOfRows() == 0) { $typeIndex = $this->_typeToIndex('enroll_stat', $enrollmentStatusType); $query = new InsertQuery(); $query->setTable('cm_enroll'); $values[] = "'" . addslashes($agentId->getIdString()) . "'"; $values[] = "'" . addslashes($typeIndex) . "'"; $values[] = "'" . addslashes($this->_id->getIdString()) . "'"; $query->setColumns(array('fk_student_id', 'fk_cm_enroll_stat_type', 'fk_cm_section')); $query->addRowOfValues($values); $query->setAutoIncrementColumn('id', 'id_sequence'); $dbManager->query($query); } else { print "<b>Warning!</b> Student with id " . $agentId->getIdString() . " is already enrolled in section " . $this->getDisplayName() . "."; } }
function test_All_Queries() { $value = "'Depeche Mode rocks!'"; $this->dbhandler->connect(); // create a new queue of queries to execuete $queryQueue = new Queue(); $query = new InsertQuery(); $query->setTable("test1"); $query->setColumns(array("value")); $query->addRowOfValues(array($value)); $queryQueue->add($query); $query = new InsertQuery(); $query->setTable("test1"); $query->setColumns(array(id, value)); $query->addRowOfValues(array("3000000", $value)); $queryQueue->add($query); $query = new DeleteQuery(); $query->setTable("test1"); $query->setWhere("id = 3000000"); $queryQueue->add($query); $query = new UpdateQuery(); $query->setTable("test1"); $query->setColumns(array("value")); $query->setValues(array($value)); $query->setWhere("id > 1000 AND id < 1006"); $queryQueue->add($query); $resultQueue = $this->dbhandler->queryQueue($queryQueue); $this->assertEqual($this->dbhandler->getTotalNumberOfQueries(), 4); $this->assertEqual($this->dbhandler->getTotalNumberOfSuccessfulQueries(), 4); $this->assertEqual($this->dbhandler->getTotalNumberOfFailedQueries(), 0); $result = $resultQueue->next(); $this->assertEqual($result->getNumberOfRows(), 1); $this->assertNotNull($result->getLastAutoIncrementValue()); $id = $result->getLastAutoIncrementValue(); $result = $resultQueue->next(); $this->assertEqual($result->getNumberOfRows(), 1); $this->assertNotNull($result->getLastAutoIncrementValue()); $result = $resultQueue->next(); $this->assertEqual($result->getNumberOfRows(), 1); $result = $resultQueue->next(); $query = new SelectQuery(); $query->setColumns(array("value")); $query->addTable("test1"); $query->setWhere("id = {$id}"); $result = $this->dbhandler->query($query); $this->assertEqual($this->dbhandler->getTotalNumberOfQueries(), 5); $this->assertEqual($this->dbhandler->getTotalNumberOfSuccessfulQueries(), 5); $this->assertEqual($this->dbhandler->getTotalNumberOfFailedQueries(), 0); $this->assertEqual("'" . $result->field("value") . "'", $value); $result->free(); }
/** * Find the index for our Type of type $type in its table. If it is not there, * put it into the table and return the index. * * @param string $typename the type of Type that is passed in. * @param object Type $type the Type itself * * @return object Type * * @access private */ function _typeToIndex($typename, $type) { //the appropriate table names and fields must be given names according to the pattern indicated below //validate the Type ArgumentValidator::validate($type, ExtendsValidatorRule::getRule("Type"), true); //query to see if it exists $dbHandler = Services::getService("DBHandler"); $query = new SelectQuery(); $query->addTable('cm_' . $typename . "_type"); $query->addWhere("domain='" . $type->getDomain() . "'"); $query->addWhere("authority='" . $type->getAuthority() . "'"); $query->addWhere("keyword='" . $type->getKeyword() . "'"); $query->addColumn('id'); $res = $dbHandler->query($query); if ($res->getNumberOfRows() == 0) { //if not query to create it $query = new InsertQuery(); $query->setTable('cm_' . $typename . '_type'); $values[] = "'" . addslashes($type->getDomain()) . "'"; $values[] = "'" . addslashes($type->getAuthority()) . "'"; $values[] = "'" . addslashes($type->getKeyword()) . "'"; if (is_null($type->getDescription())) { $query->setColumns(array('domain', 'authority', 'keyword')); } else { $query->setColumns(array('domain', 'authority', 'keyword', 'description')); $values[] = "'" . addslashes($type->getDescription()) . "'"; } $query->addRowOfValues($values); $query->setAutoIncrementColumn('id', 'cm_' . $typename . '_type_id_seq'); $result = $dbHandler->query($query); return $result->getLastAutoIncrementValue(); } elseif ($res->getNumberOfRows() == 1) { //if it does exist, create it $row = $res->getCurrentRow(); $the_index = $row['id']; return $the_index; } else { //print a warning if there is more than one such type. Should never happen. print "\n<b>Warning!<\\b> The Type with domain " . $type->getDomain() . ", authority " . $type->getAuthority() . ", and keyword " . $type->getKeyword() . " is not unique--there are " . $res->getNumberOfRows() . " copies.\n"; //return either one anyway. $row = $res->getCurrentRow(); $the_index = $row['id']; return $the_index; } }
/** * 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(); }
/** * Build the ancestory rows for a given node * * @param object Id $id * @return void * @access public * @since 11/4/05 */ function rebuildNodeAncestory(Id $id) { if (isset($this->harmoni_db)) { return $this->rebuildNodeAncestory_Harmoni_Db($id); } // print "<hr/><hr/>"; // print "<strong>"; printpre($id); print "</strong>"; $idString = $id->getIdString(); $dbHandler = Services::getService("DatabaseManager"); // Delete the old ancestory rows $this->clearNodeAncestory($idString); // Make sure we have traversed the authoratative parent/child hierarchy // To determine the new ancestory of the nodes if (!$this->_isCachedUp($idString, -1)) { $this->_traverseUp($idString, -1); } // now that all nodes are cached, add their ids to the ancestor table for // easy future searching. $query = new InsertQuery(); $query->setTable("az2_node_ancestry"); $query->setColumns(array("fk_hierarchy", "fk_node", "fk_ancestor", "level", "fk_ancestors_child")); $treeNode = $this->_tree->getNode($idString); $treeNodes = $this->_tree->traverse($treeNode, false, -1); if (count($treeNodes) > 1) { foreach (array_keys($treeNodes) as $i => $key) { $node = $this->_cache[$key][0]; // If the node was deleted, but the cache still has a key for it, // continue. if (!is_object($node)) { continue; } $nodeId = $node->getId(); // printpre($nodeId->getIdString()); if (!$nodeId->isEqual($id)) { foreach ($treeNodes[$key]['children'] as $ancestorChildId) { $query->addRowOfValues(array("'" . addslashes($this->_hierarchyId) . "'", "'" . addslashes($idString) . "'", "'" . addslashes($nodeId->getIdString()) . "'", "'" . addslashes($treeNodes[$key][1]) . "'", "'" . addslashes($ancestorChildId) . "'")); } } else { $query->addRowOfValues(array("'" . addslashes($this->_hierarchyId) . "'", "'" . addslashes($idString) . "'", "NULL", "'0'", "NULL")); } } $queryResult = $dbHandler->query($query, $this->_dbIndex); // $queryResult->free(); } }
/** * Add an Asset for this CourseOffering. Does nothing if the course has a * single copy of the asset and prints a warning if there is more than one * copy of that asset in one course. * * @param object Id $assetId * * @throws object CourseManagementException An exception * with one of the following messages defined in * org.osid.coursemanagement.CourseManagementException may be * thrown: {@link * org.osid.coursemanagement.CourseManagementException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.coursemanagement.CourseManagementException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.coursemanagement.CourseManagementException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.coursemanagement.CourseManagementException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.coursemanagement.CourseManagementException#ALREADY_ADDED * ALREADY_ADDED} * * @access public */ function addAsset(Id $assetId) { $dbManager = Services::getService("DatabaseManager"); $query = new SelectQuery(); $query->addTable('cm_assets'); $query->addWhere("fk_course_id='" . $this->_id->getIdString() . "'"); $query->addWhere("fk_asset_id='" . addslashes($assetId->getIdString()) . "'"); $query->addColumn('fk_course_id'); $res = $dbManager->query($query); if ($res->getNumberOfRows() == 0) { $query = new InsertQuery(); $query->setTable('cm_assets'); $values[] = "'" . addslashes($this->_id->getIdString()) . "'"; $values[] = "'" . addslashes($assetId->getIdString()) . "'"; $query->setColumns(array('fk_course_id', 'fk_asset_id')); $query->addRowOfValues($values); $result = $dbManager->query($query); } elseif ($res->getNumberOfRows() == 1) { //do nothing } else { print "\n<b>Warning!<\\b> The asset with course " . $this->getDisplayName() . " and id " . $assetId->getIdString() . " is not unique--there are " . $res->getNumberOfRows() . " copies.\n"; } }
/** * A public function that stores all of the properties of the property * object sent to it. * It deletes the old entries no matter what to avoid arduous checking to * if each needed to be deleted. The properties are then rewritten to the * database in the form the agent has them. * * @param int $object_id * @param object Property $properties * * @return boolean * * @access public */ function storeProperties($object_id, $properties) { $dbHandler = Services::getService("DBHandler"); //ArgumentValidator::validate($object_id, new StringValidatorRule("Type"), true); if ($properties === NULL) { return false; } $type = $properties->getType(); //so we know the type $typeIdString = $this->getTypeId($type); //get the database id for type //If we don't delete them all every time we store then if we've deleted one off of the object it will remain in the DB $query = new DeleteQuery(); $query->setTable("agent_properties"); $query->addWhere("fk_object_id='{$object_id}' AND fk_type_id='{$typeIdString}'"); $dbHandler->query($query, $this->_dbIndex); $keys = $properties->getKeys(); //all the keys for the various properties while ($keys->hasNextObject()) { //loop through all the properties $key = $keys->nextObject(); //get the next key $propertyValue = $properties->getProperty($key); //get the value of the property $query = new InsertQuery(); $query->setTable("agent_properties"); $query->setColumns(array("fk_object_id", "fk_type_id", "property_key", "property_value")); $query->addRowOfValues(array("'" . addslashes($object_id) . "'", $typeIdString, "'" . addslashes($key) . "'", "'" . addslashes($propertyValue) . "'")); // } $result = $dbHandler->query($query, $this->_dbIndex); if (!$result) { //at the first failure we'll stop and return false return false; } } return true; }
/** * Commits (either inserts or updates) the data for this DMRecord into the database. * @param boolean optional $ignoreMandatory If true, doesn't fail if mandatory * fields don't have values. * @return bool */ function commit($ignoreMandatory = false) { // Ensure that we have fields for all labels, incase // the schema has changed since we were loaded. foreach ($this->_schema->getAllLabels() as $label) { $this->_checkLabel($label); } // Get the DBHandler $dbHandler = Services::getService("DatabaseManager"); // the first thing we're gonna do is check to make sure that all our required fields // have at least one value. if (!$this->_delete) { foreach ($this->_schema->getAllIDs() as $id) { $fieldDef = $this->_schema->getField($id); if ($fieldDef->isRequired() && ($this->_fields[$id]->numValues(true) == 0 || $this->_fields[$id]->numValues() == 0) && !$ignoreMandatory) { throwError(new Error("Could not commit DMRecord to database because the required field '{$id}' does\n\t\t\t\t\tnot have any values!", "DMRecord", true)); return false; } } if ($this->_myID) { // we're already in the database $query = new UpdateQuery(); $query->setTable("dm_record"); $query->setColumns(array("ver_control")); $query->setValues(array($this->_versionControlled ? 1 : 0)); $query->setWhere("id='" . addslashes($this->_myID) . "'"); } else { // we'll have to make a new entry $schemaManager = Services::getService("SchemaManager"); $newID = $this->_idManager->createId(); $this->_myID = $newID->getIdString(); $query = new InsertQuery(); $query->setTable("dm_record"); $query->setColumns(array("id", "fk_schema", "created", "ver_control")); $query->addRowOfValues(array("'" . addslashes($this->_myID) . "'", "'" . addslashes($this->_schema->getID()) . "'", $dbHandler->toDBDate($this->_creationDate, DATAMANAGER_DBID), $this->_versionControlled ? 1 : 0)); } // execute the query; $result = $dbHandler->query($query, DATAMANAGER_DBID); if (!$result) { throwError(new UnknownDBError("DMRecord")); return false; } } // now let's cycle through our FieldValues and commit them foreach ($this->_schema->getAllIDs() as $id) { $this->_fields[$id]->commit(); } if ($this->_prune) { $constraint = $this->_pruneConstraint; // check if we have to delete any dataset tags based on our constraints $constraint->checkTags($this); $tagMgr = Services::getService("RecordTagManager"); // if we are no good any more, delete ourselves completely if ($this->_delete) { // now, remove any tags from the DB that have to do with us, since they will no longer // be valid. $tagMgr->pruneTags($this); $query = new DeleteQuery(); $query->setTable("dm_record"); $query->setWhere("id='" . addslashes($this->getID()) . "'"); $dbHandler->query($query, DATAMANAGER_DBID); $query = new DeleteQuery(); $query->setTable("dm_record_set"); $query->setWhere("fk_record='" . addslashes($this->getID()) . "'"); $dbHandler->query($query, DATAMANAGER_DBID); } else { // if we're pruning but not deleting the whole shebang, let's // make sure that there are no tags in the database with no // mappings whatsoever. $tagMgr->checkForEmptyTags($this); } } return true; }
/** * Add the specified RecordStructure and all the related Records from the * specified asset. The current and future content of the specified * Record is synchronized automatically. * * @param object Id $assetId * @param object Id $recordStructureId * * @throws object RepositoryException An exception with one of * the following messages defined in * org.osid.repository.RepositoryException may be thrown: {@link * org.osid.repository.RepositoryException#OPERATION_FAILED * OPERATION_FAILED}, {@link * org.osid.repository.RepositoryException#PERMISSION_DENIED * PERMISSION_DENIED}, {@link * org.osid.repository.RepositoryException#CONFIGURATION_ERROR * CONFIGURATION_ERROR}, {@link * org.osid.repository.RepositoryException#UNIMPLEMENTED * UNIMPLEMENTED}, {@link * org.osid.repository.RepositoryException#NULL_ARGUMENT * NULL_ARGUMENT}, {@link * org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}, * {@link * org.osid.repository.RepositoryException#ALREADY_INHERITING_STRUCTURE * ALREADY_INHERITING_STRUCTURE} * * @access public */ function inheritRecordStructure(Id $assetId, Id $recordStructureId) { // If this is a schema that is hard coded into our implementation, create // a record for that schema. if (in_array($recordStructureId->getIdString(), array_keys($this->_repository->_builtInTypes))) { // Create an Id for the record; $idManager = Services::getService("Id"); $dbHandler = Services::getService("DatabaseManager"); // get the record ids that we want to inherit $query = new SelectQuery(); $query->addTable("dr_asset_record"); $query->addColumn("fk_record"); $query->addWhere("fk_asset = '" . $assetId->getIdString() . "'"); $query->addWhere("structure_id = '" . $recordStructureId->getIdString() . "'", _AND); $result = $dbHandler->query($query, $this->_dbIndex); // store a relation to the record $dbHandler = Services::getService("DatabaseManager"); $query = new InsertQuery(); $query->setTable("dr_asset_record"); $query->setColumns(array("fk_asset", "fk_record", "structure_id")); $myId = $this->getId(); while ($result->hasMoreRows()) { $query->addRowOfValues(array("'" . $myId->getIdString() . "'", "'" . $result->field("fk_record") . "'", "'" . $recordStructureId->getIdString() . "'")); $dbHandler->query($query, $this->_dbIndex); $result->advanceRow(); } $result->free(); } else { // Get our managers: $recordMgr = Services::getService("RecordManager"); $idMgr = Services::getService("Id"); // Get the DataSetGroup for this Asset $myId = $this->_node->getId(); $mySet = $recordMgr->fetchRecordSet($myId->getIdString()); // Get the DataSetGroup for the source Asset $otherSet = $recordMgr->fetchRecordSet($assetId->getIdString()); $otherSet->loadRecords(RECORD_FULL); $records = $otherSet->getRecords(); // Add all of DataSets (Records) of the specified RecordStructure and Asset // to our RecordSet. foreach (array_keys($records) as $key) { // Get the ID of the current DataSet's TypeDefinition $schema = $records[$key]->getSchema(); $schemaId = $idMgr->getId($schema->getID()); // If the current DataSet's DataSetTypeDefinition's ID is the same as // the RecordStructure ID that we are looking for, add that dataSet to our // DataSetGroup. if ($recordStructureId->isEqual($schemaId)) { $mySet->add($records[$key]); } } // Save our DataSetGroup $mySet->commit(TRUE); } $this->updateModificationDate(); }
/** * Add tokens to the system. * * @param object AuthNTokens $authNTokens * @return void * @access public * @since 3/1/05 */ function addTokens($authNTokens) { ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens")); if ($this->tokensExist($authNTokens)) { throwError(new Error("Token Addition Error: " . "'" . $authNTokens->getUsername() . "' already exists.", "SQLDatabaseAuthNMethod", true)); } else { $dbc = Services::getService("DatabaseManager"); $dbId = $this->_configuration->getProperty('database_id'); $authenticationTable = $this->_configuration->getProperty('authentication_table'); $usernameField = $this->_configuration->getProperty('username_field'); $passwordField = $this->_configuration->getProperty('password_field'); $query = new InsertQuery(); $query->setTable($authenticationTable); $query->setColumns(array($usernameField, $passwordField)); $query->addRowOfValues(array("'" . addslashes($authNTokens->getUsername()) . "'", "'" . addslashes($authNTokens->getPassword()) . "'")); $result = $dbc->query($query, $dbId); } }