wisest owl (wisest_owl) wrote in changelog,
wisest owl
wisest_owl
changelog

[livejournal] r17934: LJSUP-7570. We need to be able to move c...

Committer: gprochaev
LJSUP-7570. We need to be able to move categories from our verticals to other verticals.

U   trunk/cgi-bin/LJ/Browse.pm
U   trunk/htdocs/admin/browse/manage_category.bml
Modified: trunk/cgi-bin/LJ/Browse.pm
===================================================================
--- trunk/cgi-bin/LJ/Browse.pm	2010-12-15 04:59:06 UTC (rev 17933)
+++ trunk/cgi-bin/LJ/Browse.pm	2010-12-15 05:53:40 UTC (rev 17934)
@@ -175,6 +175,7 @@
     my $catid = shift;
 
     my $c = $class->new( catid => $catid );
+    $c->preload_rows;
 
     return $c;
 }
@@ -632,6 +633,8 @@
         # and delete from %need for error reporting
         delete $need{$obj->{catid}};
 
+        $obj->preload_children;
+
     }
 
     # weird, catids that we couldn't find in memcache or db?
@@ -641,6 +644,21 @@
     return 1;
 }
 
+sub preload_children {
+    my $self = shift;
+
+    my $dbh = LJ::get_db_reader ();
+
+    my $sth = $dbh->prepare ("SELECT * FROM category WHERE parentcatid = ?");
+    $sth->execute($self->catid);
+
+    my @children = ();
+    while (my $row = $sth->fetchrow_hashref) {
+        push @children, $row->{catid};
+    }
+    $self->{children} = \@children;
+}
+
 sub preload_props {
     my $self = shift;
 
@@ -792,7 +810,7 @@
     my %opts = @_;
     my $just_top = $opts{top_children};
 
-    $self->load_props unless $self->{_loaded_props};
+    $self->preload_rows unless $self->{_loaded_row};
 
     # If top_children flag is set, just return the top sub-categories
     my $children = $just_top ?

Modified: trunk/htdocs/admin/browse/manage_category.bml
===================================================================
--- trunk/htdocs/admin/browse/manage_category.bml	2010-12-15 04:59:06 UTC (rev 17933)
+++ trunk/htdocs/admin/browse/manage_category.bml	2010-12-15 05:53:40 UTC (rev 17934)
@@ -50,12 +50,20 @@
                 $cat_[0]->parentid ($cat_[1]->catid);
                 $cat_[0]->vert_id ($cat_[1]->vertical->vert_id)
                     if $cat_[1]->vertical;
-                LJ::MemCache::delete($cat_[1]->memkey_catall(vertical => $cat_[1]->vertical ? $cat_[1]->vertical : undef));
+
+                ## reset caches
+                $cat_[1]->clear_memcache;
+                $cat_[1]->{_loaded_row} = 0;
             } else {
                 ## Move to Vertical
                 $cat_[0]->parentid (0);
                 $cat_[0]->vert_id ($vert_[1]->vert_id);
             }
+            LJ::Browse->reset_singletons();
+            $cat_[0]->clear_memcache;
+            $cat_[0]->{_loaded_row} = 0;
+            $cat_[0]->preload_rows;
+            $cat_[1]->preload_rows if $cat_[1];
             LJ::MemCache::delete($cat_[0]->memkey_catall(vertical => $cat_[0]->vertical ? $cat_[0]->vertical : undef));
             LJ::MemCache::delete($cat_[0]->memkey_catall(vertical => $vert_[1] ? $vert_[1] : undef));
             $ret .= "<span class='super notice'>Category successfully moved.</span>";

Tags: bml, livejournal, pm, wisest-owl
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