fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-09-26 08:06 am

[dw-free] remove LJ::create_account

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

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

Consolidate into one method signature: LJ::User->create() which returns an
LJ::User object. Obsoletes LJ::create_account({}) which returns a user id.
Updates calls to match new signature and new expected return.

Patch by [personal profile] kareila.

Files modified:
  • bin/upgrading/make_system.pl
  • bin/upgrading/update-db.pl
  • cgi-bin/LJ/Test.pm
  • cgi-bin/LJ/User.pm
--------------------------------------------------------------------------------
diff -r 6530b9568c03 -r 55485520d8e9 bin/upgrading/make_system.pl
--- a/bin/upgrading/make_system.pl	Mon Sep 26 15:57:19 2011 +0800
+++ b/bin/upgrading/make_system.pl	Mon Sep 26 16:06:26 2011 +0800
@@ -32,18 +32,18 @@
 print "\n";
 
 print "Creating system account...\n";
-unless (LJ::create_account({ 'user' => 'system',
-                             'name' => 'System Account',
-                             'password' => $pass }))
-{
+my $u = LJ::User->create( user => 'system',
+                          name => 'System Account',
+                          password => $pass );
+unless ( $u ) {
     print "Already exists.\nModifying 'system' account...\n";
     my $id = LJ::get_userid("system");
     $dbh->do("UPDATE password SET password=? WHERE userid=?",
              undef, $pass, $id);
 }
 
-my $u = LJ::load_user("system");
-unless ($u) {
+$u ||= LJ::load_user( "system" );
+unless ( $u ) {
     print "ERROR: can't find newly-created system account.\n";
     exit 1;
 }
diff -r 6530b9568c03 -r 55485520d8e9 bin/upgrading/update-db.pl
--- a/bin/upgrading/update-db.pl	Mon Sep 26 15:57:19 2011 +0800
+++ b/bin/upgrading/update-db.pl	Mon Sep 26 16:06:26 2011 +0800
@@ -245,11 +245,10 @@
     unless ($su) {
         print "System user not found. Creating with random password.\n";
         my $pass = LJ::make_auth_code(10);
-        LJ::create_account({ 'user' => 'system',
-                             'name' => 'System Account',
-                             'password' => $pass })
-            || die "Failed to create system user.";
-        $su = LJ::load_user("system") || die "Failed to load the newly created system user.";
+        $su = LJ::User->create( user => 'system',
+                                name => 'System Account',
+                                password => $pass );
+        die "Failed to create system user." unless $su;
         $freshly_made = 1;
     }
     return wantarray ? ($su, $freshly_made) : $su;
diff -r 6530b9568c03 -r 55485520d8e9 cgi-bin/LJ/Test.pm
--- a/cgi-bin/LJ/Test.pm	Mon Sep 26 15:57:19 2011 +0800
+++ b/cgi-bin/LJ/Test.pm	Mon Sep 26 16:06:26 2011 +0800
@@ -79,18 +79,16 @@
     my $pfx = $underscore ? "_" : "t_";
     while (1) {
         my $username = $pfx . LJ::rand_chars(15 - length $pfx);
-        my $uid = LJ::create_account({
+        my $u = LJ::User->create(
             user => $username,
             name => "test account $username",
             email => "test\@$LJ::DOMAIN",
             journaltype => $journaltype,
             cluster => $cluster,
-        });
-        if ($uid) {
-            my $u = LJ::load_userid($uid) or next;
-            push @temp_userids, $uid;
-            return $u;
-        }
+        );
+        next unless $u;
+        push @temp_userids, $u->id;
+        return $u;
     }
 }
 
diff -r 6530b9568c03 -r 55485520d8e9 cgi-bin/LJ/User.pm
--- a/cgi-bin/LJ/User.pm	Mon Sep 26 15:57:19 2011 +0800
+++ b/cgi-bin/LJ/User.pm	Mon Sep 26 16:06:26 2011 +0800
@@ -5232,8 +5232,6 @@
     # increment ext_ counter until we successfully create an LJ
     # account.  hard cap it at 10 tries. (arbitrary, but we really
     # shouldn't have *any* failures here, let alone 10 in a row)
-    my $dbh = LJ::get_db_writer();
-    my $uid;
 
     for (1..10) {
         my $extuser = 'ext_' . LJ::alloc_global_counter('E');
@@ -5243,20 +5241,22 @@
             $name = $vident->display;
         }
 
-        $uid = LJ::create_account({
+        $u = LJ::User->create(
             caps => undef,
             user => $extuser,
             name => $ident,
             journaltype => 'I',
-        });
-        last if $uid;
+        );
+        last if $u;
         select undef, undef, undef, .10;  # lets not thrash over this
     }
-    return undef unless $uid &&
-        $dbh->do("INSERT INTO identitymap (idtype, identity, userid) VALUES (?,?,?)",
-                 undef, $type, $ident, $uid);
-
-    $u = LJ::load_userid($uid);
+
+    return undef unless $u;
+
+    my $dbh = LJ::get_db_writer();
+    return undef unless
+        $dbh->do( "INSERT INTO identitymap (idtype, identity, userid) VALUES (?,?,?)",
+                  undef, $type, $ident, $u->id );
 
     # set default style
     $u->set_default_style;
@@ -7128,24 +7128,6 @@
 =cut
 
 # <LJFUNC>
-# name: LJ::create_account
-# des: Creates a new basic account.  <strong>Note:</strong> This function is
-#      not really too useful but should be extended to be useful so
-#      htdocs/create.bml can use it, rather than doing the work itself.
-# returns: integer of userid created, or 0 on failure.
-# args: dbarg?, opts
-# des-opts: hashref containing keys 'user', 'name', 'password', 'email', 'caps', 'journaltype'.
-# </LJFUNC>
-sub create_account {
-    my $opts = shift;
-    my $u = LJ::User->create(%$opts)
-        or return 0;
-
-    return $u->id;
-}
-
-
-# <LJFUNC>
 # name: LJ::new_account_cluster
 # des: Which cluster to put a new account on.  $DEFAULT_CLUSTER if it's
 #      a scalar, random element from [ljconfig[default_cluster]] if it's arrayref.
--------------------------------------------------------------------------------