]>
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-04-29 #
9 # Description: Severance of Threads and archiving #
11 ################################################################################
19 create_forum_xml_string
31 ################################################################################
35 use base
qw(Exporter);
36 @Arc::Archive
::EXPORT
= qw(cut_tail);
38 ### sub cut_tail ($) ###########################################################
40 # shorten the main file and archive, if necessary
42 # Params: $param - hash reference
43 # (forumFile, messagePath, archivePath, lockFile, adminDefault,
46 # Return: hash reference - empty if all right done
52 if ( $param->{adminDefault
}->{Severance
}->{severance
} ne 'instant'
53 or $param->{adminDefault
}->{Instant
}->{execute
}
55 if (write_lock_file
($param->{lockFile
}, 1)) {
56 if (write_lock_file
($param->{forumFile
})) {
63 ) = get_all_threads
($param->{forumFile
}, KEEP_DELETED
);
65 my $obsolete = get_obsolete_threads
({
66 parsedThreads
=> $threads,
67 adminDefault
=> $param->{adminDefault
}
70 delete $threads->{$_} for (@
$obsolete);
72 my $saved = save_file
(
73 $param -> {forumFile
},
74 create_forum_xml_string
(
77 lastMessage
=> $last_message,
78 lastThread
=> $last_thread
84 set_master_lock
($param->{messagePath
}."t$_.xml") or $failed{$_} = 'could not set master lock';
87 violent_unlock_file
($param->{forumFile
}) unless (write_unlock_file
($param->{forumFile
}));
90 # now process thread files
92 my $sev_opt = ($param -> {adminDefault
} -> {Severance
} -> {severance
} eq 'instant')
93 ?
$param -> {adminDefault
} -> {Instant
} -> {Severance
}
94 : ($param -> {adminDefault
} -> {Severance
});
96 my $cache = new Posting
::Cache
($param->{cachePath
});
98 if ($sev_opt->{exArchiving
}) {
99 # yes, we cut & archive
101 my $sum = $cache -> summary
;
103 for my $tid (grep {not exists ($failed{$_})} @
$obsolete) {
104 my $xml = parse_xml_file
($param->{messagePath
}."t$tid.xml");
106 $failed{$tid} = 'could not parse thread file.';
109 my $tnode = $xml -> getElementsByTagName
('Thread') -> item
(0);
110 my $msg = parse_single_thread
($tnode, KEEP_DELETED
);
112 if ($sev_opt->{archiving
} eq 'UserVotings') {
113 # filter out the bad stuff
115 my $percent = $param->{adminDefault
}->{Voting
}->{Limit
};
116 my ($oldlevel, @path, $z, %archive) = (0, 0);
118 for $z (0..$#{$msg}) {
119 if ($msg -> [$z] -> {level
} > $oldlevel) {
121 $oldlevel = $msg -> [$z] -> {level
};
123 elsif ($msg -> [$z] -> {level
} < $oldlevel) {
124 splice @path, $msg -> [$z] -> {level
};
126 $oldlevel = $msg -> [$z] -> {level
};
132 if (defined $msg->[$z]->{archive
}) {
133 if ($msg->[$z]->{archive
}) {
134 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
137 unless ($msg->[$z]->{archive
} or $msg->[$z]->{deleted
}) {
138 my $key = $sum->{$tid}->{$msg->[$z]->{mid
}};
139 if ($percent == 0 or ($key->{views
} and ($key->{votings
} * 100 / $key->{views
}) >= $percent)) {
140 $archive{$msg->[$_]->{mid
}} = 1 for (@path);
147 for (reverse grep {!$archive{$_->{mid
}}} @
$msg) {
148 my $h = get_message_node
($xml, "t$tid", 'm'.$_->{mid
});
149 $h -> getParentNode
-> removeChild
($h);
151 $h = get_body_node
($xml, 'm'.$_->{mid
});
152 $h -> getParentNode
-> removeChild
($h);
155 # save back xml file (into archive)
157 if ($tnode -> hasChildNodes
) {
158 # insert views and votings counter
160 for ($tnode -> getElementsByTagName
('Message')) {
161 my ($id) = $_ -> getAttribute
('id') =~ /(\d+)/;
162 $_ -> setAttribute
('views' => $sum->{$tid}->{$id}->{views
});
163 $_ -> setAttribute
('votings' => $sum->{$tid}->{$id}->{votings
});
166 my ($month, $year) = (localtime ($msg->[0]->{time}))[4,5];
167 $month++; $year+=1900;
168 my $yeardir = $param -> {archivePath
} . $year;
169 my $yearpath = $yeardir . '/';
170 my $monthdir = $yearpath . $month;
171 my $monthpath = $monthdir . '/';
172 my $file = $monthpath . "t$tid.xml";
174 mkdir $yeardir unless (-d
$yeardir);
176 mkdir $monthdir unless (-d
$monthdir);
181 ) or $failed{$tid} = "could not save '$file'";
184 $failed{$tid} = "could not create directory '$monthdir'";
188 $failed{$tid} = "could not create directory '$yeardir'";
196 @failed{@
$obsolete} = 'could not load summary';
199 # delete processed files
201 for (grep {not exists($failed{$_})} @
$obsolete) {
202 unlink ($param->{messagePath
}."t$_.xml") or $failed{$_} = 'could not delete thread file';
203 file_removed
($param->{messagePath
}."t$_.xml");
205 $cache -> delete_threads
(@
$obsolete);
206 $cache -> garbage_collection
;
210 violent_unlock_file
($param->{forumFile
});
212 violent_unlock_file
($param->{lockFile
}) unless (write_unlock_file
($param->{lockFile
}));
215 violent_unlock_file
($param->{lockFile
});
228 ### end of Arc::Archive ########################################################
patrick-canterino.de