Inheritance: extends Query
コード例 #1
0
ファイル: GateManager.obj.php プロジェクト: jrgns/backend-php
 public function post_permissions($component = false)
 {
     $parameters = array();
     $query = new DeleteQuery('Permission');
     $query->filter("`role` != 'nobody'")->filter("`role` != 'superadmin'");
     if ($component) {
         $query->filter('`subject` = :component');
         $parameters[':component'] = class_for_url($component);
     }
     $result = $query->execute($parameters);
     if ($result === false) {
         Backend::addError('Could not empty permissions table');
         return false;
     }
     $permission = new PermissionObj();
     $count = 0;
     foreach (Controller::getPayload() as $key => $roles) {
         if (strpos($key, '::') === false) {
             continue;
         }
         list($subject, $action) = explode('::', $key, 2);
         foreach ($roles as $role => $value) {
             $data = array('subject' => $subject, 'action' => $action, 'role' => $role);
             if ($permission->replace($data)) {
                 $count++;
             }
         }
     }
     return $count;
 }
コード例 #2
0
 public function testOrderLimitOnMultiple()
 {
     try {
         $q = new DeleteQuery(array('test', 'test2', 'test3'));
         $q->setLimit(10);
         $this->fail('LIMIT should not be allowed on multi-table queries');
     } catch (LogicException $e) {
     }
     try {
         $q = new DeleteQuery(array('test', 'test2', 'test3'));
         $q->setOrderBy(array(new Field('field1')));
         $this->fail('ORDER BY should not be allowed on multi-table queries');
     } catch (LogicException $e) {
     }
 }
コード例 #3
0
 /**
  * Deletes the data row from the appropriate table.
  * @param integer $dbID The {@link DBHandler} database ID to query.
  * @param integer $dataID The ID in the database of the data to be deleted.
  * @access public
  * @return void
  */
 function prune($dbID, $dataID)
 {
     if (!$dataID) {
         return;
     }
     // delete ourselves from our data table
     $table = $this->_table;
     $query = new DeleteQuery();
     $query->setTable($table);
     $query->setWhere("id='" . addslashes($dataID) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $res = $dbHandler->query($query, $dbID);
     if (!$res) {
         throwError(new UnknownDBError("StorablePrimitive"));
     }
 }
コード例 #4
0
 /**
  * Delete all objects
  *
  * This creates a single delete query using the complete keys of 
  * each of the dbobjects that has been registered
  */
 function delete()
 {
     if (count($this->dbobjects) && is_array($this->dbobjects)) {
         $clause = new Clause();
         $class_name = $this->class_name;
         $obj = new $class_name();
         DbObject::cascadeDelete($this->dbobjects);
         foreach ($this->dbobjects as $dbobj) {
             /**$sub_clause = new Clause();
             
                                 foreach($dbobj->primaryKeys() as $field)
                                 {
                                     $sub_clause->addTableCondition($obj->tableName(),$field->name(),$field->value());
                                 }*/
             if ($dbobj->db_clause) {
                 $clause->addSubClause($dbobj->db_clause, Clause::OR_REL, Clause::LAST);
             } else {
                 $clause->addSubClause($dbobj->uniqueClause(), Clause::OR_REL, Clause::LAST);
             }
         }
         $query = new DeleteQuery($obj->tableName());
         $query->setClause($clause);
         Session::unRegister($this->class_name . '_rel_deleteregister');
         $query->doQuery();
     }
 }
コード例 #5
0
 /**
  * Delete the DMRecord Set and any records that are referenced only by this record
  * set and not shared with other record sets.
  * 
  * @param int $id The Id of the set to delete.
  * @param optional boolean $prune If TRUE will make sure that the Records are removed
  * from the database.
  * @return void
  * @access public
  * @since 10/6/04
  */
 function deleteRecordSet($id, $prune = false)
 {
     ArgumentValidator::validate($id, StringValidatorRule::getRule());
     $recordSet = $this->fetchRecordSet($id);
     $recordSet->loadRecords($prune ? RECORD_FULL : RECORD_NODATA);
     // Delete the records in the set.
     $records = $recordSet->getRecords();
     foreach (array_keys($records) as $key) {
         $record = $records[$key];
         // Only delete records if they are not shared with other sets.
         $setsContaining = $this->getRecordSetIDsContaining($record);
         if (count($setsContaining) == 1 && $setsContaing[0] == $id) {
             $this->deleteRecord($record->getID(), $prune);
         }
     }
     // Delete the set from the database
     $query = new DeleteQuery();
     $query->setTable("dm_record_set");
     $query->addWhere("id = '" . addslashes($id) . "'");
     $dbHandler = Services::getService("DatabaseManager");
     $result = $dbHandler->query($query, DATAMANAGER_DBID);
     $this->_recordSetCache[$id] = NULL;
     unset($this->_recordSetCache[$id]);
 }
コード例 #6
0
ファイル: Tag.class.php プロジェクト: adamfranco/harmoni
 /**
  * Remove the tag everywhere where the current user has added it.
  * 
  * @return void
  * @access public
  * @since 11/2/06
  */
 function removeAllMine()
 {
     $query = new DeleteQuery();
     $query->setTable('tag');
     $query->addWhere("tag.value='" . addslashes($this->getValue()) . "'");
     $query->addWhere("tag.user_id='" . addslashes($this->getCurrentUserIdString()) . "'");
     $dbc = Services::getService("DatabaseManager");
     $dbc->query($query, $this->getDatabaseIndex());
 }
コード例 #7
0
 /**
  * Remove a student from the roster.
  * 
  * @param object Id $agentId
  * 
  * @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_ID
  *		   UNKNOWN_ID}
  * 
  * @access public
  */
 function removeStudent(Id $agentId)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_enroll');
     $query->addWhere("fk_cm_section='" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("fk_student_id='" . addslashes($agentId->getIdString()) . "'");
     $dbManager->query($query);
 }
コード例 #8
0
ファイル: SiteTheme.class.php プロジェクト: adamfranco/segue
 /**
  * Add a new image at the path specified.
  * 
  * @param object Harmoni_Filing_FileInterface $image
  * @param string $filename
  * @param string $prefixPath
  * @return null
  * @access public
  * @since 5/15/08
  */
 public function addImage(Harmoni_Filing_FileInterface $image, $filename, $prefixPath = '')
 {
     if (!$this->canModify()) {
         throw new PermissionDeniedException();
     }
     ArgumentValidator::validate($filename, NonzeroLengthStringValidatorRule::getRule());
     $path = trim($prefixPath, '/');
     if (strlen($path)) {
         $path = $path . '/' . $filename;
     } else {
         $path = $filename;
     }
     // Delete the old image
     $query = new DeleteQuery();
     $query->setTable('segue_site_theme_image');
     $query->addWhereEqual('fk_theme', $this->id);
     $query->addWhereEqual('path', $path);
     $dbc = Services::getService('DatabaseManager');
     $dbc->query($query, $this->databaseIndex);
     $query = new InsertQuery();
     $query->setTable('segue_site_theme_image');
     $query->addValue('fk_theme', $this->id);
     $query->addValue('mime_type', $image->getMimeType());
     $query->addValue('path', $path);
     $query->addValue('size', $image->getSize());
     $query->addValue('data', base64_encode($image->getContents()));
     $dbc = Services::getService('DatabaseManager');
     $dbc->query($query, $this->databaseIndex);
 }
コード例 #9
0
ファイル: ThemeImage.class.php プロジェクト: adamfranco/segue
 /**
  * Delete the file.
  * 
  * @return null
  * @access public
  * @since 5/15/08
  */
 public function delete()
 {
     $query = new DeleteQuery();
     $query->setTable('segue_site_theme_image');
     $query->addWhereEqual('fk_theme', $this->themeId);
     $query->addWhereEqual('path', $this->path);
     $dbMgr = Services::getService("DatabaseManager");
     $dbMgr->query($query, $this->databaseIndex);
 }
コード例 #10
0
 /**
  * Remove the mapping between AuthNTokens and an Agent
  * 
  * @param object AgentTokenMapping $mapping
  * @return void
  * @access public
  * @since 3/9/05
  */
 function deleteMapping(AgentTokenMapping $mapping)
 {
     $this->_checkConfig();
     $dbc = Services::getService("DatabaseManager");
     $dbc->beginTransaction($this->_dbId);
     $agentId = $mapping->getAgentId();
     $authNTokens = $mapping->getTokens();
     $typeKey = $this->_getTypeKey($mapping->getAuthenticationType());
     // Delete the mapping.
     $query = new DeleteQuery();
     $query->setTable($this->_mappingTable);
     $query->addWhere("agent_id='" . addslashes($agentId->getIdString()) . "'");
     $query->addWhere("token_identifier='" . addslashes($authNTokens->getIdentifier()) . "'", _AND);
     $query->addWhere("fk_type='" . addslashes($typeKey) . "'", _AND);
     $result = $dbc->query($query, $this->_dbId);
     // Delete the type if nothing is referencing it.
     $query = new SelectQuery();
     $query->addTable($this->_mappingTable);
     $query->addColumn("COUNT(*)", "count");
     $query->addWhere("fk_type='" . addslashes($typeKey) . "'");
     $result = $dbc->query($query, $this->_dbId);
     if ($result->getNumberOfRows() == 0) {
         $query = new DeleteQuery();
         $query->addTable($this->_typeTable);
         $query->addWhere("id='" . addslashes($typeKey) . "'");
         $result = $dbc->query($query, $this->_dbId);
     }
     $result->free();
     $dbc->commitTransaction($this->_dbId);
 }
コード例 #11
0
 /**
  * Delete all properties associated with an object
  * This is here partially to preserve the option of using non-editable agents
  * If that ceases to be an issue, this more properly belongs in
  * HarmoniEditableAgent.class
  *
  * @param string $object_id_string
  * @return boolean
  * @access public
  */
 function deleteAllProperties($object_id_string)
 {
     $dbHandler = Services::getService("DBHandler");
     //create a query to remove all properties associated with $object_id_string
     $query = new DeleteQuery();
     $query->setTable("agent_properties");
     $query->addWhere("fk_object_id='{$object_id_string}'");
     $result = $dbHandler->query($query, $this->_dbIndex);
     return $result ? true : false;
 }
コード例 #12
0
 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();
 }
