Skip to content

Commit

Permalink
Allow a single asset to be passed into findBrokenAssets via --assetId
Browse files Browse the repository at this point in the history
  • Loading branch information
perlDreamer committed Jul 20, 2012
1 parent ca2c063 commit 7c03fc7
Showing 1 changed file with 33 additions and 8 deletions.
41 changes: 33 additions & 8 deletions sbin/findBrokenAssets.pl
Expand Up @@ -23,7 +23,7 @@ BEGIN

$|++; # disable output buffering

our ( $configFile, $help, $man, $fix, $delete, $no_progress );
our ( $configFile, $help, $man, $fix, $delete, $no_progress, $op_assetId );
use Pod::Usage;
use Getopt::Long;
use WebGUI::Session;
Expand All @@ -36,6 +36,7 @@ BEGIN
'fix' => \$fix,
'delete' => \$delete,
'noProgress' => \$no_progress,
'assetId=s' => \$op_assetId,
);

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

my $totalAsset = $session->db->quickScalar('SELECT COUNT(*) FROM asset');
my $totalAssetData = $session->db->quickScalar('SELECT COUNT( DISTINCT( assetId ) ) FROM assetData' );
my $total = $totalAsset >= $totalAssetData ? $totalAsset : $totalAssetData;
## SQL statements

my $total_asset_sql = 'SELECT COUNT(*) FROM asset ';
my $total_assetdata_sql = 'SELECT COUNT( DISTINCT( assetId ) ) FROM assetData ';
my $count_shortcut_sql = q!select count(*) from asset where className='WebGUI::Asset::Shortcut' !;
my $count_files_sql = q!select count(*) from asset where className like 'WebGUI::Asset::File%' !;

# Order by lineage to put corrupt parents before corrupt children
# Join assetData to get all asset and assetData
my $sql = "SELECT * FROM asset LEFT JOIN assetData USING ( assetId ) GROUP BY assetId ORDER BY lineage ASC";
my $sth = $session->db->read($sql);
my $iterator_sql = "SELECT * FROM asset LEFT JOIN assetData USING ( assetId ) ";
my $sql_args = [];
if ($op_assetId) {
my $asset_selector = 'where assetId = ? ';
$iterator_sql .= $asset_selector;
$total_asset_sql .= $asset_selector;
$total_assetdata_sql .= $asset_selector;
$count_shortcut_sql .= ' AND assetId = ? ';
$count_files_sql .= ' AND assetId = ? ';
push @{ $sql_args }, $op_assetId;
}
$iterator_sql .= "GROUP BY assetId ORDER BY lineage ASC";
my $sth = $session->db->read($iterator_sql, $sql_args);

my $totalAsset = $session->db->quickScalar($total_asset_sql, $sql_args);
my $totalAssetData = $session->db->quickScalar($total_assetdata_sql, $sql_args);
my $total = $totalAsset >= $totalAssetData ? $totalAsset : $totalAssetData;

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

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

print "\n";

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

0 comments on commit 7c03fc7

Please sign in to comment.