From 21ae5f00945b3064e5632e3526ae2184f273f7eb Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Mon, 8 Nov 2010 07:54:14 -0600 Subject: [PATCH] Better @INC fiddling and degenerate case for ProgressTree --- lib/WebGUI/AssetClipboard.pm | 2 ++ lib/WebGUI/AssetExportHtml.pm | 1 + lib/WebGUI/AssetTrash.pm | 2 ++ lib/WebGUI/Fork.pm | 20 +++++++++++++- lib/WebGUI/Fork/ProgressTree.pm | 2 +- lib/WebGUI/Operation/VersionTag.pm | 1 + lib/WebGUI/ProgressTree.pm | 44 ++++++++++++++++-------------- 7 files changed, 49 insertions(+), 23 deletions(-) diff --git a/lib/WebGUI/AssetClipboard.pm b/lib/WebGUI/AssetClipboard.pm index 3185fd9de..f81565959 100644 --- a/lib/WebGUI/AssetClipboard.pm +++ b/lib/WebGUI/AssetClipboard.pm @@ -72,6 +72,7 @@ sub copyInFork { } my $ids = $asset->getLineage(\@pedigree); my $tree = WebGUI::ProgressTree->new($session, $ids); + $process->update(sub { $tree->json }); my $patch = Monkey::Patch::patch_class( 'WebGUI::Asset', 'duplicate', sub { my $duplicate = shift; @@ -326,6 +327,7 @@ sub pasteInFork { } @roots; my $tree = WebGUI::ProgressTree->new( $session, \@ids ); + $process->update(sub { $tree->json }); my $patch = Monkey::Patch::patch_class( 'WebGUI::Asset', 'indexContent', diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index dca2f5b53..f3ad994c8 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -673,6 +673,7 @@ sub exportInFork { $args->{indexFileName} = delete $args->{index}; my $assetIds = $self->exportGetDescendants( undef, $args->{depth} ); my $tree = WebGUI::ProgressTree->new( $session, $assetIds ); + $process->update( sub { $tree->json } ); my %reports = ( 'done' => sub { $tree->success(shift) }, 'exporting page' => sub { $tree->focus(shift) }, diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index 26e74f8a5..23eaa7f34 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -225,6 +225,7 @@ sub purgeInFork { } @roots; my $tree = WebGUI::ProgressTree->new( $session, \@ids ); + $process->update( sub { $tree->json } ); my $patch = Monkey::Patch::patch_class( 'WebGUI::Asset', 'purge', @@ -380,6 +381,7 @@ sub trashInFork { } @roots; my $tree = WebGUI::ProgressTree->new( $session, \@ids ); + $process->update(sub { $tree->json }); my $patch = Monkey::Patch::patch_class( 'WebGUI::Asset', 'setState', diff --git a/lib/WebGUI/Fork.pm b/lib/WebGUI/Fork.pm index 5be0d2694..c1d75c2d6 100644 --- a/lib/WebGUI/Fork.pm +++ b/lib/WebGUI/Fork.pm @@ -97,6 +97,23 @@ sub canView { #------------------------------------------------------------------- +=head2 cleanINC(@INC) + +Class method. Returns a new @INC array (but does not set it) to be used for +forked/daemonized processes. Note that you pass in @INC and new one is +returned, but doesn't replace the original. You must do that yourself. + +=cut + +sub cleanINC { + # gotta get rid of hooks until we think of a way to serialize them in + # forkAndExec (if we ever want to). Serializing coderefs is a tricky + # business. + map { File::Spec->rel2abs($_) } grep { !ref } @_; +} + +#------------------------------------------------------------------- + =head2 contentPairs ($module, $pid, $extra) Returns a bit of query string useful for redirecting to a @@ -278,7 +295,7 @@ sub forkAndExec { my $id = $self->getId; my $class = ref $self; my $json = JSON::encode_json($request); - my @inc = map {"-I$_"} map { File::Spec->rel2abs($_) } grep { !ref } @INC; + my @inc = $class->cleanINC(@INC); my @argv = (@inc, "-M$class", "-e$class->runCmd()" ); $class->daemonize( $json, @@ -413,6 +430,7 @@ sub init { $0 = 'webgui-fork-master'; $pipe->reader; local $/ = "\x{0}"; + @INC = $class->cleanINC(@INC); while ( my $request = $pipe->getline ) { chomp $request; eval { diff --git a/lib/WebGUI/Fork/ProgressTree.pm b/lib/WebGUI/Fork/ProgressTree.pm index 313e52ddc..5ad75f1fc 100644 --- a/lib/WebGUI/Fork/ProgressTree.pm +++ b/lib/WebGUI/Fork/ProgressTree.pm @@ -73,7 +73,7 @@ my $template = <<'TEMPLATE'; finished += 1; } if (asset.focus) { - li.className += 'focus'; + YAHOO.util.Dom.addClass(li, 'focus'); focus = asset.url; } li.appendChild(document.createTextNode(txt)); diff --git a/lib/WebGUI/Operation/VersionTag.pm b/lib/WebGUI/Operation/VersionTag.pm index 5fce10cd9..c5d85a812 100644 --- a/lib/WebGUI/Operation/VersionTag.pm +++ b/lib/WebGUI/Operation/VersionTag.pm @@ -171,6 +171,7 @@ sub rollbackInFork { $update->(); } ); + $update->(); $tag->rollback( { outputSub => sub { $status{message} = shift; diff --git a/lib/WebGUI/ProgressTree.pm b/lib/WebGUI/ProgressTree.pm index 079907ba5..c5e528a13 100644 --- a/lib/WebGUI/ProgressTree.pm +++ b/lib/WebGUI/ProgressTree.pm @@ -46,30 +46,32 @@ Constructs new tree object for tracking the progress of $assetIds. sub new { my ( $class, $session, $assetIds ) = @_; - my $db = $session->db; - my $dbh = $db->dbh; - my $set = join( ',', map { $dbh->quote($_) } @$assetIds ); - my $sql = qq{ - SELECT a.assetId, a.parentId, d.url - FROM asset a INNER JOIN assetData d ON a.assetId = d.assetId - WHERE a.assetId IN ($set) - ORDER BY a.lineage ASC, d.revisionDate DESC - }; - my $sth = $db->read($sql); my ( %flat, @roots ); + if (@$assetIds) { + my $db = $session->db; + my $dbh = $db->dbh; + my $set = join( ',', map { $dbh->quote($_) } @$assetIds ); + my $sql = qq{ + SELECT a.assetId, a.parentId, d.url + FROM asset a INNER JOIN assetData d ON a.assetId = d.assetId + WHERE a.assetId IN ($set) + ORDER BY a.lineage ASC, d.revisionDate DESC + }; + my $sth = $db->read($sql); - while ( my $asset = $sth->hashRef ) { - my ( $id, $parentId ) = delete @{$asset}{ 'assetId', 'parentId' }; + while ( my $asset = $sth->hashRef ) { + my ( $id, $parentId ) = delete @{$asset}{ 'assetId', 'parentId' }; - # We'll get back multiple rows for each asset, but the first one is - # the latest. Skip the others. - next if $flat{$id}; - $flat{$id} = $asset; - if ( my $parent = $flat{$parentId} ) { - push( @{ $parent->{children} }, $asset ); - } - else { - push( @roots, $asset ); + # We'll get back multiple rows for each asset, but the first one + # is the latest. Skip the others. + next if $flat{$id}; + $flat{$id} = $asset; + if ( my $parent = $flat{$parentId} ) { + push( @{ $parent->{children} }, $asset ); + } + else { + push( @roots, $asset ); + } } } my $self = {