コード例 #13
0
 /**
  * Delete the log with the specified name.
  * 
  * @param string $logName
  * 
  * @throws object LoggingException An exception with one of the
  *		   following messages defined in org.osid.logging.LoggingException
  *		   may be thrown:  {@link
  *		   org.osid.logging.LoggingException#UNIMPLEMENTED UNIMPLEMENTED},
  *		   {@link org.osid.logging.LoggingException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.logging.LoggingException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.logging.LoggingException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.logging.LoggingException#UNKNOWN_NAME UNKNOWN_NAME}
  * 
  * @access public
  */
 function deleteLog($logName)
 {
     $log = $this->getLogForWriting($logName);
     $log = null;
     $dbc = Services::getService("DatabaseManager");
     // get the entry Ids
     $query = new SelectQuery();
     $query->addColumn("id");
     $query->addTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $result = $dbc->query($query, $this->_dbIndex);
     $entryIds = array();
     while ($result->hasMoreRows()) {
         $entryIds[] = "'" . addslashes($result->field("id")) . "'";
         $result->advanceRow();
     }
     $result->free();
     // delete the agent keys
     $query = new DeleteQuery();
     $query->setTable("log_agent");
     $query->addWhere("fk_entry IN (" . implode(", ", $entryIds) . ")");
     $dbc->query($query, $this->_dbIndex);
     // delete the node keys
     $query->setTable("log_node");
     $dbc->query($query, $this->_dbIndex);
     // delete the entries
     $query = new DeleteQuery();
     $query->setTable("log_entry");
     $query->addWhere("log_name = '" . addslashes($logName) . "'");
     $dbc->query($query, $this->_dbIndex);
 }
コード例 #14
0
 /**
  * Clear the ancestory rows for a given node
  * 
  * @param string $idString
  * @return void
  * @access public
  * @since 11/4/05
  */
 function clearNodeAncestory($idString)
 {
     // Delete the old ancestory
     if (isset($this->harmoni_db)) {
         if (!isset($this->clearNodeAncestory_stmt)) {
             $query = $this->harmoni_db->delete();
             $query->setTable("az2_node_ancestry");
             $query->addWhereRawEqual("fk_hierarchy", '?');
             $query->addWhereRawEqual("fk_node", '?');
             $this->clearNodeAncestory_stmt = $query->prepare();
         }
         $this->clearNodeAncestory_stmt->bindValue(1, $this->_hierarchyId);
         $this->clearNodeAncestory_stmt->bindValue(2, $idString);
         $this->clearNodeAncestory_stmt->execute();
     } else {
         $dbHandler = Services::getService("DatabaseManager");
         $query = new DeleteQuery();
         $query->setTable("az2_node_ancestry");
         $query->addWhereEqual("fk_hierarchy", $this->_hierarchyId);
         $query->addWhereEqual("fk_node", $idString);
         $queryResult = $dbHandler->query($query, $this->_dbIndex);
     }
 }
