Андрей (andy) wrote in changelog,
Андрей
andy
changelog

[livejournal] r21935: LJSUP-12016 (Store tags for images data ...

Committer: ailyin
LJSUP-12016 (Store tags for images data (to be used later))
U   trunk/cgi-bin/LJ/Support/Request/Tag.pm
U   trunk/cgi-bin/LJ/Text.pm
U   trunk/cgi-bin/LJ/User.pm
Modified: trunk/cgi-bin/LJ/Support/Request/Tag.pm
===================================================================
--- trunk/cgi-bin/LJ/Support/Request/Tag.pm	2012-05-12 10:53:33 UTC (rev 21934)
+++ trunk/cgi-bin/LJ/Support/Request/Tag.pm	2012-05-12 11:41:11 UTC (rev 21935)
@@ -52,6 +52,8 @@
 use Encode qw(encode decode);
 use List::MoreUtils qw();
 
+use LJ::Text;
+
 # get_requests_tags(): fetches information about which tags are assigned
 # to the given requests; returns:
 # { $spid1 => [ $sptagid1, $sptagid2 ], $spid2 => [ $sptagid3, $sptagid4 ] }
@@ -387,23 +389,9 @@
 
     $name =~ s/\(.*?\)//g if $LJ::IS_DEV_SERVER;
 
-    # cleanup
-    $name =~ s/,//g; # tag separator
-    $name =~ s/(^\s+|\s+$)//g; # starting or trailing whitespace
-    $name =~ s/\s+/ /g; # excessive whitespace
-
-    return undef unless $name;
-
-    # this hack is to get Perl actually perform lc() on a Unicode string
-    # you're welcome to fix it if you know a better way ;)
-    $name = decode('utf8', $name);
-    $name = lc($name);
-    $name = encode('utf8', $name);
-
     # leave only the first 50 characters - it's the DB schema limit
-    $name =~ s/^(.{50}).*$/$1/;
-
-    return $name;
+    return
+        LJ::Text->normalize_tag_name( $name, 'length_limit' => 50 ) || undef;
 }
 
 # tag_name_to_id(): gets an sptagid for a given name and spcatid,

Modified: trunk/cgi-bin/LJ/Text.pm
===================================================================
--- trunk/cgi-bin/LJ/Text.pm	2012-05-12 10:53:33 UTC (rev 21934)
+++ trunk/cgi-bin/LJ/Text.pm	2012-05-12 11:41:11 UTC (rev 21935)
@@ -408,4 +408,30 @@
     return $text;
 }
 
+# this is extracted from LJ::Support::Request::Tag; note that it's only
+# used in selected places at this time -- for example, entry tags are still
+# case-sensitive in case they use non-ASCII symbols
+sub normalize_tag_name {
+    my ( $class, $name, %opts ) = @_;
+
+    # cleanup
+    $name =~ s/,//g; # tag separator
+    $name =~ s/(^\s+|\s+$)//g; # starting or trailing whitespace
+    $name =~ s/\s+/ /g; # excessive whitespace
+
+    return unless $name;
+
+    # this hack is to get Perl actually perform lc() on a Unicode string
+    # you're welcome to fix it if you know a better way ;)
+    $name = decode_utf8($name);
+    $name = lc($name);
+    $name = encode_utf8($name);
+
+    if ( my $length_limit = delete $opts{'length_limit'} ) {
+        $name = $class->truncate_to_bytes( $name, $length_limit );
+    }
+
+    return $name;
+}
+
 1;

Modified: trunk/cgi-bin/LJ/User.pm
===================================================================
--- trunk/cgi-bin/LJ/User.pm	2012-05-12 10:53:33 UTC (rev 21934)
+++ trunk/cgi-bin/LJ/User.pm	2012-05-12 11:41:11 UTC (rev 21935)
@@ -7530,7 +7530,7 @@
 #       'Q' == Notification Inbox, 'G' == 'SMS messaGe'
 #       'D' == 'moDule embed contents', 'W' == 'Wish-list element'
 #       'F' == Photo ID, 'A' == Album ID, 'Y' == delaYed entries
-#       'I' == Fotki migration log ID
+#       'I' == Fotki migration log ID, 'H' == pics tag id
 #
 # FIXME: both phonepost and vgift are ljcom.  need hooks. but then also
 #        need a separate namespace.  perhaps a separate function/table?
@@ -7541,7 +7541,7 @@
 
     ##################################################################
     # IF YOU UPDATE THIS MAKE SURE YOU ADD INITIALIZATION CODE BELOW #
-    return undef unless $dom =~ /^[LTMPSRKCOVEQGDWFAYI]$/;             #
+    return undef unless $dom =~ /^[LTMPSRKCOVEQGDWFAYIH]$/;             #
     ##################################################################
 
     my $dbh = LJ::get_db_writer();
@@ -7671,6 +7671,9 @@
     } elsif ( $dom eq 'I' ) {
         $newmax = $u->selectrow_array("SELECT MAX(logid) FROM fotki_migration_log WHERE userid=?",
                                       undef, $uid);
+    } elsif ( $dom eq 'H' ) {
+        $newmax = $u->selectrow_array("SELECT MAX(tag_id) FROM fotki_tags WHERE userid=?",
+                                      undef, $uid);
     } else {
         die "No user counter initializer defined for area '$dom'.\n";
     }

Tags: ailyin, andy, livejournal, pm
Subscribe
  • Post a new comment

    Error

    Anonymous comments are disabled in this journal

    default userpic

    Your reply will be screened

    Your IP address will be recorded 

  • 0 comments