/**
  * 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();
 }
 /**
  * Forcibly set the creation date of this Asset. This is meant to be used when importing
  * from backups.
  *  
  * WARNING: NOT IN OSID
  *
  * @param object DateAndTime $date
  * @return void
  * @access public
  * @since 1/25/08
  */
 public function forceSetModificationDate(DateAndTime $date)
 {
     $dbHandler = Services::getService("DatabaseManager");
     $query = new UpdateQuery();
     $query->setTable("dr_asset_info");
     $query->addValue("modify_timestamp", $date->asString());
     $query->addWhere("asset_id='" . $this->getId()->getIdString() . "'");
     $dbHandler->query($query, $this->_dbIndex);
     $this->_modifyDate = $date;
 }
 /**
  * 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();
 }
 /**
  * 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);
 }
 /**
  * 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);
         }
     }
 }
 /**
  * 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);
 }
 /**
  * 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();
 }
 /**
  * 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;
 }
 /**
  * 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.";
         }
     }
 }
 /**
  * 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();
     }
 }
 /**
  * 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.
     if (is_null($value)) {
         $this->_name = '';
     } else {
         $this->_name = $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");
         if (is_null($value)) {
             $query->addRawValue("filename", "NULL");
         } else {
             $query->addValue("filename", $this->_name);
         }
         $query->addWhere("id = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file");
         $query->addValue("id", $this->_recordId->getIdString());
         if (is_null($value)) {
             $query->addRawValue("filename", "NULL");
         } else {
             $query->addValue("filename", $this->_name);
         }
     }
     $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_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();
 }
 /**
  * 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;
 }
Exemple #14
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());
 }
 /**
  * Make the changes to the database required to go from harmoni-0.11.0 to harmoni-0.12.0.
  * 
  * @param integer $dbIndes
  * @return void
  * @access public
  * @since 9/13/07
  */
 public static function harmoni_0_12_0_update($dbIndex)
 {
     $dbc = Services::getService("DBHandler");
     $tables = $dbc->getTableList($dbIndex);
     $changeTables = array('j_node_node', 'node_ancestry');
     $changeTableStatus = array('j_node_node' => false, 'node_ancestry' => false);
     // Check which tables need to be updated and update if needed.
     foreach ($changeTables as $table) {
         if (in_array($table, $tables)) {
             $result = $dbc->query(new GenericSQLQuery("DESCRIBE " . $table), $dbIndex);
             $result = $result->returnAsSelectQueryResult();
             while ($result->hasNext()) {
                 if ($result->field("Field") == 'fk_hierarchy') {
                     $changeTableStatus[$table] = true;
                     break;
                 }
                 $result->advanceRow();
             }
             if (!$changeTableStatus[$table]) {
                 // Alter the table
                 printpre("Adding column fk_hierarchy to {$table}");
                 $dbc->query(new GenericSQLQuery("ALTER TABLE `" . $table . "` ADD `fk_hierarchy` VARCHAR( 170 ) FIRST ;"), $dbIndex);
             }
         }
     }
     // Select the hierarchy ids and update the table
     if (in_array(false, $changeTableStatus)) {
         // Look up which nodes belong to which hierarchy
         $query = new SelectQuery();
         $query->addTable("node");
         $query->addColumn("node_id");
         $query->addColumn("fk_hierarchy");
         $query->addOrderBy("fk_hierarchy");
         $hierarchies = array();
         $result = $dbc->query($query, $dbIndex);
         while ($result->hasMoreRows()) {
             // Create an array to hold the ids of all nodes in the hierarchy
             if (!isset($hierarchies[$result->field('fk_hierarchy')])) {
                 $hierarchies[$result->field('fk_hierarchy')] = array();
             }
             $hierarchies[$result->field('fk_hierarchy')][] = $result->field('node_id');
             $result->advanceRow();
         }
         $result->free();
         // Update each table's fk_hierarchy
         foreach ($hierarchies as $hierarchyId => $nodeIds) {
             if (!$changeTableStatus['j_node_node']) {
                 $query = new UpdateQuery();
                 $query->addValue('fk_hierarchy', $hierarchyId);
                 $query->setTable('j_node_node');
                 $query->addWhere("fk_child IN ('" . implode("', '", $nodeIds) . "')");
                 $result = $dbc->query($query, $dbIndex);
                 printpre("Updated fk_hierarchy on " . $result->getNumberOfRows() . " rows in j_node_node.");
             }
             if (!$changeTableStatus['j_node_node']) {
                 $query = new UpdateQuery();
                 $query->addValue('fk_hierarchy', $hierarchyId);
                 $query->setTable('node_ancestry');
                 $query->addWhere("fk_node IN ('" . implode("', '", $nodeIds) . "')");
                 $result = $dbc->query($query, $dbIndex);
                 printpre("Updated fk_hierarchy on " . $result->getNumberOfRows() . " rows in node_ancestry.");
             }
         }
         // Alter the table to be NOT NULL
         foreach ($changeTables as $table) {
             if (!$changeTableStatus[$table]) {
                 // Alter the table
                 $dbc->query(new GenericSQLQuery("ALTER TABLE `" . $table . "` CHANGE `fk_hierarchy` `fk_hierarchy`  VARCHAR( 170 ) NOT NULL"), $dbIndex);
                 printpre("Altering column fk_hierarchy in {$table} to be NOT NULL.");
             }
         }
     }
     // Alter the names of the Scheduling columns
     if (in_array('sc_item', $tables)) {
         try {
             $dbc->query(new GenericSQLQuery("ALTER TABLE `sc_item` CHANGE `start` `start_date` BIGINT( 20 ) NULL DEFAULT NULL , CHANGE `end` `end_date` BIGINT( 20 ) NULL DEFAULT NULL "), $dbIndex);
             printpre("Renaming columns start and end to start_date and end_date in the sc_item table.");
         } catch (QueryDatabaseException $e) {
         }
     }
 }
 /**
  * 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();
 }
 /**
  * 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();
 }
 /**
  * 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);
     }
 }