Skip to content

Commit c35b2e5

Browse files
committedJan 19, 2012
findBrokenAssets: Don't delete Shortcuts if they were requested to be fixed. Also handle File assets that have lost their files.
1 parent 3ef66c7 commit c35b2e5

File tree

1 file changed

+54
-3
lines changed

1 file changed

+54
-3
lines changed
 

‎sbin/findBrokenAssets.pl

+54-3
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ sub progress {
225225
my $linked_asset = eval { WebGUI::Asset->newPending($session, $shortcut->get('shortcutToAssetId')); };
226226
if ( $@ || Exception::Class->caught() || ! $linked_asset ) {
227227
printf "\r%-68s", "-- Broken shortcut: ".$shortcut->getId.' pointing to '.$shortcut->get('shortcutToAssetId');
228-
if ($fix || $delete) {
228+
if ($delete) {
229229
my $success = $shortcut->purge;
230230
if ($success) {
231231
print "Purged shortcut";
@@ -242,6 +242,44 @@ sub progress {
242242
progress( $shortcuts, $count ) unless $no_progress;
243243
}
244244

245+
print "\n";
246+
247+
my $file_assets = $session->db->quickScalar(q!select count(*) from asset where className like 'WebGUI::Asset::File%'!);
248+
if ($file_assets) {
249+
print "Checking for broken File Assets\n";
250+
my $get_asset = WebGUI::Asset::File->getIsa($session, 0, {returnAll => 1});
251+
$count = 0;
252+
FILE_ASSET: while (1) {
253+
my $file_asset = eval { $get_asset->() };
254+
if ( $@ || Exception::Class->caught() ) {
255+
##Do nothing, since it would have been caught above
256+
printf "\r%-68s", "No asset to check";
257+
}
258+
elsif (!$file_asset) {
259+
last FILE_ASSET
260+
}
261+
else {
262+
my $storage = $file_asset->getStorageLocation;
263+
my $file = $storage->getPath($file_asset->get('filename'));
264+
if (! -e $file) {
265+
printf "\r%-s", "-- Broken file asset: ".$file_asset->getId." file does not exist: $file";
266+
if ($delete) {
267+
my $success = $file_asset->purge;
268+
if ($success) {
269+
print "Purged File Asset";
270+
}
271+
else {
272+
print "Could not purge File Asset";
273+
}
274+
}
275+
print "\n";
276+
}
277+
}
278+
progress( $file_assets, $count++ ) unless $no_progress;
279+
}
280+
progress( $file_assets, $count ) unless $no_progress;
281+
}
282+
245283
finish($session);
246284
print "\n";
247285

@@ -298,7 +336,20 @@ =head1 SYNOPSIS
298336
=head1 DESCRIPTION
299337
300338
This utility will find any broken assets that cannot be instantiated and are
301-
causing undesired operation of your website.
339+
causing undesired operation of your website. It also checks for these kinds of
340+
semi-working assets and reports them:
341+
342+
=over 4
343+
344+
=item *
345+
346+
Shortcuts pointing to assets that don't exist.
347+
348+
=item *
349+
350+
File assets that have lost their files in the uploads area.
351+
352+
=back
302353
303354
It can also automatically delete them or fix them so you can restore missing data.
304355
@@ -320,7 +371,7 @@ =head1 OPTIONS
320371
321372
=item B<--fix>
322373
323-
Try to fix any corrupted assets.
374+
Try to fix any corrupted assets. The broken Shortcuts and File Assets cannot be fixed.
324375
325376
=item B<--help>
326377

0 commit comments

Comments
 (0)
Please sign in to comment.