From: jj v. a. <we...@ma...> - 2007-10-08 19:39:22
|
Log Message: ----------- If the system is using mysql to store image depths, we update the database when deleting images. More specifically, we keep a depth in the database iff we kept the image. Modified Files: -------------- webwork2/bin: remove_stale_images Revision Data ------------- Index: remove_stale_images =================================================================== RCS file: /webwork/cvs/system/webwork2/bin/remove_stale_images,v retrieving revision 1.5 retrieving revision 1.6 diff -Lbin/remove_stale_images -Lbin/remove_stale_images -u -r1.5 -r1.6 --- bin/remove_stale_images +++ bin/remove_stale_images @@ -65,6 +65,7 @@ use Getopt::Long; use Pod::Usage; use File::Find; +use DBI; BEGIN { die "WEBWORK_ROOT not found in environment.\n" @@ -87,7 +88,9 @@ my %kept = (); my %days=(); my %week=(); +my %depths=(); my $grandtotal=0; +my $depthConnection; ##### get command-line options ##### @@ -155,6 +158,12 @@ } if($stat[$type]<$start or $stat[$type]>$end) { $kept{$fullmd5} = ''; + if($depthConnection) { # hold dvipng depths + my $fetchdepth = $depthConnection->selectall_arrayref(" + SELECT depth FROM depths WHERE md5=\"$fullmd5\""); + my $fetchdepthval = $fetchdepth->[0]->[0]; + $depths{$fullmd5} = $fetchdepthval if($fetchdepthval); + } } else { my $result = unlink($File::Find::name); if($result) { @@ -211,11 +220,36 @@ my $tmpdir = $ce->{webworkDirs}->{tmp}; my $tmpfile = "$tmpdir/equationcache.tmp"; +# Prepare to handle depths database table +my $alignType = $ce->{pg}->{displayModeOptions}->{images}->{dvipng_align}; +if($alignType eq 'mysql' and $deloption) { + my $dbinfo = $ce->{pg}->{displayModeOptions}->{images}->{dvipng_depth_db}; + $depthConnection = DBI->connect_cached( + $dbinfo->{dbsource}, + $dbinfo->{user}, + $dbinfo->{passwd}, + { PrintError => 0, RaiseError => 1 }, + ); + print "Could not make database connection for dvipng image depths.\n" unless defined $depthConnection; +} + find({wanted => \&wanted, follow_fast => 1}, $dirHead); print "Removed $num_removed images.\n\n" if($deloption); count_report() if($reportoption); + +# For depth database, empty it and insert only values for the images +# we kept. +my $ent; +if($depthConnection) { # clean out database and put back in good values + $depthConnection->do("TRUNCATE depths"); + for my $ent (keys %depths) { + $depthConnection->do("INSERT INTO `depths` VALUES( + \"$ent\", \"$depths{$ent}\")"); + } +} + ## The rest is updating the equation cache if we deleted images and there is a cache exit() unless($deloption and $num_removed); exit() unless ($cachePath); @@ -223,7 +257,6 @@ my ($perms, $uid, $groupID) = (stat $cachePath)[2,4,5]; #Get values from current cache file my $cachevalues = readFile($cachePath); my @cachelines = split "\n", $cachevalues; -my $ent; for $ent (@cachelines) { chomp($ent); my $entmd5 = $ent; @@ -251,4 +284,3 @@ - |