Skip to content

Commit 3ef66c7

Browse files
committedJan 19, 2012
Add broken shortcut detection to findBrokenAssets
1 parent 3c8ee71 commit 3ef66c7

File tree

1 file changed

+37
-0
lines changed

1 file changed

+37
-0
lines changed
 

‎sbin/findBrokenAssets.pl

+37
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,7 @@ sub progress {
7474
##Guarantee that we get the most recent revisionDate
7575
my $max_revision = $session->db->prepare('select max(revisionDate) from assetData where assetId=?');
7676

77+
print "Checking all assets\n";
7778
my $count = 1;
7879
my %classTables; # Cache definition lookups
7980
while ( my %row = $sth->hash ) {
@@ -204,6 +205,42 @@ sub progress {
204205
} ## end while ( my %row = $sth->hash)
205206
$sth->finish;
206207
$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 ($fix || $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+
}
207244

208245
finish($session);
209246
print "\n";

0 commit comments

Comments
 (0)
Please sign in to comment.