コード例 #15
0
 /**
  * Delete the specified CourseGradeRecord by Id. courseGradeRecordId
  *
  * @param object Id $courseGradeRecordId
  *
  * @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_ID
  *		   UNKNOWN_ID}
  *
  * @access public
  */
 function deleteCourseGradeRecord(Id $courseGradeRecordId)
 {
     ArgumentValidator::validate($courseGradeRecordId, ExtendsValidatorRule::getRule("Id"), true);
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('cm_grade_rec');
     $query->addWhere("id=" . addslashes($courseGradeRecordId->getIdString()));
     $dbManager->query($query);
 }
コード例 #16
0
ファイル: GateKeeper.obj.php プロジェクト: jrgns/backend-php
 public static function dropAccess($access_type, $access_id)
 {
     $params = array(':access_type' => $access_type, ':access_id' => $access_id);
     $query = new DeleteQuery('Assignment');
     $query->filter('`access_type` = :access_type')->filter('`access_id` = :access_id');
     $result = $query->execute($params) !== false ? true : false;
     return $result;
 }
コード例 #17
0
 /**
  * Store a mapping between Segue1 ids and Segue2 ids
  * 
  * @return void
  * @access protected
  * @since 3/20/08
  */
 protected function storeSegue1IdMapping()
 {
     if (!isset($this->origenSlotname)) {
         throw new OperationFailedException("Origen slot not set. Call " . get_class($this) . "->setOrigenSlotname('xxxxx').");
     }
     if (!isset($this->destSlotname)) {
         throw new OperationFailedException("Destination slot not set. Call " . get_class($this) . "->setDestinationSlotname('xxxxx').");
     }
     $dbc = Services::getService('DatabaseManager');
     $map = $this->filterNonAccessible($this->getIdMap());
     // 		printpre(htmlentities($this->doc->saveXMLWithWhitespace()));
     // 		printpre($map);
     // 		throw new Exception('test');
     // Delete any old mappings
     $query = new DeleteQuery();
     $query->setTable('segue1_id_map');
     $query->addWhereIn('segue1_id', array_keys($map));
     $dbc->query($query, IMPORTER_CONNECTION);
     // Add new mappings
     $query = new InsertQuery();
     $query->setTable('segue1_id_map');
     foreach ($map as $segue1Id => $segue2Id) {
         $query->createRow();
         $query->addValue('segue1_slot_name', $this->origenSlotname);
         $query->addValue('segue1_id', $segue1Id);
         $query->addValue('segue2_slot_name', $this->destSlotname);
         $query->addValue('segue2_id', $segue2Id);
     }
     $dbc->query($query, IMPORTER_CONNECTION);
 }
コード例 #18
0
 /**
  * Tests the generateSQLQuery() without WHERE clause.
  */
 function test()
 {
     // insert one row
     $query = new InsertQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->addRowOfValues(array("'Spaceboy'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     $lastId = $result->getLastAutoIncrementValue();
     // insert it again, the id must have increased by one
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 1);
     // add several rows at the same time
     $query->addRowOfValues(array("'Astrogirl'"));
     $result = $this->db->query($query);
     $this->assertIdentical($result->getLastAutoIncrementValue(), $lastId + 3);
     // now insert in the other test table
     $query = new InsertQuery();
     $query->setTable("test");
     $query->setColumns(array("FK", "value"));
     $query->addRowOfValues(array($lastId, "'Ziggy'"));
     $query->addRowOfValues(array($lastId + 1, "'Lost in the Stars'"));
     $query->addRowOfValues(array($lastId + 2, "'Headstar'"));
     $query->addRowOfValues(array($lastId + 3, "'Stardust'"));
     $query->setAutoIncrementColumn("id", "test1_id_seq");
     $result = $this->db->query($query);
     // join the inserted rows
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addTable("test", INNER_JOIN, "test.FK = test1.id");
     $query->addColumn("id", "dm86_id", "test");
     $query->addColumn("FK", "dm86_fk", "test");
     $query->addColumn("value", "dm86_value", "test");
     $query->addColumn("id", "dm98_id", "test1");
     $query->addColumn("value", "dm98_value", "test1");
     $query->addWhere("test1.id >= " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 4);
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId);
     $this->assertIdentical($result->field("dm86_value"), "Ziggy");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 1);
     $this->assertIdentical($result->field("dm86_value"), "Lost in the Stars");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 1);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 2);
     $this->assertIdentical($result->field("dm86_value"), "Headstar");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 2);
     $this->assertIdentical($result->field("dm98_value"), "Spaceboy");
     $result->advanceRow();
     $this->assertIdentical((int) $result->field("dm86_fk"), $lastId + 3);
     $this->assertIdentical($result->field("dm86_value"), "Stardust");
     $this->assertIdentical((int) $result->field("dm98_id"), $lastId + 3);
     $this->assertIdentical($result->field("dm98_value"), "Astrogirl");
     $result->free();
     $query = new UpdateQuery();
     $query->setTable("test1");
     $query->setColumns(array("value"));
     $query->setValues(array("'I changed you MF!'"));
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $this->assertIdentical($result->field("value"), "I changed you MF!");
     $result->free();
     $query = new DeleteQuery();
     $query->setTable("test1");
     $query->addWhere("id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 1);
     $query = new SelectQuery();
     $query->addTable("test1");
     $query->addColumn("value");
     $query->addWhere("test1.id = " . $lastId);
     $result = $this->db->query($query);
     $this->assertIdentical($result->getNumberOfRows(), 0);
     $result->free();
 }
