From: Glenn H. <thr...@us...> - 2005-06-17 14:55:01
|
Update of /cvsroot/mantisbt/mantisbt/core In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv11527/core Modified Files: config_api.php project_api.php user_pref_api.php Log Message: delete project specific user preferences and configuration upon deleting project Index: user_pref_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/user_pref_api.php,v retrieving revision 1.23 retrieving revision 1.24 diff -u -d -r1.23 -r1.24 --- user_pref_api.php 26 Feb 2005 15:16:46 -0000 1.23 +++ user_pref_api.php 17 Jun 2005 14:54:53 -0000 1.24 @@ -286,6 +286,26 @@ return true; } + # -------------------- + # delete all preferences for a project for all users (part of deleting the project) + # returns true if the prefs were successfully deleted + # + # It is far more efficient to delete them all in one query than to + # call user_pref_delete() for each one and the code is short so that's + # what we do + function user_pref_delete_project( $p_project_id ) { + $c_project_id = db_prepare_int( $p_project_id ); + + $t_user_pref_table = config_get( 'mantis_user_pref_table' ); + + $query = "DELETE FROM $t_user_pref_table + WHERE project_id='$c_project_id'"; + db_query( $query ); + + # db_query() errors on failure so: + return true; + } + #=================================== # Data Access Index: project_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/project_api.php,v retrieving revision 1.73 retrieving revision 1.74 diff -u -d -r1.73 -r1.74 --- project_api.php 12 May 2005 21:42:06 -0000 1.73 +++ project_api.php 17 Jun 2005 14:54:53 -0000 1.74 @@ -237,7 +237,8 @@ # Delete a project function project_delete( $p_project_id ) { $t_email_notifications = config_get( 'enable_email_notification' ); - config_set( 'enable_email_notification', OFF ); + # temporarily disable all notifications + config_set_cache( 'enable_email_notification', OFF ); $c_project_id = db_prepare_int( $p_project_id ); @@ -266,6 +267,12 @@ # Delete all news entries associated with the project being deleted news_delete_all( $p_project_id ); + + # Delete project specific configurations + config_delete_project( $p_project_id ); + + # Delete any user prefs that are project specific + user_pref_delete_project( $p_project_id ); # Delete the project entry $query = "DELETE FROM $t_project_table @@ -273,7 +280,7 @@ db_query( $query ); - config_set( 'enable_email_notification', $t_email_notifications ); + config_set_cache( 'enable_email_notification', $t_email_notifications ); project_clear_cache( $p_project_id ); Index: config_api.php =================================================================== RCS file: /cvsroot/mantisbt/mantisbt/core/config_api.php,v retrieving revision 1.28 retrieving revision 1.29 diff -u -d -r1.28 -r1.29 --- config_api.php 16 Jun 2005 02:26:48 -0000 1.28 +++ config_api.php 17 Jun 2005 14:54:53 -0000 1.29 @@ -266,6 +266,17 @@ } # ------------------ + # Sets the value of the given config option to the given value + # If the config option does not exist, an ERROR is triggered + function config_set_cache( $p_option, $p_value, $p_user = NO_USER, $p_project = ALL_PROJECTS, $p_access = ADMINISTRATOR ) { + global $g_cache_config, $g_cache_config_access; + $g_cache_config[$p_option] = $p_value; + $g_cache_config_access[$p_option] = $p_access; + + return true; + } + + # ------------------ # delete the config entry function config_delete( $p_option, $p_user = ALL_USERS, $p_project = ALL_PROJECTS ) { global $g_cache_config, $g_cache_config_access; @@ -295,6 +306,21 @@ } # ------------------ + # delete the config entry + function config_delete_project( $p_project = ALL_PROJECTS ) { + global $g_cache_config, $g_cache_config_access; + $t_config_table = config_get_global( 'mantis_config_table' ); + $c_project = db_prepare_int( $p_project ); + $query = "DELETE FROM $t_config_table + WHERE project_id=$c_project"; + + $result = @db_query( $query); + + # flush cache here in case some of the deleted configs are in use. + config_flush_cache(); + } + + # ------------------ # delete the config entry from the cache # @@@ to be used sparingly function config_flush_cache( $p_option='' ) { |