OMatic/submitAnsToCat.pm untested

filter: Statementstmt 0.0% 0 / 42 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 8 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 57 CC 4 SCAR 21.5
CC
4
Cov
0%
main
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 8.5
1 ##############################################################################
2 # The Faq-O-Matic is Copyright 1997 by Jon Howell, all rights reserved. #
3 # #
4 # This program is free software; you can redistribute it and/or #
5 # modify it under the terms of the GNU General Public License #
6 # as published by the Free Software Foundation; either version 2 #
7 # of the License, or (at your option) any later version. #
8 # #
9 # This program is distributed in the hope that it will be useful, #
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of #
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the #
12 # GNU General Public License for more details. #
13 # #
14 # You should have received a copy of the GNU General Public License #
15 # along with this program; if not, write to the Free Software #
16 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.#
17 # #
18 # Jon Howell can be contacted at: #
19 # 6211 Sudikoff Lab, Dartmouth College #
20 # Hanover, NH 03755-3510 #
21 # jonh@cs.dartmouth.edu #
22 # #
23 # An electronic copy of the GPL is available at: #
24 # http://www.gnu.org/copyleft/gpl.html #
25 # #
26 ##############################################################################
27  
28 use strict;
29  
30 package FAQ::OMatic::submitAnsToCat;
31  
32 use CGI;
33 use FAQ::OMatic::Item;
34 use FAQ::OMatic;
35 use FAQ::OMatic::I18N;
36 use FAQ::OMatic::Auth;
37 use FAQ::OMatic::I18N;
38  
39 sub main {
40 my $cgi = FAQ::OMatic::dispatch::cgi();
41 my $removed = 0;
42
43 my $params = FAQ::OMatic::getParams($cgi);
44  
45 FAQ::OMatic::mirrorsCantEdit($cgi, $params);
46  
47 my $item = new FAQ::OMatic::Item($params->{'file'});
48 if ($item->isBroken()) {
49 FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $params->{'file'}));
50 }
51
52 $item->checkSequence($params);
53 $item->incrementSequence();
54  
55 FAQ::OMatic::Auth::ensurePerm('-item'=>$item,
56 '-operation'=>'PermEditDirectory',
57 '-restart'=>FAQ::OMatic::commandName(),
58 '-cgi'=>$cgi,
59 '-failexit'=>1);
60  
61 if ($item->isCategory()) {
62 # users would rarely see this message; they'd have to forge the URL.
63 FAQ::OMatic::gripe('error', "This is an answer, not a category.");
64 }
65  
66 $item->makeDirectory()->
67 setText(gettext("Subcategories:")."\n\n\n".gettext("Answers in this category:")."\n");
68  
69 # parent and any see-also linkers have changed, since their icons will
70 # be wrong. This is just like changing the title, although it doesn't
71 # affect siblings, but who cares; we'll just use
72 # the usual dependency-update routine.)
73 $item->setProperty('titleChanged', 1);
74  
75 # in any case, the user has co-authored the document
76 # TODO: does this make sense for just changing the status of a part?
77 my ($id,$aq) = FAQ::OMatic::Auth::getID();
78 $item->getDirPart()->addAuthor($id) if ($id);
79 $item->saveToFile();
80  
81 $item->notifyModerator($cgi, "made an answer into a category.");
82  
83 my $url = FAQ::OMatic::makeAref('-command'=>'faq',
84 '-params'=>$params,
85 '-changedParams'=>{'checkSequenceNumber'=>''},
86 '-refType'=>'url');
87 # eliminate things that were in our input form that weren't
88 # automatically transient (_ prefix)
89 FAQ::OMatic::redirect($cgi, $url);
90 }
91  
92 1;