コード例 #19
0
 /**
  * Delete the item and all tags for it. This should be done when deleting
  * the thing the item represents
  * 
  * @param mixed $items This can be a single Item object, an TaggedItemIterator, 
  * 		or an array of Item objects.
  * @return void
  * @access public
  * @since 11/2/06
  */
 function deleteItems($items)
 {
     $itemDbIds = array();
     // array
     if (is_array($items)) {
         foreach (array_keys($items) as $key) {
             $itemDbIds[] = "'" . addslashes($items[$key]->getDatabaseId()) . "'";
         }
     } else {
         if (method_exists($items, 'next')) {
             while ($items->hasNext()) {
                 $item = $items->next();
                 $itemDbIds[] = "'" . addslashes($item->getDatabaseId()) . "'";
             }
         } else {
             if (method_exists($items, 'getDatabaseId')) {
                 $itemDbIds[] = "'" . addslashes($items->getDatabaseId()) . "'";
             } else {
                 throwError(new Error("Invalid parameter, {$items}, for \$items", "Tagging"));
             }
         }
     }
     if (!count($itemDbIds)) {
         return;
     }
     $dbc = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('tag');
     $query->addWhere("tag.fk_item IN (" . implode(", ", $itemDbIds) . ")");
     $dbc->query($query, $this->getDatabaseIndex());
     $query = new DeleteQuery();
     $query->setTable('tag_item');
     $query->addWhere("id IN (" . implode(", ", $itemDbIds) . ")");
     $dbc->query($query, $this->getDatabaseIndex());
 }
コード例 #20
0
 /**
  * Performs a deletion of persisten objects.
  *
  * @return int
  */
 function delete()
 {
     $deleteQuery = new DeleteQuery($this->entity->getPhysicalSchema()->getTable());
     $deleteQuery->setCondition($this->toExpression());
     $affected = $this->entity->getDao()->executeQuery($deleteQuery);
     return $affected;
 }
コード例 #21
0
 /**
  * Delete this object from the database
  *
  * This will also handle deletion of all dependent objects, and any join relationships
  * (but not the joined objects themselves). If you do not require any complex 
  * deletion like this, the feel free to use the {@link SimpleQuery::create()} method to 
  * do a quick and simple delete operation, but make sure to call the 
  * {@link clearQueryCache()} method afterwards, like this:
  *
  * <code>
  * $book = new Book();
  * SimpleQuery::create('DELETE FROM '.$book->tableName().' 
  *                WHERE book_id = '.Query::clean(Application::param('book_id')));
  * $book->clearQueryCache();
  * </code>
  *
  * @access public
  * @see save,deleteLater,purge
  */
 public function delete($clear = false)
 {
     if (is_object($this->super_object)) {
         throw new Exception('You called delete() on a DbObject that has a super object (a generalised object) present. Either don\'t call also(\'' . $this->superObject()->getClass() . '\') when building the query, or call delete() on the super object. eg. $specialised->superObject()->delete()');
     }
     if ($this->db_clause || $clear || $this->id()) {
         if ($this->read() || $clear || $this->id()) {
             $this->clearAllJoins();
             $this->clearAllSupported();
             foreach ($this->existing_objects as $class => $objects) {
                 foreach ($objects as $key => $obj) {
                     $this->deleteObject($obj);
                 }
             }
             $this->existing_objects = array();
             $query = new DeleteQuery($this->tableName());
             $query->setClause($this->uniqueClause());
             $query->doQuery();
             $this->purge();
             $this->clearQueryCache();
         }
     } else {
         throw new Exception('You cannot call delete on a DbObject if you have not added conditions to it using the clause() method. If you wish to delete all instances of a particular object, use the clearTable() method');
     }
 }
