📄 submitnewtopic.pm
字号:
$temp_error_fh = tempfile(); } binmode $temp_topic_fh; binmode $temp_error_fh; my $rc; if ($start_tag eq '' && $end_tag eq '' && $module eq '') { # Retrieve the diff from ScmBug and the repository object. my $scmbug = Codestriker::Repository::ScmBug->new($Codestriker::scmbug_hostname, $Codestriker::scmbug_port, $repository); $rc = $scmbug->getDiff($bug_ids, $temp_topic_fh, $temp_error_fh, $default_to_head); } else { # Retrieve the diff directly from the repository object. $rc = $repository->getDiff($start_tag, $end_tag, $module, $temp_topic_fh, $temp_error_fh, $default_to_head); } # Make sure the data has been flushed to disk. $temp_topic_fh->flush; $temp_error_fh->flush; # Check if the generated diff was too big, and if so, throw an error # message on the screen. if ($rc == $Codestriker::DIFF_TOO_BIG) { $feedback .= "Generated diff file is too big.\n"; } elsif ($rc == $Codestriker::UNSUPPORTED_OPERATION) { $feedback .= "Repository \"" . $repository_name . "\" does not support tag retrieval, you have to use the text file upload.\n"; } elsif ($rc != $Codestriker::OK) { $feedback .= "Unexpected error $rc retrieving diff text.\n"; } # Seek to the beginning of the temporary file so it can be parsed. seek($temp_topic_fh, 0, 0); # Set $fh to this file reference which contains the topic data. $fh = $temp_topic_fh; } my @deltas = (); if ($feedback eq "") { # Try to parse the topic text into its diff chunks. @deltas = Codestriker::FileParser::Parser->parse($fh, "text/plain", $repository, $topicid, $topic_file); if ($#deltas == -1) { # Nothing in the file, report an error. $feedback .= "Reviewable text in topic is empty.\n"; } } if ($feedback ne "") { # If there was a problem generating the diff file, remove the # temporary files, and direct control to the create screen again. $temp_topic_fh->close if defined $temp_topic_fh; $temp_error_fh->close if defined $temp_error_fh; _forward_create_topic($error_vars, $feedback, $url_builder); $http_response->generate_footer(); return; } # If the topic text has been uploaded from a file, read from it now. if (defined $fh) { while (<$fh>) { $topic_text .= Codestriker::decode_topic_text($_); } if ($topic_text eq "") { if (defined $temp_error_fh) { seek($temp_error_fh, 0, 0); $feedback .= "Problem generating topic text:\n\n"; my $buf = ""; while (read $temp_error_fh, $buf, 16384) { $feedback .= $buf; } } else { $feedback = "Uploaded file doesn't exist or is empty.\n"; } # Remove the temporary files if required, and forward control # back to the create topic page. $temp_topic_fh->close if defined $temp_topic_fh; $temp_error_fh->close if defined $temp_error_fh; _forward_create_topic($error_vars, $feedback, $url_builder); $http_response->generate_footer(); return; } } # Remove the temporary files if required. $temp_topic_fh->close if defined $temp_topic_fh; $temp_error_fh->close if defined $temp_error_fh; # Remove \r from the topic text. $topic_text =~ s/\r//g; # Make sure the topic is not too large, count the number of \n # in the topic content text. my $new_topic_length = 0; ++$new_topic_length while ($topic_text =~ /\n/g); if (defined($Codestriker::maximum_topic_size_lines) && $Codestriker::maximum_topic_size_lines ne "" && $Codestriker::maximum_topic_size_lines < $new_topic_length) { $feedback .= "The topic length of $new_topic_length lines is too long. " . "Topics cannot exceed $Codestriker::maximum_topic_size_lines " . "lines long. Please remove content from topic, or break the " . "topic into several independent topics.\n"; _forward_create_topic($error_vars, $feedback, $url_builder); $http_response->generate_footer(); return; } # Make sure the specified topicids to be obsoleted are in fact valid. if (defined $obsoletes && $obsoletes ne '') { my @data = split ',', $obsoletes; for (my $i = 0; $i <= $#data; $i+=2) { my $id = $data[$i]; my $version = $data[$i+1]; if (! Codestriker::Model::Topic::exists($id)) { $feedback .= "Obsoleted topics specified do not exist.\n"; _forward_create_topic($error_vars, $feedback, $url_builder); $http_response->generate_footer(); return; } } } # Create the topic in the model. my $topic = Codestriker::Model::Topic->new($topicid); $topic->create($topicid, $email, $topic_title, $topic_state, $bug_ids, $reviewers, $cc, $topic_description, $topic_text, $start_tag, $end_tag, $module, $repository_url, $projectid, \@deltas, $obsoletes); # Obsolete any required topics. if (defined $obsoletes && $obsoletes ne '') { my @data = split ',', $obsoletes; for (my $i = 0; $i <= $#data; $i+=2) { my $id = $data[$i]; my $version = $data[$i+1]; Codestriker::Action::SubmitEditTopicsState ->update_state($id, $version, 'Obsoleted', $email); } } # Tell all of the topic listener classes that a topic has # just been created. $topic->{email_event} = $email_event; $feedback = Codestriker::TopicListeners::Manager::topic_create($topic); # Obtain a URL builder object and determine the URL to the topic. my $topic_url = $url_builder->view_url(topicid => $topicid, projectid => $projectid); # Indicate to the user that the topic has been created and an email has # been sent. my $vars = {}; $vars->{'topic_title'} = $topic->{title}; $vars->{'email'} = $email; $vars->{'topic_url'} = $topic_url; $vars->{'reviewers'} = $reviewers; $vars->{'cc'} = (defined $cc) ? $cc : ""; $vars->{'feedback'} = $feedback; my $template = Codestriker::Http::Template->new("submitnewtopic"); $template->process($vars); $http_response->generate_footer();}# Direct output to the create topic screen again, with the appropriate feedback# message.sub _forward_create_topic($$$) { my ($vars, $feedback, $url_builder) = @_; $feedback =~ s/\n/<BR>/g; $vars->{'feedback'} = $feedback; my @projects = Codestriker::Model::Project->list(); $vars->{'projects'} = \@projects; Codestriker::Action::CreateTopic-> set_obsoleted_topics_parameter($vars, $url_builder); my $template = Codestriker::Http::Template->new("createtopic"); $template->process($vars);}1;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -