Skip to content

Commit

Permalink
Fix type error in config api queries and ensure user, projects exist …
Browse files Browse the repository at this point in the history
…before adding data
  • Loading branch information
mantis committed Jan 30, 2012
1 parent 69456d9 commit 3f2e1d1
Showing 1 changed file with 12 additions and 8 deletions.
20 changes: 12 additions & 8 deletions core/config_api.php
Expand Up @@ -340,34 +340,38 @@ function config_set( $p_option, $p_value, $p_user = NO_USER, $p_project = ALL_PR

if( config_can_set_in_database( $p_option ) ) {
// before we set in the database, ensure that the user and project id exist
project_ensure_exists( $p_project );
user_ensure_exists( $p_user );
if( $p_project !== ALL_PROJECTS ) {
project_ensure_exists( $p_project );
}
if( $p_user !== NO_USER ) {
user_ensure_exists( $p_user );
}

$t_query = "SELECT COUNT(*) from {config}
WHERE config_id = %d AND project_id = %d AND user_id = %d";
$t_result = db_query( $t_query, array( (int)$p_option, (int)$p_project, (int)$p_user ) );
WHERE config_id = %s AND project_id = %d AND user_id = %d";
$t_result = db_query( $t_query, array( $p_option, (int)$p_project, (int)$p_user ) );

$t_params = array();
if( 0 < db_result( $t_result ) ) {
$t_set_query = "UPDATE {config} SET value=%s, type=%d, access_reqd=%d
WHERE config_id = %d AND project_id = %d AND user_id = %d";
WHERE config_id = %s AND project_id = %d AND user_id = %d";
$t_params = array(
$c_value,
$t_type,
(int)$p_access,
(int)$p_option,
$p_option,
(int)$p_project,
(int)$p_user,
);
} else {
$t_set_query = "INSERT INTO {config}
( value, type, access_reqd, config_id, project_id, user_id )
VALUES ( %s, %d, %d, %d, %d,%d )";
VALUES ( %s, %d, %d, %s, %d,%d )";
$t_params = array(
$c_value,
$t_type,
(int)$p_access,
(int)$p_option,
$p_option,
(int)$p_project,
(int)$p_user,
);
Expand Down

0 comments on commit 3f2e1d1

Please sign in to comment.