コード例 #22
0
 /**
  * Delete a Record.  If the specified Record has content that is inherited
  * by other Records, those other Records will not be deleted, but they
  * will no longer have a source from which to inherit value changes.
  * 
  * @param object Id $recordId
  * 
  * @throws object RepositoryException An exception with one of
  *         the following messages defined in
  *         org.osid.repository.RepositoryException may be thrown: {@link
  *         org.osid.repository.RepositoryException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.repository.RepositoryException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.repository.RepositoryException#UNIMPLEMENTED
  *         UNIMPLEMENTED}, {@link
  *         org.osid.repository.RepositoryException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function deleteRecord(Id $recordId)
 {
     $record = $this->getRecord($recordId);
     $structure = $record->getRecordStructure();
     $structureId = $structure->getId();
     // If this is a schema that is hard coded into our implementation, create
     // a record for that schema.
     if (in_array($structureId->getIdString(), array_keys($this->_repository->_builtInTypes))) {
         // Delete all of the Parts for the record
         $parts = $record->getParts();
         while ($parts->hasNext()) {
             $part = $parts->next();
             $record->deletePart($part->getId());
         }
         // Delete the relation for the record.
         $dbHandler = Services::getService("DatabaseManager");
         $query = new DeleteQuery();
         $query->setTable("dr_asset_record");
         $myId = $this->getId();
         $query->addWhere("fk_asset = '" . $myId->getIdString() . "'");
         $query->addWhere("fk_record = '" . $recordId->getIdString() . "'");
         $result = $dbHandler->query($query, $this->_dbIndex);
     } else {
         $recordMgr = Services::getService("RecordManager");
         $record = $recordMgr->fetchRecord($recordId->getIdString(), RECORD_FULL);
         // Check if the record is part of other record sets (assets via inheretance)
         $myId = $this->getId();
         $setsContaining = $recordMgr->getRecordSetIDsContaining($record);
         $myRecordSet = $recordMgr->fetchRecordSet($myId->getIdString());
         // If this is the last asset referencing this record, delete it.
         $idManager = Services::getService('Id');
         if (count($setsContaining) == 1 && $myId->isEqual($idManager->getId($setsContaining[0]))) {
             $myRecordSet->removeRecord($record);
             $myRecordSet->commit(TRUE);
             $record->delete();
             $record->commit(TRUE);
         } else {
             $myRecordSet = $recordMgr->fetchRecordSet($myId->getIdString());
             $myRecordSet->removeRecord($record);
             $myRecordSet->commit(TRUE);
         }
     }
     $this->updateModificationDate();
 }
コード例 #23
0
ファイル: query.php プロジェクト: D4rk4/Kusaba-z
 public function execute()
 {
     if (!count($this->condition)) {
         $total_rows = $this->connection->query('SELECT COUNT(*) FROM {' . $this->connection->escapeTable($this->table) . '}')->fetchField();
         parent::execute();
         return $total_rows;
     } else {
         return parent::execute();
     }
 }
コード例 #24
0
ファイル: DeleteQueryEngine.php プロジェクト: itarato/micmod
 public function execute()
 {
     $this->deleteQuery->execute();
 }
コード例 #25
0
 /**
  * Update the value for this Part.
  * 
  * @param object mixed $value (original type: java.io.Serializable)
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}
  * 
  * @access public
  */
 function updateValue($value)
 {
     //		ArgumentValidator::validate($value, StringValidatorRule::getRule());
     $dbHandler = Services::getService("DatabaseManager");
     // Delete the row if we are setting the value to null
     if (is_null($value)) {
         $query = new DeleteQuery();
         $query->setTable("dr_file_data");
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         $this->_asset->updateModificationDate();
         return;
     }
     // Store the data in the object in case its asked for again.
     //		$this->_data = $value;
     // Make sure that the dr_file row is inserted.
     $query = new InsertQuery();
     $query->setTable("dr_file");
     $query->addValue("id", $this->_recordId->getIdString());
     try {
         $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     } catch (QueryDatabaseException $e) {
         // If an error is thrown inserting (because the file already exists)
         // ignore it.
     }
     $dbHandler->beginTransaction($this->_configuration->getProperty("database_index"));
     // Base64 encode the data to preserve it,
     // then write it to the database.
     // Check to see if the data is in the database
     $query = new SelectQuery();
     $query->addTable("dr_file_data");
     $query->addColumn("COUNT(*) as count");
     $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     $result = $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // If it already exists, use an update query.
     if ($result->field("count") > 0) {
         $query = new UpdateQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("data"));
         $query->setValues(array("'" . base64_encode($value) . "'"));
         $query->addWhere("fk_file = '" . $this->_recordId->getIdString() . "'");
     } else {
         $query = new InsertQuery();
         $query->setTable("dr_file_data");
         $query->setColumns(array("fk_file", "data"));
         $query->setValues(array("'" . $this->_recordId->getIdString() . "'", "'" . base64_encode($value) . "'"));
     }
     $result->free();
     //		printpre($query);
     //		printpre(MySQL_SQLGenerator::generateSQLQuery($query));
     // run the query
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     // Update the size row.
     $query = new UpdateQuery();
     $query->setTable("dr_file");
     $query->addValue("size", strval(strlen($value)));
     $query->addWhereEqual("id", $this->_recordId->getIdString());
     $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
     $dbHandler->commitTransaction($this->_configuration->getProperty("database_index"));
     $this->_asset->updateModificationDate();
 }
