madeon (madeon) wrote in changelog,
madeon
madeon
changelog

[livejournal] r20909: LJSV-2014: Fix exists problems with rena...

Committer: sbelyaev
LJSV-2014: Fix exists problems with rename
U   trunk/cgi-bin/LJ/Support/Request/Tag.pm
U   trunk/htdocs/support/manage_tags.bml
U   trunk/htdocs/support/manage_tags.bml.text
Modified: trunk/cgi-bin/LJ/Support/Request/Tag.pm
===================================================================
--- trunk/cgi-bin/LJ/Support/Request/Tag.pm	2012-01-16 13:57:00 UTC (rev 20908)
+++ trunk/cgi-bin/LJ/Support/Request/Tag.pm	2012-01-16 14:22:50 UTC (rev 20909)
@@ -106,6 +106,10 @@
     my $everywhere  = $opts->{'everywhere'};
     my $allowmerge  = $opts->{'allowmerge'};
 
+    if ( !$sptagid || !$spcatid || !$new_name ) {
+        return 0;
+    }
+
     my $dbh = LJ::get_db_writer();
     my $old_name = LJ::Support::Request::Tag::tag_id_to_name($sptagid);
 
@@ -130,28 +134,31 @@
                                        $new_name );
 
         # Does name exist already?
-        if (!$destination) {
+        if (!%$destination) {
             # just rename 
-            my $row = $dbh->do( "UPDATE supporttag SET name=? WHERE name=?",
-                                undef,
-                                $new_name,
-                                $old_name );
+            $dbh->do( "UPDATE supporttag SET name=? WHERE name=?",
+                      undef,
+                      $new_name,
+                      $old_name );
         } elsif ($allowmerge) {
-
             # update all in 'supporttag'
             foreach my $spcatid (keys %$source) {
-                my $source_hash       = delete $source->{$spcatid};
-                my $source_id         = $source_hash->{'sptagid'};
+                if (!$destination->{$spcatid}) {
+                    next;
+                }
+
                 my $destination_hash  = $destination->{$spcatid};
                 my $destination_id    = $destination_hash->{'sptagid'};
 
+                my $source_hash       = delete $source->{$spcatid};
+                my $source_id         = $source_hash->{'sptagid'};
+
                 my ($current_spid) = $dbh->selectrow_array( 'SELECT spid ' .
                                                        'FROM supporttagmap ' .
                                                        'WHERE sptagid = ?',
                                                        undef,
                                                        $source_id);
 
-
                 my $spids = $dbh->selectcol_arrayref( 'SELECT spid ' .
                                                       'FROM supporttagmap ' .
                                                       'WHERE sptagid = ?',
@@ -172,17 +179,37 @@
                               $spid,
                               $destination_id );
                 }
+            }
 
-                my $update_list = join(',', keys %$source);
+            foreach my $spcatid (keys %$source) {
+
+                my $source_hash = delete $source->{$spcatid};
+                my $source_id   = $source_hash->{'sptagid'};
+
                 $dbh->do( 'UPDATE supporttag ' . 
                           'SET name=? ' .
-                          "WHERE sptagid IN ($update_list)",
+                          "WHERE sptagid = ?",
                           undef,
                           $new_name,
-                          $sptagid );
+                          $source_id );
             }
         } else {
-            return 0;
+            foreach my $spcatid (keys %$source) {
+
+                if (exists $destination->{$spcatid}) {
+                    next;
+                }
+                my $source_hash = delete $source->{$spcatid};
+                my $source_id   = $source_hash->{'sptagid'};
+
+                $dbh->do( 'UPDATE supporttag ' . 
+                          'SET name=? ' .
+                          "WHERE sptagid = ?",
+                          undef,
+                          $new_name,
+                          $source_id );
+            }
+            return 1;
         }
         return 1;
     }
@@ -368,10 +395,10 @@
     return undef unless $tag;
     LJ::MemCache::set("sptagid:$id", $tag->{'name'}, 86400) unless ($LJ::IS_DEV_SERVER);
     my $name = $tag->{'name'};
-    if ($LJ::IS_DEV_SERVER) {
-        my $spcats = LJ::Support::load_cats($tag->{'spcatid'});
-        $name .= ' ('.$spcats->{$tag->{'spcatid'}}->{'catkey'}.')';
-    }
+    #if ($LJ::IS_DEV_SERVER) {
+    #    my $spcats = LJ::Support::load_cats($tag->{'spcatid'});
+    #    $name .= ' ('.$spcats->{$tag->{'spcatid'}}->{'catkey'}.')';
+    #}
 
     return $name;
 }

Modified: trunk/htdocs/support/manage_tags.bml
===================================================================
--- trunk/htdocs/support/manage_tags.bml	2012-01-16 13:57:00 UTC (rev 20908)
+++ trunk/htdocs/support/manage_tags.bml	2012-01-16 14:22:50 UTC (rev 20909)
@@ -2,35 +2,6 @@
 title=><?_ml .title _ml?>
 head<=
 <?_code return LJ::robot_meta_tags(); _code?>
