]> git.p6c8.net - selfforum.git/commitdiff
modified version check
authorndparker <>
Wed, 25 Jul 2001 20:02:26 +0000 (20:02 +0000)
committerndparker <>
Wed, 25 Jul 2001 20:02:26 +0000 (20:02 +0000)
selfforum-cgi/shared/Arc/Archive.pm
selfforum-cgi/shared/Arc/Starter.pm
selfforum-cgi/shared/Arc/Test.pm
selfforum-cgi/shared/Conf/Admin.pm

index 40e6bd50a8bbbe436da19b7c81ebf4b31519766f..ef2cee5b0b33116bd938a09fba0f4be95010a2dd 100644 (file)
@@ -4,7 +4,7 @@ package Arc::Archive;
 #                                                                              #
 # File:        shared/Arc/Archive.pm                                           #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-06-16                    #
+# Authors:     André Malo <nd@o3media.de>                                      #
 #                                                                              #
 # Description: Severance of Threads and archiving                              #
 #                                                                              #
@@ -37,7 +37,11 @@ use XML::DOM;
 #
 # Version check
 #
-$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+# last modified:
+#    $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
 
 ################################################################################
 #
@@ -153,6 +157,10 @@ sub delete_no_archived ($) {
     #
     $h = get_body_node($xml, 'm'.$_->{mid});
     $h -> getParentNode -> removeChild ($h);
+
+    # 'remove' from $msg
+    #
+    $_->{deleted} = 1;
   }
 }
 
@@ -200,7 +208,7 @@ sub create_arcdir ($$) {
 #                (opt, cache, failed, obsolete, messagePath,
 #                 archivePath, adminDefault)
 #
-# Return: ~none~
+# Return: hashref (tid => $msg)
 #
 sub process_threads ($) {
   my $par = shift;
@@ -208,6 +216,8 @@ sub process_threads ($) {
   my ($opt, $failed, $obsolete, $cache) = map {$par->{$_}} qw
      ( opt   failed   obsolete   cache);
 
+  my %archived;
+
   if ($opt->{exArchiving}) {
 
     # yes, we do archive
@@ -267,14 +277,131 @@ sub process_threads ($) {
               # save thread file
               #
               my $file = "${path}t$tid.xml";
-              save_file ($file => \($xml -> toString)) or $failed->{$tid} = "could not save '$file'";
+              unless (save_file ($file => \($xml -> toString))) {
+                $failed->{$tid} = "could not save '$file'";
+              }
+              else {
+                $archived{$tid} = $msg
+              }
             }
           }
         }
       }
     }
     else {
-      @$failed{@$obsolete} = 'could not load summary';
+      @$failed{@$obsolete} = 'error: could not load summary';
+    }
+  }
+
+  \%archived;
+}
+
+### append_threads () ##########################################################
+#
+# open specified index file, append threads, save it back
+#
+# Params: $file    - /path/to/indexfile
+#         $threads - hashref (threads)
+#
+# Return: success code (boolean)
+#
+sub append_threads ($$) {
+  my ($file, $threads) = @_;
+  my $thash={};
+
+  my $index = new Lock ($file);
+
+  return unless ($index -> lock (LH_EXCL));
+
+  if (-f $file) {
+    $thash = get_all_threads ($file => KEEP_DELETED);
+    $thash->{$_} = $threads->{$_} for (keys %$threads);
+  }
+  else {
+    $thash = $threads;
+  }
+
+  # save it back...
+  #
+  my $saved = save_file (
+    $file => create_forum_xml_string (
+      $threads,
+      {
+        dtd         => 'forum.dtd',
+        lastMessage => 0,
+        lastThread  => 0
+      }
+    )
+  );
+
+  $index -> unlock;
+
+  return unless $saved;
+
+  1;
+}
+
+### indexpath () ###############################################################
+#
+# compose relative path of archive index file
+#
+# Params: $param - hash reference
+#                  ($msg->[0])
+#
+# Return: $string (relative path)
+#
+sub indexpath ($) {
+  my $root = shift;
+
+  my ($month, $year) = (localtime ($root->{time}))[4,5];
+
+  # use the 'real' values for directory names
+  #
+  $month++; $year+=1900;
+
+  "$year/$month/";
+}
+
+### index_threads () ###########################################################
+#
+# add threads to their specific archive index file
+#
+# Params: $param - hash reference
+#                  (threads, archivePath, archiveIndex, failed)
+#
+# Return: ~none~
+#
+sub index_threads ($) {
+  my $par = shift;
+
+  my ($threads, $failed) = map {$par->{$_}} qw
+     ( threads   failed);
+
+  # indexfile => hashref of threads
+  # for more efficiency (open each index file *once*)
+  #
+  my %index;
+
+  # iterate over all archived threads,
+  # prepare indexing and assign threads to indexfiles
+  #
+  for my $thread (keys %$threads) {
+
+    # index only, if the root is visible
+    #
+    unless ($threads->{$thread}->[0]->{deleted}) {
+      my $file = $par->{archivePath} . indexpath ($threads->{$thread}->[0]) . $par->{archiveIndex};
+      $index{$file} = {} unless exists($index{$file});
+
+      $index{$file} -> {$thread} = [$threads->{$thread}->[0]];
+    }
+  }
+
+  # now append threads to index files
+  #
+  for my $file (keys %index) {
+    unless (append_threads ($file => $index{$file})) {
+      $failed->{$_} = "error: could not list in '$file'" for (keys %{$index{$file}});
     }
   }
 }
