@@ -74,6 +74,7 @@ sub progress {
74
74
# #Guarantee that we get the most recent revisionDate
75
75
my $max_revision = $session -> db-> prepare(' select max(revisionDate) from assetData where assetId=?' );
76
76
77
+ print " Checking all assets\n " ;
77
78
my $count = 1;
78
79
my %classTables ; # Cache definition lookups
79
80
while ( my %row = $sth -> hash ) {
@@ -204,6 +205,80 @@ sub progress {
204
205
} # # end while ( my %row = $sth->hash)
205
206
$sth -> finish;
206
207
$max_revision -> finish;
208
+ print " \n " ;
209
+
210
+ my $shortcuts = $session -> db-> quickScalar(q! select count(*) from asset where className='WebGUI::Asset::Shortcut'! );
211
+ if ($shortcuts ) {
212
+ print " Checking for broken shortcuts\n " ;
213
+ my $get_shortcut = WebGUI::Asset::Shortcut-> getIsa($session , 0, {returnAll => 1});
214
+ $count = 0;
215
+ SHORTCUT: while (1) {
216
+ my $shortcut = eval { $get_shortcut -> () };
217
+ if ( $@ || Exception::Class-> caught() ) {
218
+ # #Do nothing, since it would have been caught above
219
+ printf " \r %-68s" , " No shortcut to check" ;
220
+ }
221
+ elsif (!$shortcut ) {
222
+ last SHORTCUT
223
+ }
224
+ else {
225
+ my $linked_asset = eval { WebGUI::Asset-> newPending($session , $shortcut -> get(' shortcutToAssetId' )); };
226
+ if ( $@ || Exception::Class-> caught() || ! $linked_asset ) {
227
+ printf " \r %-68s" , " -- Broken shortcut: " .$shortcut -> getId.' pointing to ' .$shortcut -> get(' shortcutToAssetId' );
228
+ if ($delete ) {
229
+ my $success = $shortcut -> purge;
230
+ if ($success ) {
231
+ print " Purged shortcut" ;
232
+ }
233
+ else {
234
+ print " Could not purge shortcut" ;
235
+ }
236
+ }
237
+ print " \n " ;
238
+ }
239
+ }
240
+ progress( $shortcuts , $count ++ ) unless $no_progress ;
241
+ }
242
+ progress( $shortcuts , $count ) unless $no_progress ;
243
+ }
244
+
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
+ }
207
282
208
283
finish($session );
209
284
print " \n " ;
@@ -261,7 +336,20 @@ =head1 SYNOPSIS
261
336
=head1 DESCRIPTION
262
337
263
338
This utility will find any broken assets that cannot be instantiated and are
264
- 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
265
353
266
354
It can also automatically delete them or fix them so you can restore missing data.
267
355
@@ -283,7 +371,7 @@ =head1 OPTIONS
283
371
284
372
=item B<--fix >
285
373
286
- Try to fix any corrupted assets.
374
+ Try to fix any corrupted assets. The broken Shortcuts and File Assets cannot be fixed.
287
375
288
376
=item B<--help >
289
377
0 commit comments