| 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 handling the submission of changing multiple topic states.
|
|
|
9 |
|
|
|
10 |
package Codestriker::Action::SubmitEditTopicsState;
|
|
|
11 |
|
|
|
12 |
use strict;
|
|
|
13 |
|
|
|
14 |
use Codestriker::Action::ListTopics;
|
|
|
15 |
|
|
|
16 |
# Attempt to change the topic's state, or to delete it.
|
|
|
17 |
sub process($$$) {
|
|
|
18 |
my ($type, $http_input, $http_response) = @_;
|
|
|
19 |
|
|
|
20 |
my $query = $http_response->get_query();
|
|
|
21 |
|
|
|
22 |
# Check that the appropriate fields have been filled in.
|
|
|
23 |
my $topics_ref = $http_input->get('selected_topics');
|
|
|
24 |
my @topics = @$topics_ref;
|
|
|
25 |
|
|
|
26 |
my $topic_state = $http_input->get('topic_state');
|
|
|
27 |
my $email = $http_input->get('email');
|
|
|
28 |
my $button = $http_input->get('button');
|
|
|
29 |
|
|
|
30 |
# Check if this is an obsolete function, and if so, redirect to the
|
|
|
31 |
# create topic screen.
|
|
|
32 |
if ($button eq "Obsolete Topic(s)") {
|
|
|
33 |
my $url_builder = Codestriker::Http::UrlBuilder->new($query);
|
|
|
34 |
my $create_topic_url =
|
|
|
35 |
$url_builder->create_topic_url((join ',', @topics));
|
|
|
36 |
print $query->redirect(-URI=>$create_topic_url);
|
|
|
37 |
return;
|
|
|
38 |
}
|
|
|
39 |
|
|
|
40 |
# The main topic list page does not allow deletes, so block this out.
|
|
|
41 |
if ($topic_state eq "Deleted" || $topic_state eq "Obsoleted") {
|
|
|
42 |
$http_response->error("This function has been disabled");
|
|
|
43 |
}
|
|
|
44 |
|
|
|
45 |
# Any feedback messages to the user.
|
|
|
46 |
my $feedback = "";
|
|
|
47 |
|
|
|
48 |
# Indicate if changes were attempted on invalid topics.
|
|
|
49 |
my $invalid = 0;
|
|
|
50 |
|
|
|
51 |
# Indicate if changes were made to stale topics.
|
|
|
52 |
my $stale = 0;
|
|
|
53 |
|
|
|
54 |
# Apply the change to each topic.
|
|
|
55 |
for (my $i = 0; $i <= $#topics; $i++) {
|
|
|
56 |
# Extract the topic id and the version.
|
|
|
57 |
$topics[$i] =~ /^([0-9]+)\,([0-9]+)$/;
|
|
|
58 |
|
|
|
59 |
# Dump the request if the param does not look right.
|
|
|
60 |
next if (!defined($1) || !defined($2));
|
|
|
61 |
|
|
|
62 |
my $topicid = $1;
|
|
|
63 |
my $version = $2;
|
|
|
64 |
|
|
|
65 |
my $rc = $type->update_state($topicid, $version, $topic_state, $email);
|
|
|
66 |
|
|
|
67 |
# Record if there was a problem in changing the state.
|
|
|
68 |
$invalid = 1 if $rc == $Codestriker::INVALID_TOPIC;
|
|
|
69 |
$stale = 1 if $rc == $Codestriker::STALE_VERSION;
|
|
|
70 |
}
|
|
|
71 |
|
|
|
72 |
# These message could be made more helpful in the future, but for now...
|
|
|
73 |
if ($invalid && $stale) {
|
|
|
74 |
$feedback = "Some topics could not be updated as they were either " .
|
|
|
75 |
"modified by another user, or no longer exist.";
|
|
|
76 |
} elsif ($invalid) {
|
|
|
77 |
$feedback = "Some topics could not be updated as they no longer " .
|
|
|
78 |
"exist.";
|
|
|
79 |
} elsif ($stale) {
|
|
|
80 |
$feedback = "Some topics could not be updated as they have been " .
|
|
|
81 |
"modified by another user.";
|
|
|
82 |
} else {
|
|
|
83 |
if ($#topics == 0) {
|
|
|
84 |
$feedback = "Topic was successfully updated.";
|
|
|
85 |
} else {
|
|
|
86 |
$feedback = "All topics were successfully updated.";
|
|
|
87 |
}
|
|
|
88 |
}
|
|
|
89 |
|
|
|
90 |
# Direct control to the list topic action class, with the appropriate
|
|
|
91 |
# feedback message.
|
|
|
92 |
$http_input->{feedback} = $feedback;
|
|
|
93 |
Codestriker::Action::ListTopics->process($http_input, $http_response);
|
|
|
94 |
}
|
|
|
95 |
|
|
|
96 |
# Static method for updating the state of a topic, and informing all of the
|
|
|
97 |
# topic listeners.
|
|
|
98 |
sub update_state {
|
|
|
99 |
my ($type, $topicid, $version, $topic_state, $email) = @_;
|
|
|
100 |
|
|
|
101 |
# Original topic object which won't be changed in the
|
|
|
102 |
# change_state operation.
|
|
|
103 |
my $topic_orig = Codestriker::Model::Topic->new($topicid);
|
|
|
104 |
|
|
|
105 |
# Don't do anything if the topic is already at the given state.
|
|
|
106 |
return $Codestriker::OK if ($topic_state eq $topic_orig->{topic_state});
|
|
|
107 |
|
|
|
108 |
# Topic object to operate on.
|
|
|
109 |
my $topic = Codestriker::Model::Topic->new($topicid);
|
|
|
110 |
my $rc = $Codestriker::OK;
|
|
|
111 |
if ($topic->{version} == $version) {
|
|
|
112 |
# Change the topic state.
|
|
|
113 |
$rc = $topic->change_state($topic_state);
|
|
|
114 |
} else {
|
|
|
115 |
# Stale version.
|
|
|
116 |
$rc = $Codestriker::STALE_VERSION;
|
|
|
117 |
}
|
|
|
118 |
|
|
|
119 |
if ($rc == $Codestriker::OK) {
|
|
|
120 |
# Fire a topic changed listener event.
|
|
|
121 |
my $topic_new = Codestriker::Model::Topic->new($topicid);
|
|
|
122 |
Codestriker::TopicListeners::Manager::topic_changed($email,
|
|
|
123 |
$topic_orig,
|
|
|
124 |
$topic_new);
|
|
|
125 |
}
|
|
|
126 |
|
|
|
127 |
# Indicate whether the operation was successful or not.
|
|
|
128 |
return $rc;
|
|
|
129 |
}
|
|
|
130 |
|
|
|
131 |
1;
|