From 04fa1ca7945d4ebbb688436782ef092e2e734074 Mon Sep 17 00:00:00 2001 From: Paul Driver Date: Wed, 6 Oct 2010 08:51:27 -0700 Subject: [PATCH] VersionTag rollback moved to Fork --- lib/WebGUI/Asset.pm | 12 ++- lib/WebGUI/AssetClipboard.pm | 6 +- lib/WebGUI/AssetExportHtml.pm | 3 +- lib/WebGUI/AssetTrash.pm | 9 ++- lib/WebGUI/Fork.pm | 5 +- lib/WebGUI/Fork/ProgressBar.pm | 126 +++++++++++++++++++++++++++++ lib/WebGUI/Fork/ProgressTree.pm | 111 ++++++------------------- lib/WebGUI/Operation/VersionTag.pm | 74 +++++++++++++++-- 8 files changed, 241 insertions(+), 105 deletions(-) create mode 100644 lib/WebGUI/Fork/ProgressBar.pm diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index b1d1a15bc..20651535d 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -837,7 +837,7 @@ sub fixUrlFromParent { #------------------------------------------------------------------- -=head2 forkWithProgressTree ($args) +=head2 forkWithStatusPage ($args) Kicks off a WebGUI::Fork running $method with $args (from the args hashref) and redirects to a ProgressTree status page to show the progress. The @@ -851,6 +851,10 @@ The name of the WebGUI::Asset method to call The arguments to pass that method (see WebGUI::Fork) +=head3 plugin + +The WebGUI::Operation::Fork plugin to render (e.g. ProgressTree) + =head3 title An key in Asset's i18n hash for the title of the rendered console page @@ -861,7 +865,7 @@ The full url to redirect to after the fork has finished. =cut -sub forkWithProgressTree { +sub forkWithStatusPage { my ( $self, $args ) = @_; my $session = $self->session; @@ -874,7 +878,7 @@ sub forkWithProgressTree { my $method = $session->form->get('proceed') || 'manageTrash'; my $i18n = WebGUI::International->new( $session, 'Asset' ); my $pairs = $process->contentPairs( - 'ProgressTree', { + $args->{plugin}, { title => $i18n->get( $args->{title} ), icon => 'assets', proceed => $args->{redirect} || '', @@ -882,7 +886,7 @@ sub forkWithProgressTree { ); $session->http->setRedirect( $self->getUrl($pairs) ); return 'redirect'; -} ## end sub forkWithProgressTree +} ## end sub forkWithStatusPage #------------------------------------------------------------------- diff --git a/lib/WebGUI/AssetClipboard.pm b/lib/WebGUI/AssetClipboard.pm index 52b4c98aa..3185fd9de 100644 --- a/lib/WebGUI/AssetClipboard.pm +++ b/lib/WebGUI/AssetClipboard.pm @@ -400,7 +400,8 @@ sub www_copy { } $args{assetId} = $self->getId; - $self->forkWithProgressTree({ + $self->forkWithStatusPage({ + plugin => 'ProgressTree', title => 'Copy Assets', redirect => $redir, method => 'copyInFork', @@ -727,7 +728,8 @@ sub www_pasteList { my $form = $session->form; return $session->privilege->insufficient() unless $self->canEdit && $session->form->validToken; - $self->forkWithProgressTree( { + $self->forkWithStatusPage( { + plugin => 'ProgressTree', title => 'Paste Assets', redirect => $self->getUrl( $form->get('proceed') eq 'manageAssets' diff --git a/lib/WebGUI/AssetExportHtml.pm b/lib/WebGUI/AssetExportHtml.pm index 160ab19b4..dca2f5b53 100644 --- a/lib/WebGUI/AssetExportHtml.pm +++ b/lib/WebGUI/AssetExportHtml.pm @@ -1015,7 +1015,8 @@ sub www_exportStatus { my @vars = qw( index depth userId extrasUploadsAction rootUrlAction exportUrl ); - $self->forkWithProgressTree({ + $self->forkWithStatusPage({ + plugin => 'ProgressTree', title => 'Page Export Status', method => 'exportInFork', groupId => 13, diff --git a/lib/WebGUI/AssetTrash.pm b/lib/WebGUI/AssetTrash.pm index c44e22f8f..f097db9b3 100644 --- a/lib/WebGUI/AssetTrash.pm +++ b/lib/WebGUI/AssetTrash.pm @@ -387,7 +387,8 @@ sub www_delete { if ($self->getId eq $asset->getId) { $asset = $self->getParent; } - $self->forkWithProgressTree({ + $self->forkWithStatusPage({ + plugin => 'ProgressTree', title => 'Delete Assets', redirect => $asset->getUrl, method => 'trashInFork', @@ -448,7 +449,8 @@ sub www_deleteList { my $form = $session->form; return $session->privilege->insufficient() unless $session->form->validToken; my $method = $form->get('proceed') || 'manageTrash'; - $self->forkWithProgressTree({ + $self->forkWithStatusPage({ + plugin => 'ProgressTree', title => 'Delete Assets', redirect => $self->getUrl("func=$method"), method => 'trashInFork', @@ -566,7 +568,8 @@ sub www_purgeList { return $session->privilege->insufficient() unless $session->form->validToken; my $method = $form->get('proceed') || 'manageTrash'; $method .= ';systemTrash=1' if $form->get('systemTrash'); - $self->forkWithProgressTree({ + $self->forkWithStatusPage({ + plugin => 'ProgressTree', title => 'purge', redirect => $self->getUrl("func=$method"), method => 'purgeInFork', diff --git a/lib/WebGUI/Fork.pm b/lib/WebGUI/Fork.pm index babcf0c5a..0c3f62dc0 100644 --- a/lib/WebGUI/Fork.pm +++ b/lib/WebGUI/Fork.pm @@ -355,7 +355,7 @@ Signals the fork that it should report its next status, then polls at a configurable, fractional interval (default: .1 seconds) waiting for the fork to claim that its status has been updated. Returns the updated status. See setWait() for a way to change the interval (or disable the waiting procedure -entirely). +entirely). We will only wait for a maximum of 100 intervals. =cut @@ -363,7 +363,8 @@ sub getStatus { my $self = shift; if ( my $interval = $self->{interval} ) { $self->set( { latch => 1 } ); - while (1) { + my $maxWait; + while ($maxWait++ < 100) { sleep $interval; my ( $finished, $latch ) = $self->get( 'finished', 'latch' ); last if $finished || !$latch; diff --git a/lib/WebGUI/Fork/ProgressBar.pm b/lib/WebGUI/Fork/ProgressBar.pm new file mode 100644 index 000000000..312ddc299 --- /dev/null +++ b/lib/WebGUI/Fork/ProgressBar.pm @@ -0,0 +1,126 @@ +package WebGUI::Fork::ProgressBar; + +=head1 LEGAL + + ------------------------------------------------------------------- + WebGUI is Copyright 2001-2009 Plain Black Corporation. + ------------------------------------------------------------------- + Please read the legal notices (docs/legal.txt) and the license + (docs/license.txt) that came with this distribution before using + this software. + ------------------------------------------------------------------- + http://www.plainblack.com info@plainblack.com + ------------------------------------------------------------------- + +=cut + +use strict; +use warnings; + +=head1 NAME + +WebGUI::Fork::ProgressBar + +=head1 DESCRIPTION + +Renders an admin console page that polls ::Status to draw a simple progress +bar along with some kind of message. + +=head1 SUBROUTINES + +These subroutines are available from this package: + +=cut + +use Template; +use HTML::Entities; +use JSON; + +my $template = <<'TEMPLATE'; +

+
+

Time elapsed: seconds.

+ +TEMPLATE + +#------------------------------------------------------------------- + +=head2 handler ( process ) + +See WebGUI::Operation::Fork. + +=cut + +sub handler { renderBar( shift, $template ) } + +#------------------------------------------------------------------- + +=head2 renderBar ( process, template ) + +Renders $template, passing a "params" variable to it that is JSON of a +statusUrl to poll and a page to redirect to. Includes WebGUI.Fork.redirect, +poll, and ProgressBar js and CSS (as well as all their YUI dependancies), and +puts the whole template inside an adminConsole rendered based off some form +parameters. + +=cut + +sub renderBar { + my ( $process, $template ) = @_; + my $session = $process->session; + my $url = $session->url; + my $form = $session->form; + my $style = $session->style; + my $tt = Template->new; + my %vars = ( + params => JSON::encode_json( { + statusUrl => $url->page( $process->contentPairs('Status') ), + redirect => scalar $form->get('proceed'), + } + ), + ); + $tt->process( \$template, \%vars, \my $content ) or die $tt->error; + + my $console = WebGUI::AdminConsole->new( $session, $form->get('icon') ); + $style->setLink( $url->extras("Fork/ProgressBar.css"), { rel => 'stylesheet' } ); + $style->setScript( $url->extras("$_.js") ) + for ( ( + map {"yui/build/$_"} + qw( + yahoo/yahoo-min + dom/dom-min + json/json-min + event/event-min + connection/connection_core-min + ) + ), + 'Fork/ProgressBar', + 'Fork/poll', + 'Fork/redirect' + ); + return $console->render( $content, encode_entities( $form->get('title') ) ); +} ## end sub renderBar + +1; diff --git a/lib/WebGUI/Fork/ProgressTree.pm b/lib/WebGUI/Fork/ProgressTree.pm index 7a51e0e9c..46146119e 100644 --- a/lib/WebGUI/Fork/ProgressTree.pm +++ b/lib/WebGUI/Fork/ProgressTree.pm @@ -35,42 +35,18 @@ These subroutines are available from this package: use Template; use HTML::Entities; use JSON; +use WebGUI::Fork::ProgressBar; my $template = <<'TEMPLATE'; -

-

-
-
-
-
+
Current asset: (/).
seconds elapsed. -[% MACRO inc(file) BLOCK %][% END %] -[% MACRO yui(file) BLOCK %][% inc("yui/build/$file") %][% END %] -[% yui("yahoo/yahoo-min.js") %] -[% yui("json/json-min.js") %] -[% yui("event/event-min.js") %] -[% yui("connection/connection_core-min.js") %] -[% inc("underscore/underscore-min.js") %] TEMPLATE my $stylesheet = <<'STYLESHEET';