mark: A photo of Mark kneeling on top of the Taal Volcano in the Philippines. It was a long hike. (Default)
Mark Smith ([staff profile] mark) wrote in [site community profile] changelog2009-04-05 08:20 am

[dw-free] Userpics will not import in certain valid cases

[commit: http://hg.dwscoalition.org/dw-free/rev/fadb53f23f67]

http://bugs.dwscoalition.org/show_bug.cgi?id=521

Fix userpic import to work if you bump up against the limit exactly.

Patch by [personal profile] exor674.

Files modified:
  • cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm
  • cgi-bin/DW/Worker/ContentImporter/Local/Userpics.pm
--------------------------------------------------------------------------------
diff -r 6051f7820fd2 -r fadb53f23f67 cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm	Sun Apr 05 08:10:33 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal/Userpics.pm	Sun Apr 05 08:20:52 2009 +0000
@@ -19,7 +19,9 @@ use strict;
 use strict;
 use base 'DW::Worker::ContentImporter::LiveJournal';
 
+use XML::Parser;
 use HTML::Entities;
+use Storable qw/ freeze /;
 use Carp qw/ croak confess /;
 use Encode qw/ encode_utf8 /;
 use DW::Worker::ContentImporter::Local::Userpics;
diff -r 6051f7820fd2 -r fadb53f23f67 cgi-bin/DW/Worker/ContentImporter/Local/Userpics.pm
--- a/cgi-bin/DW/Worker/ContentImporter/Local/Userpics.pm	Sun Apr 05 08:10:33 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/Local/Userpics.pm	Sun Apr 05 08:20:52 2009 +0000
@@ -48,10 +48,11 @@ sub import_userpics {
     my $count = $u->get_userpic_count;
     my $max = $u->userpic_quota;
     my $left = $max - $count;
+    my $pending = scalar( @{$upics || [] } );
 
     my ( @imported, %skip_ids );
 
-    warn "Content importer: import_userpics: $u->{user}($u->{userid}) has=$count, max=$max, importing=" . scalar(@$upics) . "\n";
+    warn "Content importer: import_userpics: $u->{user}($u->{userid}) has=$count, max=$max, importing=$pending\n";
 
     # but do nothing if we have no room...
     return () if $left <= 0;
@@ -59,13 +60,14 @@ sub import_userpics {
     # import helper
     my $import_userpic = sub {
         my $pic = shift;
-        warn "Attempting to import $pic->{src}\n";
 
         return if $skip_ids{$pic->{id}};
 
+        warn "Attempting to import $pic->{src}\n";
+
         if ( my $ret = $class->import_userpic( $u, $errors, $pic ) ) {
-            $left--
-                if $ret == 1; # 1 == success, new picture created
+            $pending--;
+            $left-- if $ret == 1; # 1 == success, new picture created
             push @imported, $pic->{id};
         }
 
@@ -79,7 +81,7 @@ sub import_userpics {
 
     # now bail out if we don't have room for everything
     return @imported
-        unless $left >= scalar( @{ $upics || [] } );
+        unless $left >= $pending;
 
     # now import the list, or try
     $import_userpic->( $_ )
--------------------------------------------------------------------------------