[Home]WikiPatches/RcOldLog

UseModWiki | WikiPatches | RecentChanges | Preferences

This patch has been added to the 1.0 release with some changes. There is a new minor option $MaintTrimRc? (default 0). If it is set to 1 then the maintenance action (Local:action=maintain) will also trim the RC log. I also added a new action "maintainrc" (Local:action=maintainrc) which can only be run by wiki admins. I also fixed a couple minor edge-case bugs in the code below (it could add blank lines to the oldrclog file if nothing was transferred, or the rclog file if all entries were transferred). --CliffordAdams
Move entries from rclog to oldrclog while running maintenance.

Here is how to keep the rclog file small. Note that this patch contains a line saying </" . "pre> -- this can be replaced by </pre>. It was necessary to hide the closing pre tag...

sub DoMaintain {
  my ($name, $fname, @rc, @temp, $starttime, $days, $status, $data, $i, $ts);
  ...
  # Determine the number of days to go back
  $days = 0;
  foreach (@RcDays) {
    $days = $_ if $_ > $days;
  }
  $starttime = $Now - $days * 24 * 60 * 60;
  # Read the current file
  ($status, $data) = &ReadFile($RcFile);
  if (!$status) {
    print '<p><strong>' . Ts('Could not open %s log file', $RCName)
      . ":</strong> $RcFile<p>"
      . T('Error was') . ":\n<pre>$!</" . "pre>\n" . '<p>'
      . T('Note: This error is normal if no changes have been made.') . "\n";
  }
  # Move the old stuff from rc to temp
  @rc = split(/\n/, $data);
  for ($i = 0; $i < @rc ; $i++) {
    ($ts) = split(/$FS3/, $rc[$i]);
    last if ($ts >= $starttime);
  }
  @temp = splice(@rc, 0, $i);
  # Write new files, and backups
  if (!open(OUT, ">>$RcOldFile")) {
    die(Ts('%s log error:', $RCName) . " $!");
  }
  print OUT  join("\n",@temp) . "\n";
  close(OUT);
  &WriteStringToFile($RcFile . '.old', $data);
  &WriteStringToFile($RcFile, join("\n",@rc) . "\n");
  # Write timestamp
  &WriteStringToFile($fname, 'Maintenance done at ' . &TimeToText($Now));
  &ReleaseLock();
  ...
}


WikiPatches

UseModWiki | WikiPatches | RecentChanges | Preferences
Edit text of this page | View other revisions | Search MetaWiki
Last edited September 23, 2007 2:20 pm by JuanmaMP (diff)
Search: