| 1293 |
dpurdie |
1 |
###############################################################################
|
|
|
2 |
# Codestriker: Copyright (c) 2001, 2002 David Sitsky. All rights reserved.
|
|
|
3 |
# sits@users.sourceforge.net
|
|
|
4 |
#
|
|
|
5 |
# This program is free software; you can redistribute it and modify it under
|
|
|
6 |
# the terms of the GPL.
|
|
|
7 |
|
|
|
8 |
# Action object for the submission of changing multiple comment states.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::SubmitEditCommentsState;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
use Codestriker::Action::ViewTopicComments;
|
|
|
15 |
use Codestriker::TopicListeners::Manager;
|
|
|
16 |
|
|
|
17 |
# Attempt to change the comment states, in particular the metrics associated
|
|
|
18 |
# with them.
|
|
|
19 |
sub process($$$) {
|
|
|
20 |
my ($type, $http_input, $http_response) = @_;
|
|
|
21 |
|
|
|
22 |
my $query = $http_response->get_query();
|
|
|
23 |
|
|
|
24 |
# Extract the values from the action.
|
|
|
25 |
my $topicid = $http_input->get('topic');
|
|
|
26 |
my $email = $http_input->get('email');
|
|
|
27 |
|
|
|
28 |
if (Codestriker::Model::Topic::exists($topicid) == 0) {
|
|
|
29 |
# Topic no longer exists, most likely its been deleted.
|
|
|
30 |
$http_response->error("Topic no longer exists.");
|
|
|
31 |
return;
|
|
|
32 |
}
|
|
|
33 |
|
|
|
34 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
35 |
|
|
|
36 |
# Any feedback messages to the user.
|
|
|
37 |
my $feedback = "";
|
|
|
38 |
|
|
|
39 |
# Indicate if changes were made to stale comments.
|
|
|
40 |
my $stale = 0;
|
|
|
41 |
|
|
|
42 |
# The number of commentstates changed.
|
|
|
43 |
my $comments_processed = 0;
|
|
|
44 |
|
|
|
45 |
# Determine the mapping of comment state to version numbers, recorded
|
|
|
46 |
# in the form submission, to ensure the versions being changed aren't
|
|
|
47 |
# stale.
|
|
|
48 |
my %comment_state_version_map = ();
|
|
|
49 |
my %comment_state_new_map = ();
|
|
|
50 |
foreach my $param_name ($query->param()) {
|
|
|
51 |
foreach my $metric (@{$Codestriker::comment_state_metrics}) {
|
|
|
52 |
my $metric_name = $metric->{name};
|
|
|
53 |
my $prefix = "comment_state_metric\\|$metric_name";
|
|
|
54 |
if ($param_name =~ /^($prefix\|\-?\d+\|\-?\d+\|\d+)\|(\d+)$/) {
|
|
|
55 |
$comment_state_version_map{$1} = $2;
|
|
|
56 |
$comment_state_new_map{$1} = $query->param($param_name);
|
|
|
57 |
}
|
|
|
58 |
}
|
|
|
59 |
}
|
|
|
60 |
|
|
|
61 |
# Go through all of the commentstate records, and change anything that
|
|
|
62 |
# needs changing.
|
|
|
63 |
my @topic_comments = $topic->read_comments();
|
|
|
64 |
my %processed_commentstates = ();
|
|
|
65 |
foreach my $comment (@topic_comments) {
|
|
|
66 |
my $key = $comment->{filenumber} . "|" . $comment->{fileline} . "|" .
|
|
|
67 |
$comment->{filenew};
|
|
|
68 |
if (! exists $processed_commentstates{$key}) {
|
|
|
69 |
# For each metric, see if there is a new value posted for this
|
|
|
70 |
# comment state.
|
|
|
71 |
my $state_changed = 0;
|
|
|
72 |
my $num_metrics_changed_for_comment_state = 0;
|
|
|
73 |
foreach my $metric (@{$Codestriker::comment_state_metrics}) {
|
|
|
74 |
my $select_form_name =
|
|
|
75 |
"comment_state_metric|" . $metric->{name} . "|" . $key;
|
|
|
76 |
|
|
|
77 |
# Check if this metric has a new value associated with it.
|
|
|
78 |
my $current_metric_value =
|
|
|
79 |
$comment->{metrics}->{$metric->{name}};
|
|
|
80 |
my $new_metric_value =
|
|
|
81 |
$comment_state_new_map{$select_form_name};
|
|
|
82 |
if (defined $new_metric_value &&
|
|
|
83 |
$new_metric_value ne $current_metric_value) {
|
|
|
84 |
|
|
|
85 |
# Change the specific metric for this commentstate record.
|
|
|
86 |
my $version =
|
|
|
87 |
$comment_state_version_map{$select_form_name} +
|
|
|
88 |
$num_metrics_changed_for_comment_state;
|
|
|
89 |
my $rc = $comment->change_state($metric->{name},
|
|
|
90 |
$new_metric_value,
|
|
|
91 |
$version);
|
|
|
92 |
if ($rc == $Codestriker::OK) {
|
|
|
93 |
$state_changed = 1;
|
|
|
94 |
$num_metrics_changed_for_comment_state++;
|
|
|
95 |
Codestriker::TopicListeners::Manager::comment_state_change(
|
|
|
96 |
$email, $metric->{name},
|
|
|
97 |
$current_metric_value,
|
|
|
98 |
$new_metric_value, $topic,
|
|
|
99 |
$comment);
|
|
|
100 |
} elsif ($rc == $Codestriker::STALE_VERSION) {
|
|
|
101 |
$stale = 1;
|
|
|
102 |
}
|
|
|
103 |
}
|
|
|
104 |
}
|
|
|
105 |
if ($state_changed) {
|
|
|
106 |
$comments_processed++;
|
|
|
107 |
}
|
|
|
108 |
|
|
|
109 |
# Indicate that this commentstate has been processed for all
|
|
|
110 |
# metrics.
|
|
|
111 |
$processed_commentstates{$key} = 1;
|
|
|
112 |
}
|
|
|
113 |
}
|
|
|
114 |
|
|
|
115 |
# These message could be made more helpful in the future, but for now...
|
|
|
116 |
if ($stale) {
|
|
|
117 |
$feedback = "Some comments could not be updated as they have been " .
|
|
|
118 |
"modified by another user.";
|
|
|
119 |
} else {
|
|
|
120 |
if ($comments_processed == 1) {
|
|
|
121 |
$feedback = "Comment was successfully updated.";
|
|
|
122 |
} elsif ($comments_processed > 1) {
|
|
|
123 |
$feedback = "$comments_processed comments were successfully updated.";
|
|
|
124 |
}
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
# Direct control to the list comment action class, with the appropriate
|
|
|
128 |
# feedback message.
|
|
|
129 |
$http_input->{feedback} = $feedback;
|
|
|
130 |
Codestriker::Action::ViewTopicComments->process($http_input,
|
|
|
131 |
$http_response);
|
|
|
132 |
}
|
|
|
133 |
|
|
|
134 |
1;
|