function version_update($p_version_info) { version_ensure_exists($p_version_info->id); $t_old_version_name = version_get_field($p_version_info->id, 'version'); # check for duplicates if (strtolower($t_old_version_name) != strtolower($p_version_info->version) && !version_is_unique($p_version_info->version, $p_version_info->project_id)) { trigger_error(ERROR_VERSION_DUPLICATE, ERROR); } $c_version_id = db_prepare_int($p_version_info->id); $c_version_name = db_prepare_string($p_version_info->version); $c_old_version_name = db_prepare_string($t_old_version_name); $c_description = db_prepare_string($p_version_info->description); $c_released = db_prepare_int($p_version_info->released); $c_date_order = db_timestamp($p_version_info->date_order); $c_project_id = db_prepare_int($p_version_info->project_id); $t_project_version_table = config_get('mantis_project_version_table'); $t_bug_table = config_get('mantis_bug_table'); $query = "UPDATE {$t_project_version_table}\r\n\t\t\t\t SET version='{$c_version_name}',\r\n\t\t\t\t\tdescription='{$c_description}',\r\n\t\t\t\t\treleased='{$c_released}',\r\n\t\t\t\t\tdate_order={$c_date_order}\r\n\t\t\t\t WHERE id='{$c_version_id}'"; db_query($query); if ($c_version_name != $c_old_version_name) { $query = "UPDATE {$t_bug_table}\r\n\t\t\t\t\t SET version='{$c_version_name}'\r\n\t\t\t\t\t WHERE ( project_id='{$c_project_id}' ) AND ( version='{$c_old_version_name}' )"; db_query($query); $query = "UPDATE {$t_bug_table}\r\n\t\t\t\t\t SET fixed_in_version='{$c_version_name}'\r\n\t\t\t\t\t WHERE ( project_id='{$c_project_id}' ) AND ( fixed_in_version='{$c_old_version_name}' )"; db_query($query); $query = "UPDATE {$t_bug_table}\r\n\t\t\t\t\t SET target_version='{$c_version_name}'\r\n\t\t\t\t\t WHERE ( project_id='{$c_project_id}' ) AND ( target_version='{$c_old_version_name}' )"; db_query($query); # @@@ We should consider using ids instead of names for foreign keys. The main advantage of using the names are: # - for history the version history entries will still be valid even if the version is deleted in the future. -- we can ban deleting referenced versions. # - when an issue is copied or moved from one project to another, we can keep the last version with the issue even if it doesn't exist in the new project. Also previous history entries remain valid. # @@@ We should update the history for version, fixed_in_version, and target_version. # @@@ We probably need to update the saved filters too? } # db_query() errors on failure so: return true; }
/** * Update a token * @param integer Token ID * @param string Token value * @param integer Token expiration in seconds */ function token_update($p_token_id, $p_value, $p_expiry = TOKEN_EXPIRY) { token_ensure_exists($p_token_id); $c_token_id = db_prepare_int($p_token_id); $c_value = db_prepare_string($p_value); $c_expiry = db_timestamp(db_date(time() + $p_expiry)); $t_tokens_table = config_get('mantis_tokens_table'); $query = "UPDATE {$t_tokens_table} \n\t\t\t\t\tSET value='{$c_value}', expiry={$c_expiry}\n\t\t\t\t\tWHERE id={$c_token_id}"; db_query($query); return true; }