Skip to content

Commit 4ae4877

Browse files
committedJan 18, 2012
Add a new plugin for trashing, restoring and purging assets.
1 parent 91d5939 commit 4ae4877

File tree

1 file changed

+75
-0
lines changed

1 file changed

+75
-0
lines changed
 

‎lib/WGDev/Command/Trash.pm

+75
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
package WGDev::Command::Trash;
2+
# ABSTRACT: Trash assets by URL/assetId
3+
use strict;
4+
use warnings;
5+
use 5.008008;
6+
7+
use parent qw(WGDev::Command::Base);
8+
9+
use WGDev ();
10+
11+
sub config_options {
12+
return qw(
13+
purge
14+
restore
15+
);
16+
}
17+
18+
sub process {
19+
my $self = shift;
20+
my $wgd = $self->wgd;
21+
my @asset_specs = $self->arguments;
22+
my $error;
23+
my $method = $self->option('purge') ? 'purge'
24+
: $self->option('restore') ? 'restore'
25+
: 'trash';
26+
ASSET:
27+
while ( my $asset_spec = shift @asset_specs ) {
28+
my $asset;
29+
if ( !eval { $asset = $wgd->asset->find($asset_spec) } ) {
30+
warn "wgd trash: $asset_spec: No such asset\n";
31+
$error++;
32+
next ASSET;
33+
}
34+
my $success = $asset->$method;
35+
if ($method ne 'restore' && ! $success) {
36+
warn "wgd trash: unable to $method $asset_spec\n";
37+
++$error;
38+
}
39+
}
40+
41+
return (! $error);
42+
}
43+
44+
1;
45+
46+
=head1 SYNOPSIS
47+
48+
wgd trash [--purge] [--restore] <asset> [<asset> ...]
49+
50+
=head1 DESCRIPTION
51+
52+
Puts assets into the trash, or purges them.
53+
54+
=head1 OPTIONS
55+
56+
=over 8
57+
58+
=item C<--purge>
59+
60+
Purges the assets from the system instead of putting it into the trash.
61+
62+
=item C<--restore>
63+
64+
Restores the assets that have been trashed to the regular, published state.
65+
66+
=item C<< <asset> >>
67+
68+
Either an asset URL or an ID. As many can be specified as desired.
69+
Prepending with a slash will force it to be interpreted as a URL.
70+
71+
=back
72+
73+
=cut
74+
75+
1;

0 commit comments

Comments
 (0)