コード例 #26
0
 /**
  * Delete a GradeRecord.  The first two parameters are required, but the
  * third may be left null to dignify any Type
  * 
  * @param object Id $gradableObjectId
  * @param object Id $agentId
  * @param object Type $GradeRecordType
  * 
  * @throws object GradingException An exception with one of the
  *         following messages defined in org.osid.grading.GradingException
  *         may be thrown:  {@link
  *         org.osid.grading.GradingException#OPERATION_FAILED
  *         OPERATION_FAILED}, {@link
  *         org.osid.grading.GradingException#PERMISSION_DENIED
  *         PERMISSION_DENIED}, {@link
  *         org.osid.grading.GradingException#CONFIGURATION_ERROR
  *         CONFIGURATION_ERROR}, {@link
  *         org.osid.grading.GradingException#UNIMPLEMENTED UNIMPLEMENTED},
  *         {@link org.osid.grading.GradingException#NULL_ARGUMENT
  *         NULL_ARGUMENT}, {@link
  *         org.osid.grading.GradingException#UNKNOWN_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function deleteGradeRecord(Id $gradableObjectId, Id $agentId, Type $GradeRecordType)
 {
     $dbManager = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('gr_record');
     $query->addWhere("fk_gr_gradable='" . addslashes($gradableObjectId->getIdString()) . "'");
     $query->addWhere("fk_agent_id='" . addslashes($agentId->getIdString()) . "'");
     if (!is_null($GradeRecordType)) {
         $query->addWhere("fk_gr_record_type='" . addslashes($this->_typeToIndex('record', $GradeRecordType)) . "'");
     }
     $dbManager->query($query);
 }
コード例 #27
0
 /**
  * Remove an External group from a Hierarchy-based group.
  * 
  * @param object Id $hierarchyParentId
  * @param object Id $externalChildId
  * @return void
  * @access public
  * @since 11/6/07
  */
 public function removeExternalChildGroup(Id $hierarchyParentId, Id $externalChildId)
 {
     // Remove the row.
     $query = new DeleteQuery();
     $query->setTable('agent_external_children');
     $query->addWhereEqual('fk_parent', $hierarchyParentId->getIdString());
     $query->addWhereEqual('fk_child', $externalChildId->getIdString());
     $dbc = Services::getService("DBHandler");
     $dbc->query($query, $this->_configuration->getProperty('database_index'));
 }
