Tree view buttons now work. Changed progress bar helpers to use fork. Added forkId option to AssetHelpers. Added updateAsset service to Admin.
This commit is contained in:
parent
399aa5368b
commit
b27bc19e4d
14 changed files with 757 additions and 277 deletions
|
|
@ -3,6 +3,7 @@ package WebGUI::AssetHelper::Copy;
|
|||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
|
|
@ -34,69 +35,54 @@ These methods are available from this class:
|
|||
|
||||
=head2 process ( $asset )
|
||||
|
||||
Open a progress dialog for the copy operation
|
||||
Fork the copy operation
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($self, $asset) = @_;
|
||||
my $session = $self->session;
|
||||
|
||||
# Should we autocommit?
|
||||
my $commit = $session->setting->get('versionTagMode') eq 'autoCommit';
|
||||
|
||||
# Fork the copy. Forking makes sure it won't get interrupted
|
||||
my $fork = WebGUI::Fork->start(
|
||||
$session, blessed( $self ), 'copy', { assetId => $asset->getId, commit => $commit },
|
||||
);
|
||||
|
||||
return {
|
||||
openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=copy;assetId=' . $asset->getId,
|
||||
forkId => $fork->getId,
|
||||
};
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 www_copy ( $asset )
|
||||
=head2 copy ( $process, $args )
|
||||
|
||||
Perform the copy operation, showing the progress.
|
||||
Perform the copy stuff in a forked process
|
||||
|
||||
=cut
|
||||
|
||||
sub www_copy {
|
||||
my ( $self, $asset ) = @_;
|
||||
my $session = $asset->session;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset');
|
||||
sub copy {
|
||||
my ($process, $args) = @_;
|
||||
my $session = $process->session;
|
||||
my $asset = WebGUI::Asset->newById($session, $args->{assetId});
|
||||
my $tree = WebGUI::ProgressTree->new($session, [ $asset->getId ] );
|
||||
$process->update(sub { $tree->json });
|
||||
my $newAsset = $asset->duplicate({ state => "clipboard" });
|
||||
|
||||
return $session->response->stream( sub {
|
||||
my ( $session ) = @_;
|
||||
my $pb = WebGUI::ProgressBar->new($session);
|
||||
my @stack;
|
||||
# If we aren't committing, add to a tag
|
||||
if ( !$args->{commit} ) {
|
||||
$newAsset->update({
|
||||
status => "pending",
|
||||
tagId => WebGUI::VersionTag->getWorking( $session )->getId,
|
||||
});
|
||||
}
|
||||
$newAsset->update({ title => $newAsset->getTitle . ' (copy)'});
|
||||
|
||||
return $pb->run(
|
||||
admin => 1,
|
||||
total => 2,
|
||||
title => $i18n->get('Copy Assets'),
|
||||
icon => $session->url->extras('adminConsole/assets.gif'),
|
||||
code => sub {
|
||||
my $bar = shift;
|
||||
my $newAsset = $asset->duplicate;
|
||||
$bar->update($i18n->get('cut'));
|
||||
my $title = sprintf("%s (%s)", $asset->getTitle, $i18n->get('copy'));
|
||||
$newAsset->update({ title => $title });
|
||||
$newAsset->cut;
|
||||
my $result = WebGUI::VersionTag->autoCommitWorkingIfEnabled(
|
||||
$session, {
|
||||
allowComments => 1,
|
||||
returnUrl => $asset->getUrl,
|
||||
}
|
||||
);
|
||||
if ( $result eq 'redirect' ) {
|
||||
return $asset->getUrl;
|
||||
}
|
||||
return { message => 'Your asset is now copied!' };
|
||||
},
|
||||
wrap => {
|
||||
'WebGUI::Asset::duplicate' => sub {
|
||||
my ($bar, $original, $asset, @args) = @_;
|
||||
my $name = join '/', @stack, $asset->getTitle;
|
||||
$bar->update($name);
|
||||
return $asset->$original(@args);
|
||||
},
|
||||
}
|
||||
);
|
||||
} );
|
||||
$tree->success($asset->getId);
|
||||
$process->update(sub { $tree->json });
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
|
|
@ -3,6 +3,8 @@ package WebGUI::AssetHelper::Cut;
|
|||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
use Monkey::Patch;
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
|
|
@ -51,58 +53,47 @@ sub process {
|
|||
return { error => $i18n->get('41'), };
|
||||
}
|
||||
|
||||
# Fork the cut. Forking makes sure it won't get interrupted
|
||||
my $fork = WebGUI::Fork->start(
|
||||
$session, blessed( $self ), 'cut', { assetId => $asset->getId },
|
||||
);
|
||||
|
||||
return {
|
||||
openDialog => '?op=assetHelper;helperId=' . $self->id . ';method=cut;assetId=' . $asset->getId,
|
||||
forkId => $fork->getId,
|
||||
};
|
||||
}
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
||||
=head2 www_cut ( $asset )
|
||||
=head2 cut ( process, args )
|
||||
|
||||
Show the progress bar while cutting the asset.
|
||||
Handle the actual cutting in the forked process.
|
||||
|
||||
=cut
|
||||
|
||||
sub www_cut {
|
||||
my ( $self, $asset ) = @_;
|
||||
my $session = $asset->session;
|
||||
my $i18n = WebGUI::International->new($session, 'Asset');
|
||||
sub cut {
|
||||
my ( $process, $args ) = @_;
|
||||
my $asset = WebGUI::Asset->newById( $process->session, $args->{assetId} );
|
||||
|
||||
return $session->response->stream( sub {
|
||||
my ( $session ) = @_;
|
||||
my $pb = WebGUI::ProgressBar->new($session);
|
||||
my @stack;
|
||||
# All the Assets we need to work on
|
||||
my $assetIds = $asset->getLineage( ['self','descendants'] );
|
||||
|
||||
return $pb->run(
|
||||
admin => 1,
|
||||
title => $i18n->get('Copy Assets'),
|
||||
icon => $session->url->extras('adminConsole/assets.gif'),
|
||||
code => sub {
|
||||
my $bar = shift;
|
||||
$bar->update( "Preparing... (i18n)" );
|
||||
$bar->total( $asset->getDescendantCount + 2 );
|
||||
$bar->update( "Cutting... (i18n)" );
|
||||
my $success = $asset->cut();
|
||||
if (! $success) {
|
||||
return { error => $i18n->get('41', 'WebGUI'), };
|
||||
}
|
||||
return { message => "Your asset is cut!" };
|
||||
},
|
||||
wrap => {
|
||||
'WebGUI::Asset::getLineageIterator' => sub {
|
||||
my ($bar, $orig, $asset, @args) = @_;
|
||||
$bar->update("Updating descendants... (i18n)");
|
||||
return $asset->$orig(@args);
|
||||
},
|
||||
'WebGUI::Asset::updateHistory' => sub {
|
||||
my ( $bar, $orig, $asset, @args ) = @_;
|
||||
$bar->update( "Updating " . $asset->getTitle );
|
||||
return $asset->$orig(@args);
|
||||
},
|
||||
},
|
||||
);
|
||||
} );
|
||||
# Build a tree and update process status
|
||||
my $tree = WebGUI::ProgressTree->new( $process->session, $assetIds );
|
||||
$process->update( sub { $tree->json } );
|
||||
|
||||
# Monkeypatch a sub to get a status update
|
||||
my $patch = Monkey::Patch::patch_class(
|
||||
'WebGUI::Asset', 'updateHistory', sub {
|
||||
my ( $orig, $self, @args ) = @_;
|
||||
$tree->success( $self->assetId );
|
||||
$process->update( sub { $tree->json } );
|
||||
$self->$orig( @args );
|
||||
}
|
||||
);
|
||||
|
||||
# Do the actual work
|
||||
$asset->cut;
|
||||
}
|
||||
|
||||
1;
|
||||
|
|
|
|||
107
lib/WebGUI/AssetHelper/Delete.pm
Normal file
107
lib/WebGUI/AssetHelper/Delete.pm
Normal file
|
|
@ -0,0 +1,107 @@
|
|||
package WebGUI::AssetHelper::Delete;
|
||||
|
||||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Deleteright 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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::AssetHelper::Delete
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Delete an Asset, and all descendants
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( $asset )
|
||||
|
||||
Fork the Delete operation
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($self, $asset) = @_;
|
||||
my $session = $self->session;
|
||||
|
||||
my $i18n = WebGUI::International->new($session, 'WebGUI');
|
||||
if (! $asset->canEdit) {
|
||||
return { error => $i18n->get('38'), };
|
||||
}
|
||||
elsif ( $asset->get('isSystem') ) {
|
||||
return { error => $i18n->get('41'), };
|
||||
}
|
||||
|
||||
# Fork the Delete. Forking makes sure it won't get interrupted
|
||||
my $fork = WebGUI::Fork->start(
|
||||
$session, blessed( $self ), 'delete', { assetId => $asset->getId, },
|
||||
);
|
||||
|
||||
return {
|
||||
forkId => $fork->getId,
|
||||
};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 delete ( $process, $args )
|
||||
|
||||
Perform the delete stuff in a forked process
|
||||
|
||||
=cut
|
||||
|
||||
sub delete {
|
||||
my ($process, $args) = @_;
|
||||
my $session = $process->session;
|
||||
my $asset = WebGUI::Asset->newById($session, $args->{assetId});
|
||||
|
||||
# Prepare a tree with all the ids
|
||||
my $ids =
|
||||
$asset->getLineage(
|
||||
[ 'self', 'descendants' ], {
|
||||
statesToInclude => [qw(published clipboard clipboard-limbo trash trash-limbo)],
|
||||
statusToInclude => [qw(approved archived pending)],
|
||||
}
|
||||
);
|
||||
my $tree = WebGUI::ProgressTree->new( $session, $ids );
|
||||
$process->update(sub { $tree->json });
|
||||
|
||||
# Patch a sub to get a status update
|
||||
my $patch = Monkey::Patch::patch_class(
|
||||
'WebGUI::Asset',
|
||||
'setState',
|
||||
sub {
|
||||
my ( $setState, $self, $state ) = @_;
|
||||
my $id = $self->getId;
|
||||
$tree->focus($id);
|
||||
my $ret = $self->$setState($state);
|
||||
$tree->success($id);
|
||||
$process->update(sub { $tree->json });
|
||||
return $ret;
|
||||
}
|
||||
);
|
||||
|
||||
# Do the dirty deed, cheap
|
||||
$asset->trash;
|
||||
}
|
||||
|
||||
1;
|
||||
88
lib/WebGUI/AssetHelper/Duplicate.pm
Normal file
88
lib/WebGUI/AssetHelper/Duplicate.pm
Normal file
|
|
@ -0,0 +1,88 @@
|
|||
package WebGUI::AssetHelper::Duplicate;
|
||||
|
||||
use strict;
|
||||
use Class::C3;
|
||||
use base qw/WebGUI::AssetHelper/;
|
||||
use Scalar::Util qw( blessed );
|
||||
|
||||
=head1 LEGAL
|
||||
|
||||
-------------------------------------------------------------------
|
||||
WebGUI is Duplicateright 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
|
||||
-------------------------------------------------------------------
|
||||
|
||||
=head1 NAME
|
||||
|
||||
Package WebGUI::AssetHelper::Duplicate
|
||||
|
||||
=head1 DESCRIPTION
|
||||
|
||||
Duplicate an Asset, with no children.
|
||||
|
||||
=head1 METHODS
|
||||
|
||||
These methods are available from this class:
|
||||
|
||||
=cut
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 process ( $asset )
|
||||
|
||||
Fork the duplicate operation
|
||||
|
||||
=cut
|
||||
|
||||
sub process {
|
||||
my ($self, $asset) = @_;
|
||||
my $session = $self->session;
|
||||
|
||||
# Should we autocommit?
|
||||
my $commit = $session->setting->get('versionTagMode') eq 'autoCommit';
|
||||
|
||||
# Fork the Duplicate. Forking makes sure it won't get interrupted
|
||||
my $fork = WebGUI::Fork->start(
|
||||
$session, blessed( $self ), 'duplicate', { assetId => $asset->getId, commit => $commit },
|
||||
);
|
||||
|
||||
return {
|
||||
forkId => $fork->getId,
|
||||
};
|
||||
}
|
||||
|
||||
#-------------------------------------------------------------------
|
||||
|
||||
=head2 duplicate ( $process, $args )
|
||||
|
||||
Perform the duplicate stuff in a forked process
|
||||
|
||||
=cut
|
||||
|
||||
sub duplicate {
|
||||
my ($process, $args) = @_;
|
||||
my $session = $process->session;
|
||||
my $asset = WebGUI::Asset->newById($session, $args->{assetId});
|
||||
my $tree = WebGUI::ProgressTree->new($session, [ $asset->getId ] );
|
||||
$process->update(sub { $tree->json });
|
||||
my $newAsset = $asset->duplicate;
|
||||
|
||||
# If we aren't committing, add to a tag
|
||||
if ( !$args->{commit} ) {
|
||||
$newAsset->update({
|
||||
status => "pending",
|
||||
tagId => WebGUI::VersionTag->getWorking( $session )->getId,
|
||||
});
|
||||
}
|
||||
$newAsset->update({ title => $newAsset->getTitle . ' (Duplicate)'});
|
||||
|
||||
$tree->success($asset->getId);
|
||||
$process->update(sub { $tree->json });
|
||||
}
|
||||
|
||||
1;
|
||||
Loading…
Add table
Add a link
Reference in a new issue