Permalink
Browse files

fix to ensure default preference entries always exist

  • Loading branch information...
1 parent c664da0 commit e0c65c97ffe7c98c5555b1da789c8fe6d26d743f barbie committed Dec 14, 2008
Showing with 45 additions and 15 deletions.
  1. +5 −0 CHANGES
  2. +3 −3 META.yml
  3. +20 −9 lib/CPAN/Testers/WWW/Reports/Mailer.pm
  4. +17 −3 lib/CPAN/Testers/WWW/Reports/Mailer/DBUtils.pm
View
@@ -1,5 +1,10 @@
Revision history for Perl module CPAN::Testers::WWW::Reports::Mailer.
+0.07 current
+ - fix to ensure default preference entries always exist.
+ - fix broken SQL for incorrect table name :(
+ - additional POD for DBUtils.pm.
+
0.06 17/11/2008
- fixed run time error where iterator call was bogus :(
- fixed preferences parsing to correctly set the new fields for ignored
View
@@ -1,6 +1,6 @@
--- #YAML:1.0
name: CPAN-Testers-WWW-Reports-Mailer
-version: 0.06
+version: 0.07
abstract: CPAN Testers Reports Mailer
author:
- Barbie <barbie@cpan.org>
@@ -30,10 +30,10 @@ requires:
provides:
CPAN::Testers::WWW::Reports::Mailer:
file: lib/CPAN/Testers/WWW/Reports/Mailer.pm
- version: 0.06
+ version: 0.07
CPAN::Testers::WWW::Reports::Mailer::DBUtils:
file: lib/CPAN/Testers/WWW/Reports/Mailer/DBUtils.pm
- version: 0.06
+ version: 0.07
meta-spec:
version: 1.4
@@ -4,7 +4,7 @@ use warnings;
use strict;
use vars qw($VERSION);
-$VERSION = '0.06';
+$VERSION = '0.07';
=head1 NAME
@@ -96,10 +96,12 @@ my %phrasebook = (
'GetReportCount' => "SELECT id FROM cpanstats WHERE platform=? AND perl=? AND state=? AND id < ? LIMIT 2",
'GetLatestDistVers' => "SELECT version FROM cpanstats WHERE dist=? AND state='cpan' ORDER BY id DESC LIMIT 1",
'GetAuthor' => "SELECT tester FROM cpanstats WHERE dist=? AND version=? AND state='cpan' LIMIT 1",
- 'GetDistPrefs' => "SELECT * FROM prefs_distributions WHERE pauseid=? AND distribution=?",
+
+ 'GetAuthorPrefs' => "SELECT * FROM prefs_authors WHERE pauseid=?",
'GetDefaultPrefs' => "SELECT * FROM prefs_authors AS a INNER JOIN prefs_distributions AS d ON d.pauseid=a.pauseid AND d.distribution='-' WHERE a.pauseid=?",
+ 'GetDistPrefs' => "SELECT * FROM prefs_distributions WHERE pauseid=? AND distribution=?",
'InsertAuthorLogin' => 'INSERT INTO prefs_authors (active,lastlogin,pauseid) VALUES (1,?,?)',
- 'InsertDistPrefs' => "INSERT INTO prefs_distribution (pauseid,distribution,ignored,report,grade,tuple,version,patches,perl,platform) VALUES (?,?,0,1,'FAIL','FIRST','LATEST',0,'ALL','ALL')",
+ 'InsertDistPrefs' => "INSERT INTO prefs_distributions (pauseid,distribution,ignored,report,grade,tuple,version,patches,perl,platform) VALUES (?,?,0,1,'FAIL','FIRST','LATEST',0,'ALL','ALL')",
);
# -------------------------------------
@@ -394,6 +396,7 @@ sub get_author {
sub get_prefs {
my ($author,$dist) = @_;
+ my $active = 0;
# get distribution defaults
if($author && $dist) {
@@ -416,19 +419,27 @@ sub get_prefs {
return $prefs{$author}{default};
}
- my @rows = $options{authors}->GetQuery('hash',$phrasebook{'GetDefaultPrefs'}, $author);
- if(@rows) {
- $prefs{$author}{default} = parse_prefs($rows[0]);
- $prefs{$author}{default}{active} = $rows[0]->{active} || 0;
- return $prefs{$author}{default};
+ my @auth = $options{authors}->GetQuery('hash',$phrasebook{'GetAuthorPrefs'}, $author);
+ if(@auth) {
+ $prefs{$author}{default}{active} = $auth[0]->{active} || 0;
+
+ my @rows = $options{authors}->GetQuery('hash',$phrasebook{'GetDefaultPrefs'}, $author);
+ if(@rows) {
+ $prefs{$author}{default} = parse_prefs($rows[0]);
+ $prefs{$author}{default}{active} = $rows[0]->{active} || 0;
+ return $prefs{$author}{default};
+ } else {
+ $options{authors}->DoQuery($phrasebook{'InsertDistPrefs'}, $author, '-');
+ $active = $prefs{$author}{default}{active};
+ }
}
# fall through and assume new author
}
# use global defaults
my %prefs = (
- active => 0,
+ active => $active,
ignored => 0,
report => 1,
grades => {'FAIL' => 1},
@@ -4,7 +4,7 @@ use warnings;
use strict;
use vars qw($VERSION);
-$VERSION = '0.06';
+$VERSION = '0.07';
=head1 NAME
@@ -14,9 +14,13 @@ CPAN::Testers::WWW::Reports::Mailer::DBUtils - Database Wrapper
use CPAN::Testers::WWW::Reports::Mailer::DBUtils;
+ my $dbx = CPAN::Testers::WWW::Reports::Mailer::DBUtils->new({
+ driver => 'mysql',
+ database => 'testdb');
+
my $dbi = CPAN::Testers::WWW::Reports::Mailer::DBUtils->new({
- driver => 'CSV',
- file => '/var/www/mysite/db);
+ driver => 'CSV',
+ dbfile => '/var/www/mysite/db);
sub errors { print STDERR "Error: $_[0], sql=$_[1]\n" }
my @arr = $dbi->GetQuery('array',$sql);
@@ -40,6 +44,16 @@ The DBUtils package is a further database interface layer, providing a
collection of control methods to initiate the database connection, handle
errors and a smooth handover from the program to the database drivers.
+Known supported drivers:
+
+ MySQL (database)
+ SQLite (database)
+ CSV (dbfile)
+ ODBC (driver)
+
+The keys in braces above, indicate how the name/location of the data store is
+passed to the connection string.
+
=cut
# -------------------------------------

0 comments on commit e0c65c9

Please sign in to comment.