@@ -285,7 +412,7 @@ sub process_threads ($) {
 #
 # Params: $param - hash reference
 #                  (forumFile, messagePath, archivePath, lockFile, adminDefault,
-#                   cachePath)
+#                   cachePath, archiveIndex)
 #
 # Return: hash reference - empty if all right done
 #
@@ -353,7 +480,7 @@ sub cut_tail ($) {
           #
           if ($saved) {
             for (@$obsolete) {
-              new Lock($param->{messagePath}."t$_.xml")->lock(LH_MASTER) or $failed{$_} = 'could not set master lock';
+              new Lock($param->{messagePath}."t$_.xml")->lock(LH_MASTER) or $failed{$_} = 'error: could not set master lock';
             }
           }
 
@@ -380,18 +507,42 @@ sub cut_tail ($) {
               adminDefault => $param->{adminDefault}
             });
 
-
             # delete processed files, that are not failed
             #
+            my @removed;
+
             for (grep {not exists($failed{$_})} @$obsolete) {
-              unlink ($param->{messagePath}."t$_.xml") or $failed{$_} = 'could not delete thread file';
-              #file_removed ($param->{messagePath}."t$_.xml");
+              if (exists($failed{$_})) {
+                delete $obsolete{$_};
+              }
+              else {
+                unless (unlink ($param->{messagePath}."t$_.xml")) {
+                  $failed{$_} = 'warning: could not delete thread file';
+                }
+                else {
+                  push @removed => $_;
+                  #file_removed ($param->{messagePath}."t$_.xml");
+                }
+              }
             }
-            $cache -> delete_threads (@$obsolete);
-            $cache -> garbage_collection;
+
+            if (@removed) {
+              $cache -> delete_threads (@removed);
+              $cache -> garbage_collection;
+            }
+
+            # add archived threads to archive index
+            #
+            index_threads ({
+              threads      => \%obsolete,
+              archivePath  => $param->{archivePath},
+              archiveIndex => $param->{archiveIndex},
+              failed       => \%failed
+            });
           }
         }
-        # we're ready, tell this other instances
+
+        # we're ready, tell this other (waiting?) instances
         #
         $sev -> unlock;
       }
index 905a33acaa61d64b088e87279e7b5a3f183f53eb..a912d94eff5c2272cef9bdac441b6023cc215ec3 100644 (file)
@@ -4,7 +4,7 @@ package Arc::Starter;
 #                                                                              #
 # File:        shared/Arc/Starter.pm                                           #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-07-16                    #
+# Authors:     André Malo <nd@o3media.de>                                      #
 #                                                                              #
 # Description: start severancer and archiver                                   #
 #                                                                              #
@@ -20,7 +20,11 @@ use vars qw(
 #
 # Version check
 #
-$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+# last modified:
+#    $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
 
 ################################################################################
 #
index aacc92eec7be63e73706f0383e6424ebf21bbbb3..c0f6ba92b27e037c27b75f5f1a013d4fad054cb0 100644 (file)
@@ -4,7 +4,7 @@ package Arc::Test;
 #                                                                              #
 # File:        shared/Arc/Test.pm                                              #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-04-27                    #
+# Authors:     André Malo <nd@o3media.de>                                      #
 #                                                                              #
 # Description: check on obsolete threads                                       #
 #                                                                              #
@@ -20,7 +20,11 @@ use vars qw(
 #
 # Version check
 #
-$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+# last modified:
+#    $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
 
 ################################################################################
 #
index c834c37206819056304af97b080417f53ede07a9..ac0d8dc3ab27c7c89df85dfa4c4e310f792f87bd 100644 (file)
@@ -4,7 +4,7 @@ package Conf::Admin;
 #                                                                              #
 # File:        shared/CheckRFC.pm                                              #
 #                                                                              #
-# Authors:     Andre Malo       <nd@o3media.de>, 2001-06-16                    #
+# Authors:     André Malo <nd@o3media.de>                                      #
 #                                                                              #
 # Description: read and parse admin default config                             #
 #                                                                              #
@@ -13,7 +13,6 @@ package Conf::Admin;
 use strict;
 use vars qw(
   @EXPORT
-  $VERSION
 );
 
 use Lock;
@@ -24,7 +23,11 @@ use XML::DOM;
 #
 # Version check
 #
-$VERSION = do { my @r =(q$Revision$ =~ /\d+/g); sprintf "%d."."%02d" x $#r, @r };
+# last modified:
+#    $Date$ (GMT)
+# by $Author$
+#
+sub VERSION {(q$Revision$ =~ /([\d.]+)\s*$/)[0] or '0.0'}
 
 ################################################################################
 #

patrick-canterino.de