View Issue Details

IDProjectCategoryView StatusLast Update
0026611mantisbtcustom fieldspublic2020-02-09 07:05
Reporterbluescreenterror Assigned Todregad  
PrioritynormalSeverityminorReproducibilityalways
Status closedResolutionno change required 
PlatformIntel i5OSWindows 7 
Product Version2.23.0 
Summary0026611: Mantis overrides change in custom fields values made by plugin calling custom_field_set_value triggered by EVENT_UPDATE_BUG_DATA
Description

Hi,

I started to write a plugin which updates a custom field when the status is set to resolved (comfort feature for my colleagues).

I used the function custom_field_set_value() to manipulate the custom field and get back true, from that function. I checked the db (debug-mode) and the changes where written (phpmyadmin). But the changes where rolled back by update_bug.php line 410 to 413:

# Update custom field values.
foreach ( $t_custom_fields_to_set as $t_custom_field_to_set ) {
    custom_field_set_value( $t_custom_field_to_set['id'], $f_bug_id, $t_custom_field_to_set['value'] );
}

The variable $t_custom_fields_to_set is filled with data before the event is triggered, is it possible to change that ?

EDIT [dregad] fix markdown

Steps To Reproduce

Write a plugin, triggered by event EVENT_UPDATE_BUG_DATA, try to change a custom field with the custom_field_set_value() function.

TagsNo tags attached.

Activities

bluescreenterror

bluescreenterror

2020-01-18 18:26

reporter   ~0063473

Last edited: 2020-01-18 18:28

View 4 revisions

Adding/Updating this to line 409 in bug_update.php could maybe solve the problem:

//Check if custom field where updated trough plugin
$t_custom_plugin_updated_fields_to_set = array();
foreach ( $t_custom_fields_to_set as $t_custom_field_to_set ) {
$t_updated_custom_field_value = custom_field_get_value( $t_custom_field_to_set['id'], $f_bug_id );
$t_value = $t_custom_field_to_set['value'];

if($t_updated_custom_field_value != $t_value){
    $t_value = $t_updated_custom_field_value;
}
$t_custom_plugin_updated_fields_to_set[] = array( 'id' => $t_custom_field_to_set['id'], 'value' => $t_value);

}
//Update custom field values.
foreach ( $t_custom_plugin_updated_fields_to_set as $t_custom_field_to_set ) {
custom_field_set_value( $t_custom_field_to_set['id'], $f_bug_id, $t_custom_field_to_set['value'] );
}

bluescreenterror

bluescreenterror

2020-01-19 17:32

reporter   ~0063474

Can be closed...with wont fix. Got the wrong event...to manipulate Custom_Fields you need EVENT_UPDATE_BUG.

Sry but the doc´s as thin as paper on the topic.

dregad

dregad

2020-01-20 03:11

developer   ~0063476

Thanks for the feedback

Sry but the doc´s as thin as paper on the topic.

Guilty as charged your honor... But we gladly accept pull requests if you're willing to improve it :-)

Issue History

Date Modified Username Field Change
2020-01-18 17:35 bluescreenterror New Issue
2020-01-18 18:26 bluescreenterror Note Added: 0063473
2020-01-18 18:27 bluescreenterror Note Edited: 0063473 View Revisions
2020-01-18 18:27 bluescreenterror Note Edited: 0063473 View Revisions
2020-01-18 18:28 bluescreenterror Note Edited: 0063473 View Revisions
2020-01-19 17:32 bluescreenterror Note Added: 0063474
2020-01-20 03:09 dregad Description Updated View Revisions
2020-01-20 03:11 dregad Assigned To => dregad
2020-01-20 03:11 dregad Status new => resolved
2020-01-20 03:11 dregad Resolution open => no change required
2020-01-20 03:11 dregad Note Added: 0063476
2020-02-09 07:05 atrol Status resolved => closed