コード例 #28
0
ファイル: viewfile.act.php プロジェクト: adamfranco/polyphony
 /**
  * Write the cache
  * 
  * @return void
  * @access public
  * @since 2/13/06
  */
 function writeCache()
 {
     $dbc = Services::getService('DatabaseManager');
     $query = new DeleteQuery();
     $query->setTable('dr_resized_cache');
     $query->addWhere("dr_resized_cache.fk_file = '" . addslashes($this->_id->getIdString()) . "'");
     $query->addWhere("dr_resized_cache.size = '" . addslashes($this->_size) . "'");
     $query->addWhere("dr_resized_cache.websafe = " . ($this->_websafe ? '1' : '0'));
     $dbc->query($query, $this->getDBIndex());
     $query = new InsertQuery();
     $query->setTable('dr_resized_cache');
     $query->setColumns(array('fk_file', 'size', 'websafe', 'cache_time', 'fk_mime_type', 'data'));
     $values = array();
     $values[] = "'" . addslashes($this->_id->getIdString()) . "'";
     $values[] = "'" . addslashes($this->_size) . "'";
     $values[] = $this->_websafe ? '1' : '0';
     $values[] = "NOW()";
     $imgProcessor = Services::getService("ImageProcessor");
     if ($this->_websafe) {
         $this->_mimeType = $imgProcessor->getWebsafeFormat($this->_parts['MIME_TYPE']->getValue());
         $values[] = $this->getMimeKey();
         $values[] = "'" . addslashes($imgProcessor->getWebsafeData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'";
     } else {
         $this->_mimeType = $imgProcessor->getResizedFormat($this->_parts['MIME_TYPE']->getValue());
         $values[] = $this->getMimeKey();
         $values[] = "'" . addslashes($imgProcessor->getResizedData($this->_parts['MIME_TYPE']->getValue(), $this->_size, $this->_parts['FILE_DATA']->getValue())) . "'";
     }
     $query->addRowOfValues($values);
     $dbc->query($query, $this->getDBIndex());
 }
コード例 #29
0
 /**
  * Delete a Part and all its Parts.
  * 
  * @param object Id $partId
  * 
  * @throws object RepositoryException An exception with one of
  *		   the following messages defined in
  *		   org.osid.repository.RepositoryException may be thrown: {@link
  *		   org.osid.repository.RepositoryException#OPERATION_FAILED
  *		   OPERATION_FAILED}, {@link
  *		   org.osid.repository.RepositoryException#PERMISSION_DENIED
  *		   PERMISSION_DENIED}, {@link
  *		   org.osid.repository.RepositoryException#CONFIGURATION_ERROR
  *		   CONFIGURATION_ERROR}, {@link
  *		   org.osid.repository.RepositoryException#UNIMPLEMENTED
  *		   UNIMPLEMENTED}, {@link
  *		   org.osid.repository.RepositoryException#NULL_ARGUMENT
  *		   NULL_ARGUMENT}, {@link
  *		   org.osid.repository.RepositoryException#UNKNOWN_ID UNKNOWN_ID}
  * 
  * @access public
  */
 function deletePart(Id $partId)
 {
     $string = $partId->getIdString();
     if (preg_match("/(.*)-(" . implode("|", array_keys($this->_parts)) . ")/", $string, $r)) {
         $recordId = $r[1];
         $field = $r[2];
         if ($this->_isLastPart($field)) {
             $dbHandler = Services::getService("DatabaseManager");
             // Delete the data
             $query = new DeleteQuery();
             $query->setTable("dr_file_url");
             $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'");
             $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
             // Delete the thumbnail
             $query = new DeleteQuery();
             $query->setTable("dr_thumbnail");
             $query->setWhere("fk_file = '" . $this->_id->getIdString() . "'");
             $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
             // delete the file row.
             $query = new DeleteQuery();
             $query->setTable("dr_file");
             $query->setWhere("id = '" . $this->_id->getIdString() . "'");
             $dbHandler->query($query, $this->_configuration->getProperty("database_index"));
         } else {
             $this->_parts[$field]->updateValue("NULL");
         }
     } else {
         throwError(new Error(RepositoryException::UNKNOWN_ID() . ": {$string}", "FileRecord", true));
     }
     $this->_asset->updateModificationDate();
 }
コード例 #30
0
ファイル: remote_feed.act.php プロジェクト: adamfranco/segue
 /**
  * Save an XML string to the feed cache
  * 
  * @param string $url
  * @param string $feedXml
  * @return void
  * @access protected
  * @since 7/8/08
  */
 protected function cacheXmlString($url, $feedXml)
 {
     $dbc = Services::getService("DatabaseManager");
     $query = new DeleteQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addWhereEqual('url', $url);
     $query->addWhereRawLessThan('cache_time', $dbc->toDBDate(DateAndTime::now()->minus(Duration::withSeconds(600)), IMPORTER_CONNECTION), _OR);
     try {
         $result = $dbc->query($query, IMPORTER_CONNECTION);
     } catch (NoSuchTableDatabaseException $e) {
         $this->createCacheTable();
     }
     $query = new InsertQuery();
     $query->setTable('segue_plugins_rssfeed_cache');
     $query->addValue('url', $url);
     $query->addValue('feed_data', $feedXml);
     $dbc->query($query, IMPORTER_CONNECTION);
 }