fu: Close-up of Fu, bringing a scoop of water to her mouth (Default)
fu ([personal profile] fu) wrote in [site community profile] changelog2011-12-01 07:46 am

[dw-free] better organization of LJ functions

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

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

Move LJ::get_cluster_description from ljlib.pl to LJ/DB.pm. Changes package
from LJ::get_cluster_description to LJ::DB::get_cluster_description. Also
removes second (unused) argument from function calls -- not sure what that's
about.

Patch by [personal profile] kareila.

Files modified:
  • cgi-bin/LJ/Console/Command/FindUserCluster.pm
  • cgi-bin/LJ/DB.pm
  • cgi-bin/ljlib.pl
  • htdocs/admin/clusterstatus.bml
  • htdocs/support/see_request.bml
  • t/console-findusercluster.t
--------------------------------------------------------------------------------
diff -r 02660941ee45 -r 4dc5918d25be cgi-bin/LJ/Console/Command/FindUserCluster.pm
--- a/cgi-bin/LJ/Console/Command/FindUserCluster.pm	Thu Dec 01 15:40:14 2011 +0800
+++ b/cgi-bin/LJ/Console/Command/FindUserCluster.pm	Thu Dec 01 15:46:56 2011 +0800
@@ -42,7 +42,7 @@
     return $self->error("Invalid username $user")
         unless $u;
 
-    my $cluster = LJ::get_cluster_description($u->{clusterid}, 0);
+    my $cluster = LJ::DB::get_cluster_description( $u->{clusterid} );
     return $self->print("$user is on the $cluster cluster");
 }
 
diff -r 02660941ee45 -r 4dc5918d25be cgi-bin/LJ/DB.pm
--- a/cgi-bin/LJ/DB.pm	Thu Dec 01 15:40:14 2011 +0800
+++ b/cgi-bin/LJ/DB.pm	Thu Dec 01 15:46:56 2011 +0800
@@ -431,6 +431,23 @@
 }
 
 # <LJFUNC>
+# name: LJ::DB::get_cluster_description
+# des: Get descriptive text for a cluster id.
+# args: clusterid
+# des-clusterid: id of cluster to get description of.
+# returns: string representing the cluster description
+# </LJFUNC>
+sub get_cluster_description {
+    my ( $cid ) = @_;
+    $cid += 0;
+    my $text = LJ::Hooks::run_hook( 'cluster_description', $cid );
+    return $text if $text;
+
+    # default behavior just returns clusterid
+    return $cid;
+}
+
+# <LJFUNC>
 # name: LJ::DB::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.
diff -r 02660941ee45 -r 4dc5918d25be cgi-bin/ljlib.pl
--- a/cgi-bin/ljlib.pl	Thu Dec 01 15:40:14 2011 +0800
+++ b/cgi-bin/ljlib.pl	Thu Dec 01 15:46:56 2011 +0800
@@ -1222,23 +1222,6 @@
 }
 
 # <LJFUNC>
-# name: LJ::get_cluster_description
-# des: Get descriptive text for a cluster id.
-# args: clusterid
-# des-clusterid: id of cluster to get description of.
-# returns: string representing the cluster description
-# </LJFUNC>
-sub get_cluster_description {
-    my ($cid) = shift;
-    $cid += 0;
-    my $text = LJ::Hooks::run_hook('cluster_description', $cid);
-    return $text if $text;
-
-    # default behavior just returns clusterid
-    return $cid;
-}
-
-# <LJFUNC>
 # name: LJ::cmd_buffer_add
 # des: Schedules some command to be run sometime in the future which would
 #      be too slow to do synchronously with the web request.  An example
diff -r 02660941ee45 -r 4dc5918d25be htdocs/admin/clusterstatus.bml
--- a/htdocs/admin/clusterstatus.bml	Thu Dec 01 15:40:14 2011 +0800
+++ b/htdocs/admin/clusterstatus.bml	Thu Dec 01 15:46:56 2011 +0800
@@ -29,7 +29,7 @@
 
     my $ret;
     foreach my $cid (@LJ::CLUSTERS) {
-        my $name = LJ::get_cluster_description($cid) || 'no name';
+        my $name = LJ::DB::get_cluster_description( $cid ) || 'no name';
 
         $ret .= "<b>$name</b>: ";
 
diff -r 02660941ee45 -r 4dc5918d25be htdocs/support/see_request.bml
--- a/htdocs/support/see_request.bml	Thu Dec 01 15:40:14 2011 +0800
+++ b/htdocs/support/see_request.bml	Thu Dec 01 15:46:56 2011 +0800
@@ -422,7 +422,8 @@
         if ($u->{'status'} eq "N") { $ret .= "<b>$ML{'.no'}</b>" . $extraval->(); }
         if ($u->{'status'} eq "T") { $ret .= $ML{'.transitioning'} . $extraval->(); }
         $ret .= "<br />";
-        if ($u->{clusterid}) { $ret .= "$ML{'.cluster'}: <b>" . LJ::get_cluster_description($u->{clusterid}, 1) . "</b>; "; }
+        $ret .= "$ML{'.cluster'}: <b>" . LJ::DB::get_cluster_description( $u->{clusterid} ) . "</b>; "
+            if $u->{clusterid};
         $ret .= "$ML{'.dataversion'}: <b>$u->{dversion}</b>";
         $ret .= "<br />$ML{'.scheme'}: <b>" . ($u->{schemepref} ? $u->{schemepref} : "default") . "</b>; ";
         $ret .= "$ML{'.language'}: <b>" . ($u->{browselang} ? $u->{browselang} : "default") . "</b>";
diff -r 02660941ee45 -r 4dc5918d25be t/console-findusercluster.t
--- a/t/console-findusercluster.t	Thu Dec 01 15:40:14 2011 +0800
+++ b/t/console-findusercluster.t	Thu Dec 01 15:46:56 2011 +0800
@@ -21,10 +21,10 @@
    "error: You are not authorized to run this command.");
 $u->grant_priv("supporthelp");
 is($run->("find_user_cluster " . $u2->user),
-   "success: " . $u2->user . " is on the " . LJ::get_cluster_description($u2->{clusterid}, 0) . " cluster");
+   "success: " . $u2->user . " is on the " . LJ::DB::get_cluster_description( $u2->{clusterid} ) . " cluster");
 $u->revoke_priv("supporthelp");
 
 $u->grant_priv("supportviewscreened");
 is($run->("find_user_cluster " . $u2->user),
-   "success: " . $u2->user . " is on the " . LJ::get_cluster_description($u2->{clusterid}, 0) . " cluster");
+   "success: " . $u2->user . " is on the " . LJ::DB::get_cluster_description( $u2->{clusterid} ) . " cluster");
 $u->revoke_priv("supportviewscreened");
--------------------------------------------------------------------------------