From: <jfi...@us...> - 2003-02-09 00:51:34
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1:/tmp/cvs-serv25566/core Modified Files: project_api.php version_api.php Log Message: * constant_inc.php (ERROR_DUPLICATE_VERSION): removed (ERROR_VERSION_DUPLICATE): added (ERROR_VERSION_NOT_FOUND): added * manage_proj_ver_add.php: * manage_proj_ver_delete.php: * manage_proj_ver_edit_page.php: * manage_proj_ver_update.php: cleaned up all these files * manage_proj_edit_page.php: use string_display() before showing the version name * core/version_api.php - cleaned up all API functions to use config_get() instead of globals and db_prepare_*() functions (version_is_duplicate): renamed to version_is_unique() and logic reversed (version_is_unique): new function (version_ensure_unique): new function (version_exists): new function (version_ensure_exists): new function (version_delete): renamed to version_remove() to be symmetric with version_add() (version_remove): renamed from version_delete() to be symmetric with version_add() (version_update): update the bugs as well as the version table * core/project_api.php (project_delete): synch with rename of version_delete_all() to version_remove_all() * lang/* (ERROR_DUPLICATE_VERSION): renamed to ERROR_VERSION_DUPLICATE (ERROR_VERSION_DUPLICATE): renamed from ERROR_DUPLICATE_VERSION * lang/strings_english.txt (ERROR_VERSION_NOT_FOUND): added Index: project_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/project_api.php,v retrieving revision 1.27 retrieving revision 1.28 diff -u -d -r1.27 -r1.28 --- project_api.php 8 Feb 2003 23:33:00 -0000 1.27 +++ project_api.php 9 Feb 2003 00:51:00 -0000 1.28 @@ -210,7 +210,7 @@ category_remove_all( $p_project_id ); # Delete the project versions - version_delete_all( $p_project_id ); + version_remove_all( $p_project_id ); # Delete the project files project_delete_all_files( $p_project_id ); Index: version_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/version_api.php,v retrieving revision 1.6 retrieving revision 1.7 diff -u -d -r1.6 -r1.7 --- version_api.php 30 Jan 2003 09:41:39 -0000 1.6 +++ version_api.php 9 Feb 2003 00:51:00 -0000 1.7 @@ -13,90 +13,189 @@ # Version API ########################################################################### + #=================================== + # Boolean queries and ensures + #=================================== + # -------------------- - # checks to see if the version is a duplicate - # we do it this way because each different project can have the same category names - # The old version name is excluded from the search for duplicates since a version - # can re-take its name. It is also useful when changing the case of a version name. - # For example, "version" -> "Version". - function version_is_duplicate( $p_project_id, $p_version, $p_date_order='0', $p_old_version = '' ) { - $c_project_id = db_prepare_int($p_project_id); - $c_version = db_prepare_string($p_version); + # Check whether the version exists + # Returns true if the version exists, false otherwise + function version_exists( $p_project_id, $p_version ) { + $c_project_id = db_prepare_int( $p_project_id ); + $c_version = db_prepare_string( $p_version ); - $t_project_version_table = config_get('mantis_project_version_table'); + $t_project_version_table = config_get( 'mantis_project_version_table' ); $query = "SELECT COUNT(*) FROM $t_project_version_table WHERE project_id='$c_project_id' AND version='$c_version'"; - if ( strlen($p_old_version) != 0 ) { - $c_old_version = db_prepare_string($p_old_version); - $query = $query . " AND version <> '$c_old_version'"; - } + $result = db_query( $query ); + $version_count = db_result( $result ); - if ( strcmp($p_date_order, '0') != 0) { - $c_date_order = db_prepare_string($p_date_order); - $query = $query . " AND date_order='$c_date_order'"; + if ( 0 < $version_count ) { + return true; + } else { + return false; } + } - $result = db_query( $query ); - $version_count = db_result( $result, 0, 0 ); + # -------------------- + # Check whether the version name is unique + # Returns true if the name is unique, false otherwise + function version_is_unique( $p_project_id, $p_version ) { + return ! version_exists( $p_project_id, $p_version ); + } - return ( $version_count > 0 ); + # -------------------- + # Check whether the version exists in the project + # Trigger an error if it does not + function version_ensure_exists( $p_project_id, $p_version ) { + if ( ! version_exists( $p_project_id, $p_version ) ) { + trigger_error( ERROR_VERSION_NOT_FOUND, ERROR ); + } } + # -------------------- + # Check whether the version is unique within a project + # Trigger an error if it is not + function version_ensure_unique( $p_project_id, $p_version ) { + if ( ! version_is_unique( $p_project_id, $p_version ) ) { + trigger_error( ERROR_VERSION_DUPLICATE, ERROR ); + } + } + + + #=================================== + # Creation / Deletion / Updating + #=================================== + + # -------------------- + # Add a version to the project function version_add( $p_project_id, $p_version ) { - $c_project_id = db_prepare_int($p_project_id); - $c_version = db_prepare_string($p_version); + $c_project_id = db_prepare_int( $p_project_id ); + $c_version = db_prepare_string( $p_version ); - $t_project_version_table = config_get('mantis_project_version_table'); + version_ensure_unique( $p_project_id, $p_version ); + + $t_project_version_table = config_get( 'mantis_project_version_table' ); $query = "INSERT INTO $t_project_version_table ( project_id, version, date_order ) - VALUES ( '$c_project_id', '$c_version', NOW() )"; - return db_query( $query ); + VALUES + ( '$c_project_id', '$c_version', NOW() )"; + db_query( $query ); + + # db_query() errors on failure so: + return true; } + # -------------------- - function version_update( $p_project_id, $p_version, $p_date_order, $p_orig_version ) { - $c_project_id = db_prepare_int($p_project_id); - $c_version = db_prepare_string($p_version); - $c_date_order = db_prepare_string($p_date_order); - $c_orig_version = db_prepare_string($p_orig_version); + # Update the definition of a version + function version_update( $p_project_id, $p_version, $p_new_version, $p_date_order ) { + $c_project_id = db_prepare_int( $p_project_id ); + $c_version = db_prepare_string( $p_version ); + $c_new_version = db_prepare_string( $p_new_version ); + $c_date_order = db_prepare_string( $p_date_order ); - $t_project_version_table = config_get('mantis_project_version_table'); + version_ensure_exists( $p_project_id, $p_version ); + + # check for duplicates + if ( strtolower( $p_version ) != strtolower( $p_new_version ) && + ! version_is_unique( $p_project_id, $p_new_version ) ) { + trigger_error( ERROR_VERSION_DUPLICATE, ERROR ); + } + + $t_project_version_table = config_get( 'mantis_project_version_table' ); + $t_bug_table = config_get( 'mantis_bug_table' ); $query = "UPDATE $t_project_version_table - SET version='$c_version', + SET version='$c_new_version', date_order='$c_date_order' - WHERE version='$c_orig_version' + WHERE version='$c_version' AND project_id='$c_project_id'"; - return db_query( $query ); + db_query( $query ); + + if ( $p_version != $p_new_version ) { + $query = "UPDATE $t_bug_table + SET version='$c_new_version' + WHERE version='$c_version' + AND project_id='$c_project_id'"; + db_query( $query ); + } + + # db_query() errors on failure so: + return true; } + # -------------------- - function version_delete( $p_project_id, $p_version ) { - $c_project_id = db_prepare_int($p_project_id); - $c_version = db_prepare_string($p_version); + # Remove a version from the project + function version_remove( $p_project_id, $p_version, $p_new_version='' ) { + $c_project_id = db_prepare_int( $p_project_id ); + $c_version = db_prepare_string( $p_version ); + $c_new_version = db_prepare_string( $p_new_version ); - $t_project_version_table = config_get('mantis_project_version_table'); + version_ensure_exists( $p_project_id, $p_version ); + + $t_project_version_table = config_get( 'mantis_project_version_table' ); + $t_bug_table = config_get( 'mantis_bug_table' ); $query = "DELETE - FROM $t_project_version_table - WHERE project_id='$c_project_id' AND - version='$c_version'"; - return db_query( $query ); + FROM $t_project_version_table + WHERE project_id='$c_project_id' + AND version='$c_version'"; + db_query( $query ); + + $query = "UPDATE $t_bug_table + SET version='$c_new_version' + WHERE version='$c_version' + AND project_id='$c_project_id'"; + db_query( $query ); + + # db_query() errors on failure so: + return true; } + # -------------------- - # return all categories for the specified project id + # Remove all versions associated with a project + function version_remove_all( $p_project_id ) { + $c_project_id = db_prepare_int( $p_project_id ); + + $t_project_version_table = config_get( 'mantis_project_version_table' ); + $t_bug_table = config_get( 'mantis_bug_table' ); + + $query = "DELETE + FROM $t_project_version_table + WHERE project_id='$c_project_id'"; + + db_query( $query ); + + $query = "UPDATE $t_bug_table + SET version='' + WHERE project_id='$c_project_id'"; + db_query( $query ); + + # db_query() errors on failure so: + return true; + } + + + #=================================== + # Data Access + #=================================== + + # -------------------- + # Return all versions for the specified project function version_get_all_rows( $p_project_id ) { $c_project_id = db_prepare_int( $p_project_id ); $t_project_version_table = config_get( 'mantis_project_version_table' ); $query = "SELECT version, date_order - FROM $t_project_version_table - WHERE project_id='$c_project_id' - ORDER BY date_order DESC"; + FROM $t_project_version_table + WHERE project_id='$c_project_id' + ORDER BY date_order DESC"; $result = db_query( $query ); $count = db_num_rows( $result ); @@ -110,21 +209,5 @@ } return $rows; - } - # -------------------- - # delete all versions associated with a project - function version_delete_all( $p_project_id ) { - $c_project_id = db_prepare_int( $p_project_id ); - - $t_project_version_table = config_get( 'mantis_project_version_table' ); - - $query = "DELETE - FROM $t_project_version_table - WHERE project_id='$c_project_id'"; - - db_query( $query ); - - # db_query() errors on failure so: - return true; } ?> |