]>
git.p6c8.net - selfforum.git/blob - selfforum-cgi/shared/Arc/Archive.pm
3 ################################################################################
5 # File: shared/Arc/Archive.pm #
7 # Authors: Andre Malo <nd@o3media.de>, 2001-06-16 #
9 # Description: Severance of Threads and archiving #
11 ################################################################################
23 create_forum_xml_string
35 ################################################################################
39 $VERSION = do { my @r =(q
$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x
$#r, @r };
41 ################################################################################
45 use base
qw(Exporter);
46 @EXPORT = qw(cut_tail);
48 ### sub cut_tail ($) ###########################################################
50 # shorten the main file and archive, if necessary
52 # Params: $param - hash reference
53 # (forumFile, messagePath, archivePath, lockFile, adminDefault,
56 # Return: hash reference - empty if all right done
62 if ( $param->{adminDefault
}->{Severance
}->{severance
} ne 'instant'
63 or $param->{adminDefault
}->{Instant
}->{execute
}
65 my $sev = new Lock
($param->{lockFile
});
66 if ($sev -> lock(LH_EXCL
)) {
67 my $forum = new Lock
($param->{forumFile
});
68 if ($forum -> lock (LH_EXCL
)) {
75 ) = get_all_threads
($forum->filename, KEEP_DELETED
);
77 my $obsolete = get_obsolete_threads
({
78 parsedThreads
=> $threads,
79 adminDefault
=> $param->{adminDefault
}
82 delete $threads->{$_} for (@
$obsolete);
84 my $saved = save_file
(
85 $param -> {forumFile
},
86 create_forum_xml_string
(
89 lastMessage
=> $last_message,
90 lastThread
=> $last_thread
96 new Lock
($param->{messagePath
}."t$_.xml")->lock(LH_MASTER
) or $failed{$_} = 'could not set master lock';
102 # now process thread files
104 my $sev_opt = ($param -> {adminDefault
} -> {Severance
} -> {severance
} eq 'instant')
105 ?
$param -> {adminDefault
} -> {Instant
} -> {Severance
}
106 : ($param -> {adminDefault
} -> {Severance
});
108 my $cache = new Posting
::Cache
($param->{cachePath
});
110 if ($sev_opt->{exArchiving
}) {
111 # yes, we cut & archive
113 my $sum = $cache -> summary
;
115 for my $tid (grep {not exists ($failed{$_})} @
$obsolete) {
116 my $xml = parse_xml_file
($param->{messagePath
}."t$tid.xml");
118 $failed{$tid} = 'could not parse thread file.';
121 my $tnode = $xml -> getElementsByTagName
('Thread') -> item
(0);
122 my $msg = parse_single_thread
($tnode, KEEP_DELETED
);
124 if ($sev_opt->{archiving
} eq 'UserVotings') {
125 # filter out the bad stuff
127 my $percent = $param->{adminDefault
}->{Voting
}->{Limit
};
128 my ($oldlevel, @path, $z, %archive) = (0, 0);
130 for $z (0..$#{$msg}) {
131 if ($msg -> [$z] -> {level
} > $oldlevel) {
133 $oldlevel = $msg -> [$z] -> {level
};
135 elsif ($msg -> [$z] -> {level
} < $oldlevel) {
136 splice @path, $msg -> [$z] -> {level
};
138 $oldlevel = $msg -> [$z] -> {level
};
144 if (defined $msg->[$z]->{archive
}) {
145 if ($msg->[$z]->{archive
}) {
146 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
149 unless ($msg->[$z]->{archive
} or $msg->[$z]->{deleted
}) {
150 my $key = $sum->{$tid}->{$msg->[$z]->{mid
}};
151 if ($percent == 0 or ($key->{views
} and ($key->{votings
} * 100 / $key->{views
}) >= $percent)) {
152 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
159 for (reverse grep {!$archive{$_->{mid
}}} @
$msg) {
160 my $h = get_message_node
($xml, "t$tid", 'm'.$_->{mid
});
161 $h -> getParentNode
-> removeChild
($h);
163 $h = get_body_node
($xml, 'm'.$_->{mid
});
164 $h -> getParentNode
-> removeChild
($h);
167 # save back xml file (into archive)
169 if ($tnode -> hasChildNodes
) {
170 # insert views and votings counter
172 for ($tnode -> getElementsByTagName
('Message')) {
173 my ($id) = $_ -> getAttribute
('id') =~ /(\d+)/;
174 $_ -> setAttribute
('views' => $sum->{$tid}->{$id}->{views
});
175 $_ -> setAttribute
('votings' => $sum->{$tid}->{$id}->{votings
});
178 my ($month, $year) = (localtime ($msg->[0]->{time}))[4,5];
179 $month++; $year+=1900;
180 my $yeardir = $param -> {archivePath
} . $year;
181 my $yearpath = $yeardir . '/';
182 my $monthdir = $yearpath . $month;
183 my $monthpath = $monthdir . '/';
184 my $file = $monthpath . "t$tid.xml";
186 mkdir $yeardir unless (-d
$yeardir);
188 mkdir $monthdir unless (-d
$monthdir);
193 ) or $failed{$tid} = "could not save '$file'";
196 $failed{$tid} = "could not create directory '$monthdir'";
200 $failed{$tid} = "could not create directory '$yeardir'";
208 @failed{@
$obsolete} = 'could not load summary';
211 # delete processed files
213 for (grep {not exists($failed{$_})} @
$obsolete) {
214 unlink ($param->{messagePath
}."t$_.xml") or $failed{$_} = 'could not delete thread file';
215 #file_removed ($param->{messagePath}."t$_.xml");
217 $cache -> delete_threads
(@
$obsolete);
218 $cache -> garbage_collection
;
229 # keep 'require' happy
234 ### end of Arc::Archive ########################################################
patrick-canterino.de