Better @INC fiddling and degenerate case for ProgressTree

This commit is contained in:
Paul Driver 2010-11-08 07:54:14 -06:00
parent f14545ec12
commit bb8753cd2a
7 changed files with 49 additions and 23 deletions

View file

@ -73,6 +73,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;
@ -331,6 +332,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',

View file

@ -664,6 +664,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) },

View file

@ -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',
@ -390,6 +391,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',

View file

@ -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 {

View file

@ -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));

View file

@ -172,6 +172,7 @@ sub rollbackInFork {
$update->();
}
);
$update->();
$tag->rollback( {
outputSub => sub {
$status{message} = shift;

View file

@ -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 = {