OMatic/submitCatToAns.pm untested

filter: Statementstmt 0.0% 0 / 49 Branchbran 0.0% 0 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 67 CC 6 SCAR 30.9
CC
6
Cov
0%
main
42.0
BEGIN
2.0
BEGIN
2.0
CRAP 22.0
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::submitCatToAns;
31  
32 use CGI;
33 use FAQ::OMatic::Item;
34 use FAQ::OMatic;
35 use FAQ::OMatic::Auth;
36 use FAQ::OMatic::I18N;
37  
38 sub main {
39 my $cgi = FAQ::OMatic::dispatch::cgi();
40 my $removed = 0;
41
42 my $params = FAQ::OMatic::getParams($cgi);
43  
44 FAQ::OMatic::mirrorsCantEdit($cgi, $params);
45  
46 my $item = new FAQ::OMatic::Item($params->{'file'});
47 if ($item->isBroken()) {
48 FAQ::OMatic::gripe('error', gettexta("The file (%0) doesn't exist.", $params->{'file'}));
49 }
50
51 $item->checkSequence($params);
52 $item->incrementSequence();
53  
54 FAQ::OMatic::Auth::ensurePerm('-item'=>$item,
55 '-operation'=>'PermEditDirectory',
56 '-restart'=>FAQ::OMatic::commandName(),
57 '-cgi'=>$cgi,
58 '-failexit'=>1);
59  
60 # users would rarely see these messages; they'd have to forge the URL.
61 if (not $item->isCategory()) {
62 FAQ::OMatic::gripe('error', "This isn't a category.");
63 }
64  
65 if (scalar($item->getChildren())>0) {
66 FAQ::OMatic::gripe('error', "This category still has children. "
67 ."Move them to another category before trying to convert this "
68 ."category into an answer.");
69 }
70  
71 if ($params->{'_removePart'}) {
72 # just delete the entire part outright
73 my $partnum = $item->{'directoryHint'};
74 if (not defined $partnum) {
75 FAQ::OMatic::gripe('abort',
76 "spooky: directoryHint not defined in category "
77 .$item->{'filename'});
78 }
79 splice @{$item->{'Parts'}}, $partnum, 1;
80 delete $item->{'directoryHint'};
81 } else {
82 # the directory part has no faqomatic: links, so it won't hurt to
83 # turn it into a regular text part.
84 my $part = $item->getDirPart();
85 $part->setProperty('Type', '');
86 $part->touch();
87 delete $item->{'directoryHint'};
88 # makes sure later code (such as that that rewrites the cache)
89 # thinks this is an answer now, not a category.
90 }
91  
92 # parent and any see-also linkers have changed, since their icons will
93 # be wrong. This is just like changing the title, although it doesn't
94 # affect siblings, but who cares; we'll just use
95 # the usual dependency-update routine.)
96 # TODO: maybe siblings should have icons! So should the parent chain!
97 $item->setProperty('titleChanged', 1);
98  
99 $item->saveToFile();
100  
101 $item->notifyModerator($cgi, "made a category into an answer.");
102  
103 my $url = FAQ::OMatic::makeAref('-command'=>'faq',
104 '-params'=>$params,
105 '-changedParams'=>{'checkSequenceNumber'=>''},
106 '-refType'=>'url');
107 # eliminate things that were in our input form that weren't
108 # automatically transient (_ prefix)
109 FAQ::OMatic::redirect($cgi, $url);
110 }
111  
112 1;