/**
  * Uses the ID passed and updates the database row with
  * new data.
  * @param integer $dbID The {@link DBHandler} database ID to query.
  * @param integer $dataID The ID in the database of the data to be updated.
  * @access public
  * @return void
  */
 function update($dbID, $dataID)
 {
     if (!$dataID) {
         return false;
     }
     $query = new UpdateQuery();
     $query->setTable($this->_table);
     $query->setColumns(array("data"));
     $query->setWhere("id='" . addslashes($dataID) . "'");
     $query->setValues(array("'" . addslashes($this->asString()) . "'"));
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $dbID);
     if (!$result) {
         throwError(new UnknownDBError("StorableString"));
         return false;
     }
     return true;
 }
 /**
  * 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();
 }
 /**
  * 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)
 {
     if (is_array($value)) {
         $this->_dimensions = $value;
         $dbHandler = Services::getService("DatabaseManager");
         $query = new SelectQuery();
         $query->addTable($this->_table);
         $query->addColumn("COUNT(*)", "count");
         $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         if ($result->field("count") > 0) {
             $query = new UpdateQuery();
             $query->setTable($this->_table);
             $query->setColumns(array($this->_widthColumn, $this->_heightColumn));
             $query->setValues(array("'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'"));
             $query->addWhere($this->_idColumn . " = '" . $this->_recordId->getIdString() . "'");
         } else {
             $query = new InsertQuery();
             $query->setTable($this->_table);
             $query->setColumns(array($this->_idColumn, $this->_widthColumn, $this->_heightColumn));
             $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . $this->_dimensions[0] . "'", "'" . $this->_dimensions[1] . "'"));
         }
         $result->free();
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // This gets done during thumbnail generation, so don't change our
         // asset's modification date.
         // 			$this->_asset->updateModificationDate();
     }
 }
 /**
  * Change the Enrollment Status Type for the student on the roster.
  * 
  * @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}
  * 
  * @access public
  */
 function changeStudent(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) {
         throwError(new Error("Cannot change status of student [" . $agentId->getIDString() . "] because that student in not enrolled in the course[" . $this->_id->getIdString() . "]", "CourseManagement", true));
     } else {
         if ($res->getNumberOfRows() > 1) {
             print "<b>Warning!</b> Student with id " . $agentId->getIdString() . " is already enrolled in section " . $this->getDisplayName() . " twice.";
         }
     }
     $typeIndex = $this->_typeToIndex('enroll_stat', $enrollmentStatusType);
     $query = new UpdateQuery();
     $query->setTable('cm_enroll');
     $query->addWhere("fk_cm_section='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_student_id='" . addslashes($agentId->getIdString()) . "'");
     $query->setColumns(array('fk_cm_enroll_stat_type'));
     $query->setValues(array("'" . addslashes($typeIndex) . "'"));
     $dbManager->query($query);
 }
 /**
  * Given the object in table $table with id $id, change the field with name $key to $value
  *
  * @param object Id $id The Id of the object in question
  * @param string $table The table that our object resides in
  * @param string $key The name of the field
  * @param mixed $value The value to pass in
  *
  *
  * @access private
  */
 function _setField($id, $table, $key, $value)
 {
     //just an update query
     $dbHandler = Services::getService("DBHandler");
     $query = new UpdateQuery();
     $query->setTable($table);
     $query->addWhere("id='" . addslashes($id->getIdString()) . "'");
     $query->setColumns(array(addslashes($key)));
     $query->setValues(array("'" . addslashes($value) . "'"));
     $dbHandler->query($query);
 }
 /**
  * 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;
 }
 /**
  * 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)
 {
     if (!is_null($value)) {
         ArgumentValidator::validate($value, NonzeroLengthStringValidatorRule::getRule());
     }
     // Store the name in the object in case its asked for again.
     $this->_type = $value;
     // then write it to the database.
     $dbHandler = Services::getService("DatabaseManager");
     // If we have a key, make sure it exists.
     if ($this->_type && $this->_type != "NULL") {
         // Check to see if the type is in the database
         $query = new SelectQuery();
         $query->addTable("dr_mime_type");
         $query->addColumn("id");
         $query->addWhere("type = '" . $this->_type . "'");
         $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         // If it doesn't exist, insert it.
         if (!$result->getNumberOfRows()) {
             $query = new InsertQuery();
             $query->setTable("dr_mime_type");
             $query->setAutoIncrementColumn("id", "dr_mime_type_id_seq");
             $query->setColumns(array("type"));
             $query->setValues(array("'" . addslashes($this->_type) . "'"));
             $result2 = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
             $mimeId = "'" . $result2->getLastAutoIncrementValue() . "'";
         } else {
             $mimeId = "'" . $result->field("id") . "'";
         }
         $result->free();
     } else {
         $mimeId = "NULL";
     }
     // add its id to the file.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->setColumns(array("fk_mime_type"));
     $query->setValues(array($mimeId));
     $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 /**
  * Run the update
  * 
  * @return boolean
  * @access public
  * @since 3/8/07
  */
 function runUpdate()
 {
     $dbc = Services::getService('DatabaseManager');
     $dbc->beginTransaction();
     $toUpdate = array(array('table' => "j_node_node", 'column' => "fk_parent"), array('table' => "j_node_node", 'column' => "fk_child"), array('table' => "node", 'column' => "node_id"), array('table' => "node_ancestry", 'column' => "fk_node"), array('table' => "node_ancestry", 'column' => "fk_ancestor"), array('table' => "node_ancestry", 'column' => "fk_ancestors_child"));
     foreach ($toUpdate as $unit) {
         $query = new UpdateQuery();
         $query->setTable($unit['table']);
         $query->setColumns(array($unit['column']));
         $query->setValues(array("'edu.middlebury.repositories_root'"));
         $query->addWhere($unit['column'] . "='edu.middlebury.concerto.collections_root'");
         $results = $dbc->query($query, 0);
         print "\n<br/>" . $results->getNumberOfRows() . " rows in " . $unit['table'] . " (column " . $unit['column'] . ") updated";
     }
     $dbc->commitTransaction();
     print "<div style='font-weight: bold'>" . _("Please update your repository config to use the new repository root id, 'edu.middlebury.repositories_root'.") . "</div>";
     return true;
 }
 /**
  * Update the orders of the ids in the database.
  * @param array $oldOrders The previous orders to compare so that only 
  *		updates will be done to changed orders.
  * @access private
  * @return void
  */
 function _updateOrders($oldOrders)
 {
     $dbHandler = Services::getService("DatabaseManager");
     foreach ($this->_items as $key => $val) {
         // If the old key-value pairs don't match the current ones,
         // update that row
         if ($oldOrders[$key] != $val) {
             $query = new UpdateQuery();
             $query->setTable("sets");
             $columns = array("item_order");
             $query->setColumns($columns);
             $values = array($key);
             $query->setValues($values);
             $query->addWhere("id = '" . addslashes($this->_setId->getIdString()) . "'");
             $query->addWhere("item_id = '" . addslashes($val) . "'");
             $dbHandler->query($query);
         }
     }
 }
 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();
 }
Exemple #11
0
 /**
  * Rename the tag for the given agent
  * 
  * @param object Id $agentId
  * @param string $newValue
  * @return void
  * @access public
  * @since 11/27/06
  */
 function renameForAgent($agentId, $newValue)
 {
     $newTag = new Tag($newValue);
     $query = new UpdateQuery();
     $query->setTable('tag');
     $query->setColumns(array('value'));
     $query->setValues(array("'" . addslashes($newTag->getValue()) . "'"));
     $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'");
     $query->addWhere("tag.user_id='" . addslashes($agentId->getIdString()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $dbc->query($query, $this->getDatabaseIndex());
 }
 /**
  * Change a previously added Agent commitment for 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}
  * 
  * @access public
  */
 function changeAgentCommitment(Id $agentId, Type $agentStatus)
 {
     $typeIndex = $this->_typeToIndex('commit_stat', $agentStatus);
     $dbHandler = Services::getService("DBHandler");
     $query = new UpdateQuery();
     $query->setTable('sc_commit');
     $query->addWhere("fk_sc_item='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'");
     $query->setColumns(array('fk_sc_commit_stat_type'));
     $query->setValues(array("'" . addslashes($typeIndex) . "'"));
     $res = $dbHandler->query($query);
     if ($res->getNumberOfRows() == 0) {
         print "<b>Warning!</b> Agent with Id [" . $agentId->getIdString() . "] is not added to ScheduleItem " . $this->getdisplayName() . " [" . $this->_id->getIdString() . "] yet.  Use addAgentCommitment() to add the Agent before changing it.";
     } else {
         if ($res->getNumberOfRows() > 1) {
             print "<b>Warning!</b> Agent with Id [" . $agentId->getIdString() . "] is added " . $res->getNumberOfRows() . " times to ScheduleItem " . $this->getdisplayName() . " [" . $this->_id->getIdString() . "] when only one is acceptable.";
         }
     }
 }
Exemple #13
0
 /**
  * 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;
 }
 /**
  * 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;
 }
 /**
  * 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)
 {
     if (!is_null($value)) {
         ArgumentValidator::validate($value, StringValidatorRule::getRule());
     }
     // Store the name in the object in case its asked for again.
     $this->_value = $value;
     // then write it to the database.
     $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;
     }
     // Check to see if the name is in the database
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_url");
     $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_url");
         $query->setColumns(array("url"));
         $query->setValues(array("'" . addslashes($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_url");
         $query->setColumns(array("fk_file", "url"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . addslashes($value) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 /**
  * Passed a {@link Schema}, will make sure that the definition stored in the database
  * reflects what is stored in the passed object.
  * @param ref object A {@link Schema} object.
  * @return boolean Success/failure.
  * @access public
  */
 function synchronize($new)
 {
     ArgumentValidator::validate($new, ExtendsValidatorRule::getRule("Schema"));
     $id = $new->getID();
     debug::output("Attempting to synchronize Schema type '" . $id . "' with\n\t\tthe database.", DEBUG_SYS1, "DataManager");
     // check if we already have a definition for this type. if we don't, add a new one.
     if (!$this->schemaExists($id)) {
         $old = $this->_addSchema($id, $new->getDisplayName(), $new->getRevision(), $new->getDescription());
         debug::output("Creating new Schema in the database.", DEBUG_SYS3, "DataManager");
     } else {
         $old = $this->getSchemaByID($id);
         // make sure $oldDef has all its data loaded
         $old->load();
         debug::output("Using database version for synchronization.", DEBUG_SYS3, "DataManger");
     }
     /*
     The synchronization process is not simple. 
     
     compare revision numbers, and update them appropriately. do this last.
     
     get all field ids, from both old def (from DB) and new def, store in $ids[]
     
     For each $ids {
     	if the field doesn't exist, add it to the DB
     	if the field does exist {
     		...in database, but not in new, delete it
     		...in both new def and db {
     			if mult value has changed ...
     				... from yes to no, make the change.
     				... from no to yes, make the change.
     			if versionControl has changed ...
     				... shouldn't be a problem -- just make the change
     			if field type has changed ...
     				... NOT ALLOWED!
     			if active flag has changed ...
     				... from yes to no, delete the old
     				... from no to yes, re-activate the old
     			if required flag has changed ...
     				... from yes to no, ok, update it
     				... from no to yes, throw an error. we can't validate all datasets
     			if display name has changed
     				... change it
     			if desc has changed
     				... change it
     		}
     	}
     }
     */
     $allLabels = array_unique(array_merge($new->getAllIDs(true), $old->getAllIDs(true)));
     debug::output("Merged ids: " . implode(", ", $allLabels), DEBUG_SYS5, "DataManager");
     foreach ($allLabels as $label) {
         // now we're going to go through the logic above in the comment
         debug::output("Checking id '{$label}' ...", DEBUG_SYS5, "DataManager");
         // if the field exists in new and not in old, add it to old, and flag it to add to DB
         if (!$old->fieldExists($label) && $new->fieldExists($label)) {
             $field = $new->getField($label);
             $newField = $field->replicate();
             $newField->addToDB();
             $old->addField($newField);
             debug::output("Label '{$label}' flagged for addition to database.", DEBUG_SYS5, "DataManager");
             unset($newField, $field);
             continue;
         }
         // if the field exists in the old but not in the new, flag it for deletion.
         if ($old->fieldExists($label) && !$new->fieldExists($label)) {
             $field = $old->getField($label);
             $field->delete();
             debug::output("Label '{$label}' flagged for deletion from database.", DEBUG_SYS5, "DataManager");
             unset($field);
             continue;
         }
         // ok, if we're at this point it means the label is defined in both definitions.
         $oldField = $old->getField($label);
         $newField = $new->getField($label);
         // first let's check if the types match. if they don't, we're going to go psycho
         $oldType = $oldField->getType();
         $newType = $newField->getType();
         if ($newType != $oldType) {
             // go PSYCHO!!!!
             throwError(new Error("While synchronizing Schema '" . $this->_type . "', it appears that the\n\t\t\t\t\tfield type for id '{$label}' is different from what we have stored. It is not possible\n\t\t\t\t\tto synchronize without potential data loss. Aborting.", "DataManager", true));
             return false;
         }
         unset($newType, $oldType);
         // let's check the active flag
         $oldActive = $oldField->isActive();
         $newActive = $newField->isActive();
         if ($oldActive != $newActive) {
             if ($oldActive && !$newActive) {
                 $oldField->delete();
                 debug::output("ID '{$label}' is no longer active.", DEBUG_SYS5, "DataManager");
             }
             if (!$oldActive && $newActive) {
                 $oldField->setActiveFlag(true);
                 $oldField->update();
                 debug::output("ID '{$label}' is to be reactivated.", DEBUG_SYS5, "DataManager");
             }
         }
         // now let's check the mult
         $oldMult = $oldField->getMultFlag();
         $newMult = $newField->getMultFlag();
         if ($oldMult !== $newMult) {
             // boolean-safe compare
             // ok, now, if we're changing from true to false, just go ahead, make the change
             if (!$oldMult && $newMult) {
                 $oldField->setMultFlag(true);
                 $oldField->update();
                 debug::output("Label '{$label}': activating multiple-values.", DEBUG_SYS5, "DataManager");
             }
             // otherwise, we'll have to do some smart updating
             if ($oldMult && !$newMult) {
                 // now, make the change
                 $oldField->setMultFlag(false);
                 $oldField->update();
                 debug::output("Label '{$label}': deactivating multiple values, deleted any additional data entries that would conflict with this setting.", DEBUG_SYS5, "DataManager");
             }
         }
         // check the description
         $oldDesc = $oldField->getDescription();
         $newDesc = $newField->getDescription();
         if ($oldDesc != $newDesc) {
             $oldField->updateDescription($newDesc);
             $oldField->update();
         }
         // check the display name
         $oldName = $oldField->getDisplayName();
         $newName = $newField->getDisplayName();
         if ($oldName != $newName) {
             $oldField->updateDisplayName($newName);
             $oldField->update();
         }
         // now let's check the req
         $oldReq = $oldField->isRequired();
         $newReq = $newField->isRequired();
         if ($oldReq !== $newReq) {
             // boolean-safe compare
             // ok, now, if we're changing from true to false, just go ahead, make the change
             if (!$oldReq && $newReq) {
                 $oldField->setRequired(true);
                 $oldField->update();
             }
             // otherwise, throw an error!
             if ($oldReq && !$newReq) {
                 throwError(new Error("synchronize() can not change a field's required flag from NO to YES!", "DataManager", true));
                 return false;
             }
         }
     }
     // now that we're done syncrhonizing $newDef with $oldDef, let's commit everything to the DB
     $old->commitAllFields();
     // lastly, update the row in the table for this schema
     // change the database.
     $query = new UpdateQuery();
     $query->setTable("dm_schema");
     $query->setWhere("id='" . addslashes($old->getID()) . "'");
     $query->setColumns(array("revision", "displayname", "description", "other_params"));
     $query->setValues(array($new->getRevision(), "'" . addslashes($old->getDisplayName()) . "'", "'" . addslashes($old->getDescription()) . "'", "'" . addslashes(serialize($old->getOtherParameters())) . "'"));
     $dbHandler = Services::getService("DatabaseManager");
     $dbHandler->query($query, DATAMANAGER_DBID);
     $old->loaded(true);
     debug::output("... synchronization finished.", DEBUG_SYS2, "DataManager");
 }
 /**
  * Uses the ID passed and updates the database row with
  * new data.
  * @param integer $dbID The {@link DBHandler} database ID to query.
  * @param integer $dataID The ID in the database of the data to be updated.
  * @access public
  * @return void
  */
 function update($dbID, $dataID)
 {
     if (!$dataID) {
         return false;
     }
     $query = new UpdateQuery();
     $query->setTable("dm_time");
     $query->setColumns(array("jdn", "seconds"));
     $query->setWhere("id='" . addslashes($dataID) . "'");
     // Convert to UTC for storage
     $utc = $this->asUTC();
     $utcTime = $utc->asTime();
     $query->setValues(array("'" . addslashes($utc->julianDayNumber()) . "'", "'" . addslashes($utcTime->asSeconds()) . "'"));
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $dbID);
     if (!$result) {
         throwError(new UnknownDBError("StorableTime"));
         return false;
     }
     return true;
 }
 /**
  * Convert all occurrances of the sourceId in the data manager and sets
  * into the destination id.
  * 
  * @param object Id $sourceId
  * @param object Id $destId
  * @return boolean
  * @access public
  * @since 3/7/07
  */
 function convertRecordStructureIds($sourceId, $destId)
 {
     $sourceIdString = $sourceId->getIdString();
     $destIdString = $destId->getIdString();
     printpre("Converting from id '" . $sourceIdString . "' to '" . $destIdString . "'.");
     $fieldMapping = $this->getFieldMapping();
     $dbc = Services::getService('DatabaseManager');
     $dbc->beginTransaction();
     $query = new SelectQuery();
     $query->addColumn('id');
     $query->addColumn('name');
     $query->addTable('dm_schema_field');
     $query->addWhere("fk_schema='" . addslashes($sourceIdString) . "'");
     $results = $dbc->query($query, 0);
     while ($results->hasNext()) {
         $row = $results->next();
         $fieldMapping[$row['name']]['source_id'] = $row['id'];
     }
     $results->free();
     // Update the dm_schema table
     $query = new UpdateQuery();
     $query->setTable('dm_schema');
     $query->setColumns(array('id'));
     $query->setValues(array("'" . addslashes($destIdString) . "'"));
     $query->addWhere("id='" . addslashes($sourceIdString) . "'");
     $results = $dbc->query($query, 0);
     print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in dm_schema updated");
     // Check to ensure that all mappings are valid
     foreach ($fieldMapping as $mapping) {
         if (!$mapping['dest_id'] || !$mapping['source_id']) {
             print "\n<br/>Error: the following mapping is invalid: ";
             printpre($mapping);
             return false;
         }
     }
     // Update the dm_schema_field table
     foreach ($fieldMapping as $mapping) {
         $query = new UpdateQuery();
         $query->setTable('dm_schema_field');
         $query->setColumns(array('id', 'fk_schema'));
         $query->setValues(array("'" . addslashes($mapping['dest_id']) . "'", "'" . addslashes($destIdString) . "'"));
         $query->addWhere("id='" . addslashes($mapping['source_id']) . "'");
         $results = $dbc->query($query, 0);
         print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in dm_schema_field updated");
     }
     // Update the dm_record table
     $query = new UpdateQuery();
     $query->setTable('dm_record');
     $query->setColumns(array('fk_schema'));
     $query->setValues(array("'" . addslashes($destIdString) . "'"));
     $query->addWhere("fk_schema='" . addslashes($sourceIdString) . "'");
     $results = $dbc->query($query, 0);
     print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in dm_record updated");
     // Update the dm_record_field table
     foreach ($fieldMapping as $mapping) {
         $query = new UpdateQuery();
         $query->setTable('dm_record_field');
         $query->setColumns(array('fk_schema_field'));
         $query->setValues(array("'" . addslashes($mapping['dest_id']) . "'"));
         $query->addWhere("fk_schema_field='" . addslashes($mapping['source_id']) . "'");
         $results = $dbc->query($query, 0);
         print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in dm_record_field updated");
     }
     // Update the sets table
     $query = new UpdateQuery();
     $query->setTable('sets');
     $query->setColumns(array('id'));
     $query->setValues(array("'" . addslashes($destIdString) . "'"));
     $query->addWhere("id='" . addslashes($sourceIdString) . "'");
     $results = $dbc->query($query, 0);
     print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in sets updated");
     $query = new UpdateQuery();
     $query->setTable('sets');
     $query->setColumns(array('item_id'));
     $query->setValues(array("'" . addslashes($destIdString) . "'"));
     $query->addWhere("item_id='" . addslashes($sourceIdString) . "'");
     $results = $dbc->query($query, 0);
     print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in sets updated");
     // Update the dm_record_field table
     foreach ($fieldMapping as $mapping) {
         $query = new UpdateQuery();
         $query->setTable('sets');
         $query->setColumns(array('id'));
         $query->setValues(array("'" . addslashes($mapping['dest_id']) . "'"));
         $query->addWhere("id='" . addslashes($mapping['source_id']) . "'");
         $results = $dbc->query($query, 0);
         print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in sets updated");
         $query = new UpdateQuery();
         $query->setTable('sets');
         $query->setColumns(array('item_id'));
         $query->setValues(array("'" . addslashes($mapping['dest_id']) . "'"));
         $query->addWhere("item_id='" . addslashes($mapping['source_id']) . "'");
         $results = $dbc->query($query, 0);
         print "\n<br/>" . $results->getNumberOfRows() . " " . _("rows in sets updated");
     }
     $dbc->commitTransaction();
     return true;
 }
 /**
  * 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();
 }
 /**
  * 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)
 {
     $file = $this->_getFilePath();
     if (!($handle = fopen($file, 'w'))) {
         throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be opened for writing.", "FileSystemFileDataPart", true));
     }
     if (fwrite($handle, $value) === FALSE) {
         fclose($handle);
         throwError(new Error(RepositoryException::OPERATION_FAILED() . ": '{$file}' could not be written to.", "FileSystemFileDataPart", true));
     }
     fclose($handle);
     // Check to see if the size is in the database
     $dbHandler = Services::getService("DatabaseManager");
     $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("'" . strlen($value) . "'"));
         $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() . "'", "'" . strlen($value) . "'"));
     }
     $result->free();
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
 /**
  * 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();
 }
 /**
  * Uses the ID passed and updates the database row with
  * new data.
  * @param integer $dbID The {@link DBHandler} database ID to query.
  * @param integer $dataID The ID in the database of the data to be updated.
  * @access public
  * @return void
  */
 function update($dbID, $dataID)
 {
     if (!$dataID) {
         return false;
     }
     $query = new UpdateQuery();
     $query->setTable("dm_okitype");
     $query->setColumns(array("domain", "authority", "keyword"));
     $query->setWhere("id='" . addslashes($dataID) . "'");
     $query->setValues(array("'" . addslashes($this->getDomain()) . "'", "'" . addslashes($this->getAuthority()) . "'", "'" . addslashes($this->getKeyword()) . "'"));
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, $dbID);
     if (!$result) {
         throwError(new UnknownDBError("StorableOKIType"));
         return false;
     }
     return true;
 }
 /**
  * Update the last-changed timestamp for the node to be now so that the authorization
  * system can sychronize with the new value.
  * 
  * @param object Id $nodeId
  * @return void
  * @access public
  * @since 12/20/05
  */
 function dirtyNode(Id $nodeId)
 {
     // Need to test more to determin if the Harmoni_Db version is fast enough to use.
     // 		if (isset($this->authorizationManager->harmoni_db))
     // 			return $this->dirtyNode_Harmoni_Db($nodeId);
     $hierarchyManager = $this->authorizationManager->getHierarchyManager();
     $node = $hierarchyManager->getNode($nodeId);
     $hierarchy = $hierarchyManager->getHierarchyForNode($node);
     $dbHandler = Services::getService("DBHandler");
     if (isset($this->_configuration)) {
         $dbIndex = $this->_configuration->getProperty('database_index');
     } else {
         $dbIndex = $hierarchyManager->_configuration->getProperty('database_index');
     }
     $traversalInfo = $hierarchy->traverse($nodeId, Hierarchy::TRAVERSE_MODE_DEPTH_FIRST, Hierarchy::TRAVERSE_DIRECTION_DOWN, Hierarchy::TRAVERSE_LEVELS_ALL);
     $nodesToDirty = array();
     while ($traversalInfo->hasNext()) {
         $info = $traversalInfo->next();
         $nodeId = $info->getNodeId();
         $idString = $nodeId->getIdString();
         if (isset($_SESSION['__isAuthorizedCache'])) {
             foreach (array_keys($_SESSION['__isAuthorizedCache']) as $agentIdString) {
                 if (isset($_SESSION['__isAuthorizedCache'][$agentIdString][$idString])) {
                     unset($_SESSION['__isAuthorizedCache'][$agentIdString][$idString]);
                 }
             }
         }
         $nodesToDirty[] = "'" . addslashes($idString) . "'";
     }
     // Update the node's az_changed time
     // so that it can be removed from the caches of other users during
     // their synchronization.
     $query = new UpdateQuery();
     $query->setTable("az2_node");
     $query->setColumns(array("last_changed"));
     $query->setValues(array("NOW()"));
     $query->addWhere("id IN (" . implode(", ", $nodesToDirty) . ")");
     // 		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
     $queryResult = $dbHandler->query($query, $dbIndex);
 }
 /**
  * Update the properties for the given tokens
  * 
  * @param object AuthNTokens $authNTokens
  * @param object Properties $newProperties
  * @return void
  * @access public
  * @since 3/1/05
  */
 function updatePropertiesForTokens($authNTokens, $newProperties)
 {
     ArgumentValidator::validate($authNTokens, ExtendsValidatorRule::getRule("AuthNTokens"));
     ArgumentValidator::validate($newProperties, ExtendsValidatorRule::getRule("Properties"));
     if (!$this->tokensExist($authNTokens)) {
         throwError(new Error("Properties Update Error: " . "'" . $authNTokens->getUsername() . "' does not exist.", "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');
         $propertiesFields = $this->_configuration->getProperty('properties_fields');
         if (!is_array($propertiesFields) || !count($propertiesFields)) {
             return;
         }
         $query = new UpdateQuery();
         $query->setTable($authenticationTable);
         $columns = array();
         $values = array();
         foreach ($propertiesFields as $propertyKey => $fieldName) {
             // Don't allow overwriting of tokens even if they are listed in the
             // properties array.
             if ($fieldName != $usernameField && $fieldName != $passwordField) {
                 $columns[] = $fieldName;
                 $values[] = "'" . addslashes($newProperties->getProperty($propertyKey)) . "'";
             }
         }
         $query->setColumns($columns);
         $query->setValues($values);
         $query->addWhere($usernameField . "='" . addslashes($authNTokens->getUsername()) . "'");
         $result = $dbc->query($query, $dbId);
     }
 }