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-03-12 09:51 am

[dw-free] Allow importing of your journal from another LiveJournal-based site.

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

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

Fix bug that caused suspended/deleted users to not get identity accounts
created. (And allow setting password on new accounts in the command line
tool.)

Patch by [staff profile] mark.

Files modified:
  • bin/create-account
  • cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
--------------------------------------------------------------------------------
diff -r 388b6bf4d50d -r 3a216b7a556c bin/create-account
--- a/bin/create-account	Thu Mar 12 09:04:06 2009 +0000
+++ b/bin/create-account	Thu Mar 12 09:51:50 2009 +0000
@@ -6,12 +6,13 @@ require 'ljlib.pl';
 
 use Getopt::Long;
 
-my ( $user, $email );
+my ( $user, $email, $pass );
 GetOptions(
         'user=s' => \$user,
+        'password=s' => \$pass,
         'email=s' => \$email,
     ) or die "usage: $0 -u USERNAME -e EMAIL\n";
-die "usage: $0 -u USERNAME -e EMAIL\n"
+die "usage: $0 -u USERNAME -e EMAIL [-p PASSWORD]\n"
     unless $user && $email;
 
 $user = LJ::canonical_username( $user );
@@ -23,8 +24,11 @@ my $u2 = LJ::load_user( $user )
 my $u2 = LJ::load_user( $user )
     and die "User already exists\n";
 
-my $password = '';
-$password .= substr( 'abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ0123456789', int(rand()*62), 1 ) for 1..10;
+my $password = $pass || '';
+unless ( $password ) {
+    $password .= substr( 'abcdefghijklmnopqrstuvwxyzABCEFGHIJKLMNOPQRSTUVWXYZ0123456789', int(rand()*62), 1 ) for 1..10;
+}
+
 my $u = LJ::User->create_personal( user => $user, email => $email, password => $password )
     or die "unable to create account?\n";
 
diff -r 388b6bf4d50d -r 3a216b7a556c cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm
--- a/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Thu Mar 12 09:04:06 2009 +0000
+++ b/cgi-bin/DW/Worker/ContentImporter/LiveJournal.pm	Thu Mar 12 09:51:50 2009 +0000
@@ -390,15 +390,16 @@ sub remap_username_friend {
 
     } else {
         my $url_prefix = "http://$data->{hostname}/~" . $username;
-        my ( $foaf_items ) = $class->get_foaf_from( $url_prefix )
-            or return undef;
+        my ( $foaf_items ) = $class->get_foaf_from( $url_prefix );
 
-        # if they don't have an identity section (but foaf was successful
-        # or we would have returned undef above), then they are a community
-        # or some other account without.  return 0 to signify this.
-        my $ident = $foaf_items->{identity}->{url}
-            or return 0;
+        # if we get an empty hashref, we know that the foaf data failed
+        # to load.  probably because the account is suspended or something.
+        # in that case, we pretend.
+        my $ident =
+            exists $foaf_items->{identity} ? $foaf_items->{identity}->{url} : undef;
+        $ident ||= "http://$username.$data->{hostname}/";
 
+        # build the identity account (or return it if it exists)
         my $iu = LJ::User::load_identity_user( 'O', $ident, undef )
             or return undef;
         return $iu->id;
--------------------------------------------------------------------------------