Skip to content

Commit 7c03fc7

Browse files
committedJul 20, 2012
Allow a single asset to be passed into findBrokenAssets via --assetId

File tree

1 file changed

+33
-8
lines changed

1 file changed

+33
-8
lines changed
 

‎sbin/findBrokenAssets.pl

+33-8
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ BEGIN
2323

2424
$|++; # disable output buffering
2525

26-
our ( $configFile, $help, $man, $fix, $delete, $no_progress );
26+
our ( $configFile, $help, $man, $fix, $delete, $no_progress, $op_assetId );
2727
use Pod::Usage;
2828
use Getopt::Long;
2929
use WebGUI::Session;
@@ -36,6 +36,7 @@ BEGIN
3636
'fix' => \$fix,
3737
'delete' => \$delete,
3838
'noProgress' => \$no_progress,
39+
'assetId=s' => \$op_assetId,
3940
);
4041

4142
pod2usage( verbose => 1 ) if $help;
@@ -62,14 +63,32 @@ sub progress {
6263
printf ' (%d/%d)', $current, $total;
6364
}
6465

65-
my $totalAsset = $session->db->quickScalar('SELECT COUNT(*) FROM asset');
66-
my $totalAssetData = $session->db->quickScalar('SELECT COUNT( DISTINCT( assetId ) ) FROM assetData' );
67-
my $total = $totalAsset >= $totalAssetData ? $totalAsset : $totalAssetData;
66+
## SQL statements
67+
68+
my $total_asset_sql = 'SELECT COUNT(*) FROM asset ';
69+
my $total_assetdata_sql = 'SELECT COUNT( DISTINCT( assetId ) ) FROM assetData ';
70+
my $count_shortcut_sql = q!select count(*) from asset where className='WebGUI::Asset::Shortcut' !;
71+
my $count_files_sql = q!select count(*) from asset where className like 'WebGUI::Asset::File%' !;
6872

6973
# Order by lineage to put corrupt parents before corrupt children
7074
# Join assetData to get all asset and assetData
71-
my $sql = "SELECT * FROM asset LEFT JOIN assetData USING ( assetId ) GROUP BY assetId ORDER BY lineage ASC";
72-
my $sth = $session->db->read($sql);
75+
my $iterator_sql = "SELECT * FROM asset LEFT JOIN assetData USING ( assetId ) ";
76+
my $sql_args = [];
77+
if ($op_assetId) {
78+
my $asset_selector = 'where assetId = ? ';
79+
$iterator_sql .= $asset_selector;
80+
$total_asset_sql .= $asset_selector;
81+
$total_assetdata_sql .= $asset_selector;
82+
$count_shortcut_sql .= ' AND assetId = ? ';
83+
$count_files_sql .= ' AND assetId = ? ';
84+
push @{ $sql_args }, $op_assetId;
85+
}
86+
$iterator_sql .= "GROUP BY assetId ORDER BY lineage ASC";
87+
my $sth = $session->db->read($iterator_sql, $sql_args);
88+
89+
my $totalAsset = $session->db->quickScalar($total_asset_sql, $sql_args);
90+
my $totalAssetData = $session->db->quickScalar($total_assetdata_sql, $sql_args);
91+
my $total = $totalAsset >= $totalAssetData ? $totalAsset : $totalAssetData;
7392

7493
##Guarantee that we get the most recent revisionDate
7594
my $max_revision = $session->db->prepare('select max(revisionDate) from assetData where assetId=?');
@@ -207,9 +226,10 @@ sub progress {
207226
$max_revision->finish;
208227
print "\n";
209228

210-
my $shortcuts = $session->db->quickScalar(q!select count(*) from asset where className='WebGUI::Asset::Shortcut'!);
229+
my $shortcuts = $session->db->quickScalar($count_shortcut_sql, $sql_args);
211230
if ($shortcuts) {
212231
print "Checking for broken shortcuts\n";
232+
use WebGUI::Asset::Shortcut;
213233
my $get_shortcut = WebGUI::Asset::Shortcut->getIsa($session, 0, {returnAll => 1});
214234
$count = 0;
215235
SHORTCUT: while (1) {
@@ -244,9 +264,10 @@ sub progress {
244264

245265
print "\n";
246266

247-
my $file_assets = $session->db->quickScalar(q!select count(*) from asset where className like 'WebGUI::Asset::File%'!);
267+
my $file_assets = $session->db->quickScalar($count_files_sql, $sql_args);
248268
if ($file_assets) {
249269
print "Checking for broken File Assets\n";
270+
use WebGUI::Asset::File;
250271
my $get_asset = WebGUI::Asset::File->getIsa($session, 0, {returnAll => 1});
251272
$count = 0;
252273
FILE_ASSET: while (1) {
@@ -378,6 +399,10 @@ =head1 OPTIONS
378399
379400
Try to fix any corrupted assets. The broken Shortcuts and File Assets cannot be fixed.
380401
402+
=item B<--assetId=s>
403+
404+
Limit the search for all broken assets to one assetId.
405+
381406
=item B<--help>
382407
383408
Shows a short summary and usage

0 commit comments

Comments
 (0)
Please sign in to comment.