]>
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 if (write_lock_file
($param->{lockFile
}, 1)) {
66 if (write_lock_file
($param->{forumFile
})) {
73 ) = get_all_threads
($param->{forumFile
}, KEEP_DELETED
);
75 my $obsolete = get_obsolete_threads
({
76 parsedThreads
=> $threads,
77 adminDefault
=> $param->{adminDefault
}
80 delete $threads->{$_} for (@
$obsolete);
82 my $saved = save_file
(
83 $param -> {forumFile
},
84 create_forum_xml_string
(
87 lastMessage
=> $last_message,
88 lastThread
=> $last_thread
94 set_master_lock
($param->{messagePath
}."t$_.xml") or $failed{$_} = 'could not set master lock';
97 violent_unlock_file
($param->{forumFile
}) unless (write_unlock_file
($param->{forumFile
}));
100 # now process thread files
102 my $sev_opt = ($param -> {adminDefault
} -> {Severance
} -> {severance
} eq 'instant')
103 ?
$param -> {adminDefault
} -> {Instant
} -> {Severance
}
104 : ($param -> {adminDefault
} -> {Severance
});
106 my $cache = new Posting
::Cache
($param->{cachePath
});
108 if ($sev_opt->{exArchiving
}) {
109 # yes, we cut & archive
111 my $sum = $cache -> summary
;
113 for my $tid (grep {not exists ($failed{$_})} @
$obsolete) {
114 my $xml = parse_xml_file
($param->{messagePath
}."t$tid.xml");
116 $failed{$tid} = 'could not parse thread file.';
119 my $tnode = $xml -> getElementsByTagName
('Thread') -> item
(0);
120 my $msg = parse_single_thread
($tnode, KEEP_DELETED
);
122 if ($sev_opt->{archiving
} eq 'UserVotings') {
123 # filter out the bad stuff
125 my $percent = $param->{adminDefault
}->{Voting
}->{Limit
};
126 my ($oldlevel, @path, $z, %archive) = (0, 0);
128 for $z (0..$#{$msg}) {
129 if ($msg -> [$z] -> {level
} > $oldlevel) {
131 $oldlevel = $msg -> [$z] -> {level
};
133 elsif ($msg -> [$z] -> {level
} < $oldlevel) {
134 splice @path, $msg -> [$z] -> {level
};
136 $oldlevel = $msg -> [$z] -> {level
};
142 if (defined $msg->[$z]->{archive
}) {
143 if ($msg->[$z]->{archive
}) {
144 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
147 unless ($msg->[$z]->{archive
} or $msg->[$z]->{deleted
}) {
148 my $key = $sum->{$tid}->{$msg->[$z]->{mid
}};
149 if ($percent == 0 or ($key->{views
} and ($key->{votings
} * 100 / $key->{views
}) >= $percent)) {
150 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
157 for (reverse grep {!$archive{$_->{mid
}}} @
$msg) {
158 my $h = get_message_node
($xml, "t$tid", 'm'.$_->{mid
});
159 $h -> getParentNode
-> removeChild
($h);
161 $h = get_body_node
($xml, 'm'.$_->{mid
});
162 $h -> getParentNode
-> removeChild
($h);
165 # save back xml file (into archive)
167 if ($tnode -> hasChildNodes
) {
168 # insert views and votings counter
170 for ($tnode -> getElementsByTagName
('Message')) {
171 my ($id) = $_ -> getAttribute
('id') =~ /(\d+)/;
172 $_ -> setAttribute
('views' => $sum->{$tid}->{$id}->{views
});
173 $_ -> setAttribute
('votings' => $sum->{$tid}->{$id}->{votings
});
176 my ($month, $year) = (localtime ($msg->[0]->{time}))[4,5];
177 $month++; $year+=1900;
178 my $yeardir = $param -> {archivePath
} . $year;
179 my $yearpath = $yeardir . '/';
180 my $monthdir = $yearpath . $month;
181 my $monthpath = $monthdir . '/';
182 my $file = $monthpath . "t$tid.xml";
184 mkdir $yeardir, 0777 unless (-d
$yeardir);
186 mkdir $monthdir, 0777 unless (-d
$monthdir);
191 ) or $failed{$tid} = "could not save '$file'";
194 $failed{$tid} = "could not create directory '$monthdir'";
198 $failed{$tid} = "could not create directory '$yeardir'";
206 @failed{@
$obsolete} = 'could not load summary';
209 # delete processed files
211 for (grep {not exists($failed{$_})} @
$obsolete) {
212 unlink ($param->{messagePath
}."t$_.xml") or $failed{$_} = 'could not delete thread file';
213 file_removed
($param->{messagePath
}."t$_.xml");
215 $cache -> delete_threads
(@
$obsolete);
216 $cache -> garbage_collection
;
220 violent_unlock_file
($param->{forumFile
});
222 violent_unlock_file
($param->{lockFile
}) unless (write_unlock_file
($param->{lockFile
}));
225 violent_unlock_file
($param->{lockFile
});
233 # keep 'require' happy
238 ### end of Arc::Archive ########################################################
patrick-canterino.de