-<script type="text/javascript" charset="UTF-8">
-
-function rename_support_tag(sptagid, spcatid, text) {
-    var wopts = 'width=200,height=130';
-    var redirect_url = "<?_code return $LJ::SITEROOT.'/support/manage_tags.bml'; _code?>";
-    var new_window = window.open('', "Rename: " + text, wopts)
-    with(new_window) {
-        document.body.innerHTML= ""
-        document.write('<html><head>');
-        document.write('<meta http-equiv="content-type" content="text/html; charset=utf-8">');
-        document.write('</head><body>');
-        document.write('<form>New name: <input id="new_name" type="text" value="' + text +'"/><br/>');
-        document.write('rename everywhere <input id="everywhere" type="checkbox"/><br/>');
-        document.write('<input id="rename" type="button" value="rename" onclick="javascript:void(0)"/>');
-        document.write('<input type="button" value="cancel" onclick="javascript:window.close()"/>');
-        document.write('</form>');
-        document.write('</body></html>');;
-    }
-
-    jQuery(new_window.document).contents().find("#rename").click( function() {
-        var every = new_window.document.getElementById('everywhere').checked;
-        var name = new_window.document.getElementById('new_name').value;
-        new_window.close();
-
-        jQuery.post(redirect_url, {renamed: sptagid, catid: spcatid, new_name: name, everywhere: every});
-        location.reload();
-    });
-}
-</script>
 <=head
 body<=
 <?_code
@@ -71,9 +42,34 @@
     my %can_see_cats = map { $_ => 1 } @can_see_cats;
     my %can_manage_cats = map { $_ => 1 } @can_manage_cats;
 
+    if ($FORM{'rename'}) {
+        my $sptagid = $FORM{'sptagid'};
+        my $spcatid = $FORM{'spcatid'};
+        my $name = LJ::Support::Request::Tag::tag_id_to_name($sptagid);
+
+        my $ret = '<form method="POST">';
+        $ret .= qq{New name: <input name="new_name" type="text" value="$name"/>};
+        $ret .= '<br/>';
+        $ret .= qq{<label for="everywhere">$ML{'.rename.everywhere'}</label>};
+        $ret .= qq{<input id="everywhere" type="checkbox" name="everywhere"/>};
+        $ret .= '<br/>';
+        $ret .= qq{<label for="merge">$ML{'.rename.merge'}</label>};
+        $ret .= qq{<input id="merge" type="checkbox" name="allowmerge"/>};
+        $ret .= '<br/>';
+        $ret .= qq{<input id="rename" type="submit" value="rename"/>};
+        $ret .= '<br/>';
+        $ret .= qq{<input type="button" value="cancel"
+                    onclick="javascript:new_window.location($LJ::SITEROOT . '/support/manage_tags.bml')"/>};
+        $ret .= qq{<input type="hidden" value="$sptagid" name="sptagid"/>};
+        $ret .= qq{<input type="hidden" value="$spcatid" name="spcatid"/>};
+        $ret .= qq{<input type="hidden" value="1" name="renamed"/>};
+        $ret .= '</form>';
+        return $ret;
+    }
+
     if (LJ::did_post() && $FORM{'renamed'}) {
-        my $sptagid     = int($FORM{'renamed'});
-        my $spcatid     = int($FORM{'catid'});
+        my $sptagid     = int($FORM{'sptagid'});
+        my $spcatid     = int($FORM{'spcatid'});
         my $everywhere  = $FORM{'everywhere'};
         my $allowmerge  = $FORM{'allowmerge'};
         my $new_name    = $FORM{'new_name'};
@@ -81,8 +77,8 @@
         LJ::Support::Request::Tag::rename_tag( {'sptagid'    => $sptagid,
                                                 'spcatid'    => $spcatid,
                                                 'new_name'   => $new_name,
-                                                'everywhere' => $everywhere eq 'true',
-                                                'allowmerge' => 1} );
+                                                'everywhere' => $everywhere,
+                                                'allowmerge' => $allowmerge } );
 
         return BML::redirect($LJ::SITEROOT . '/support/manage_tags.bml');
     }
@@ -92,18 +88,16 @@
         foreach my $k (keys %FORM) {
             push @delete, $1 if ($k =~ /^delete-(\d+)$/ && $FORM{$k});
         }
-        
+
         LJ::Support::Request::Tag::drop_tags(\@delete, \@can_manage_cats);
         return BML::redirect($LJ::SITEROOT . '/support/manage_tags.bml');
     }
 
-
-
     my $ret;
     $ret .= '<form action="" method="post">';
 
     foreach my $spcat (values %$cats) {
-        my $catkey = $spcat->{'catkey'};
+        my $catkey  = $spcat->{'catkey'};
         my $spcatid = $spcat->{'spcatid'};
         my $catname = $spcat->{'catname'};
 
@@ -131,10 +125,11 @@
                         'tags=' . $name . '">' . $ML{'.requests'} . '</a>]';
 
                     $ret .= 
-                        '<a href="javascript:rename_support_tag('.
-                        $sptagid . ','.
-                        $spcatid . ',\''.
-                        $name . '\')">[rename]</a>';
+                        '[<a href="'.$LJ::SITEROOT.'/support/manage_tags.bml?' .
+                        'rename=1&' .
+                        'sptagid='. $sptagid . '&' .
+                        'spcatid=' . $spcatid . '">' .
+                        $ML{'.rename.link'} . '</a>]';
                 } else {
                     $ret .= '<a href="'.$LJ::SITEROOT.'/support/help.bml?' .
                         'tags=' . $name . '">' . $name . '</a>';

Modified: trunk/htdocs/support/manage_tags.bml.text
===================================================================
--- trunk/htdocs/support/manage_tags.bml.text	2012-01-16 13:57:00 UTC (rev 20908)
+++ trunk/htdocs/support/manage_tags.bml.text	2012-01-16 14:22:50 UTC (rev 20909)
@@ -14,3 +14,12 @@
 .title|staleness=1
 .title=Manage Support Tags
 
+.rename.link|staleness=1
+.rename.link=Rename
+
+.rename.everywhere|staleness=1
+.rename.everywhere=Rename everywhere
+
+.rename.merge|staleness=1
+.rename.merge=Merge tags
+

Tags: bml, livejournal, madeon, pm, sbelyaev, text
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