[Cpan-forum-commit] rev 146 - in branches/db_changes: . bin
lib/CPAN lib/CPAN/Forum schema templates
svn at pti.co.il
svn at pti.co.il
Fri Mar 25 23:01:30 IST 2005
Author: gabor
Date: 2005-03-25 23:01:29 +0200 (Fri, 25 Mar 2005)
New Revision: 146
Added:
branches/db_changes/lib/CPAN/Forum/Authors.pm
branches/db_changes/lib/CPAN/Forum/Subscriptions_pauseid.pm
Modified:
branches/db_changes/TODO
branches/db_changes/bin/populate.pl
branches/db_changes/bin/upgrade.pl
branches/db_changes/lib/CPAN/Forum.pm
branches/db_changes/lib/CPAN/Forum/Groups.pm
branches/db_changes/lib/CPAN/Forum/INC.pm
branches/db_changes/schema/schema.sql
branches/db_changes/templates/mypan.tmpl
branches/db_changes/templates/notes.tmpl
Log:
working on populating the database with version data and PAUSEID so people will be able to monitor per PAUSEID
Modified: branches/db_changes/TODO
===================================================================
--- branches/db_changes/TODO 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/TODO 2005-03-25 21:01:29 UTC (rev 146)
@@ -1,12 +1,18 @@
+- A way to monitor all current and future modules associated with a certain PAUSE ID.
+ (both RSS and e-mail)
-- Enable people to subscribe to all messages or all thread starters or all followups
- A table called "subscription_all"
+
+- Clean up the listing of the subscribers at the bottom of the pages:
+ Separate people who will receive all messages
+ Thread starters
+ And show names of people with "followup set" only within the threads they posted.
-
+- Unite and clean up the code that fetches list of people who need to be notified
+
- Script that populates databse should not lock the whole database for a long time
Maybe it should fetch all the data to memory and work there.
@@ -30,7 +36,6 @@
Send out e-mail about PAUSEID changes
-
A table called "subscription_PAUSE"
@@ -44,10 +49,6 @@
So especially the module authors would like to have a button that sais
subscribe too all the modules of XYZ
-
-- A way to monitor all current and future modules associated with a certain PAUSE ID.
- (both RSS and e-mail)
-
- Let people select a group of distros (e.g. all the distros by author SZABGAB)
and show them on the /mypan interface (or just subscribe to all of them)
Modified: branches/db_changes/bin/populate.pl
===================================================================
--- branches/db_changes/bin/populate.pl 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/bin/populate.pl 2005-03-25 21:01:29 UTC (rev 146)
@@ -8,21 +8,21 @@
use FindBin qw ($Bin);
use Text::CSV_XS;
use Mail::Sendmail qw(sendmail);
+use Getopt::Long qw(GetOptions);
use CPAN::Forum::DBI;
use CPAN::Forum::Groups;
-
-
my $dir = "$Bin/../db";
my $dbfile = "$dir/forum.db";
-my $version_file = "$dir/cpan_versions.txt";
-my $csv = Text::CSV_XS->new();
+my $csv = Text::CSV_XS->new();
+my %opts;
CPAN::Forum::DBI->myinit($dbfile);
+GetOptions(\%opts, "sendmail");
my $source = shift @ARGV;
@@ -48,55 +48,69 @@
my $p = Parse::CPAN::Packages->new($source);
my @distributions = $p->distributions;
+my %message = (
+ version => "",
+ pauseid => "",
+ new => "",
+);
-my %versions;
-open my $in, "<", $version_file or die "Could not open '$version_file' for reading $!\n";
-my $cnt = 0;
-while (my $line = <$in>) {
- $cnt++;
- if (not $csv->parse($line)) {
- warn "ERROR in line $cnt " . $csv->error_input();
- next;
- }
- my ($name, $version) = $csv->fields();
- $versions{$name} = $version;
-}
-
-my $version_message = "";
-my $new_message = "";
foreach my $d (@distributions) {
# skip scripts
next if not $d->prefix or $d->prefix =~ m{^\w/\w\w/\w+/scripts/};
- my $name = $d->dist;
+ my $name = $d->dist;
+ my %new = (
+ version => ($d->version() || ""),
+ pauseid => ($d->cpanid() || ""),
+ );
+
if (not $name) {
#warn "No name: " . $d->prefix . "\n";
next;
}
- # skip names that start with lower case
+ # for now skip names that start with lower case
next if $name =~ /^[a-z]/;
my ($g) = CPAN::Forum::Groups->search(name => $name);
- my $version = $d->version();
+ if ($g) {
+ #if (not defined $version{$name} or $version{$name} ne $new_version) {
+ # $version{$name} ||= ""; # to avoid warnings;
+ # # send e-mail to whoever asked for it.
+ # $version_message .= "The version of $name has changed from $version{$name} to $version\n";
+ #}
+ #if (not defined $version{$name} or $version{$name} ne $new_version) {
+ # #$pausid_message .= "The PAUSEID of $name has changed from $old_paused to $new_pauseid\n";
+ #}
- if ($g) {
- if ($versions{$name} ne $version) {
- # send e-mail to whoever asked for it.
- $version_message .= "The version of $name has changed from $versions{$name} to $version\n";
+ my $changed;
+ foreach my $field (qw(version pauseid)) {
+ print "$name\n";
+ print "NEW: $new{$field}\n";
+ print "OLD: " . $g->$field, "\n";
+ <STDIN>;
+ if (not defined $g->$field or $g->$field ne $new{$field}) {
+ print "change\n";
+ $g->$field($new{$field});
+ $message{$field} .= sprintf "The $field of %s has changed from to %s\n",
+ $name, ($g->$field || ""), $new{$field};
+ $changed++;
+ }
}
- } else {
- $new_message .= "$name $version\n";
+
+ $g->update if $changed;
+ next;
}
- $versions{$name} = $version;
- next if $g;
+ $message{new} .= sprintf "%s %s\n", $name, $new{version}, $new{pauseid};
eval {
- my $dist = CPAN::Forum::Groups->create({
- name => $name,
- gtype => $CPAN::Forum::DBI::group_types{Distribution},
+ my $g = CPAN::Forum::Groups->create({
+ name => $name,
+ gtype => $CPAN::Forum::DBI::group_types{Distribution},
+ version => $new{version},
+ pauseid => $new{pauseid},
});
};
if ($@) {
@@ -105,26 +119,36 @@
}
}
-open my $out, ">", $version_file or die "Could not open '$version_file' for writing $!\n";
-foreach my $name (sort keys %versions) {
- print $out qq("$name","$versions{$name}"\n);
-}
+#open my $out, ">", $version_file or die "Could not open '$version_file' for writing $!\n";
+#foreach my $name (sort keys %version) {
+# print $out qq("$name","$version{$name}"\n);
+#}
my %mail = (
To => 'gabor at pti.co.il',
From => 'cpanforum at cpanforum.com',
Subject => 'CPAN Version Update',
- Message => $version_message,
+ Message => $message{version},
);
-sendmail(%mail);
+if ($opts{sendmail}) {
+ sendmail(%mail);
+} else {
+ open my $fh, ">", "$Bin/../cpan_version_update";
+ print $fh $message{version};
+}
%mail = (
To => 'gabor at pti.co.il',
From => 'cpanforum at cpanforum.com',
Subject => 'New CPAN Distros',
- Message => $new_message,
+ Message => $message{new},
);
-sendmail(%mail);
+if ($opts{sendmail}) {
+ sendmail(%mail);
+} else {
+ open my $fh, ">", "$Bin/../cpan_new_distros";
+ print $fh $message{new};
+}
Modified: branches/db_changes/bin/upgrade.pl
===================================================================
--- branches/db_changes/bin/upgrade.pl 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/bin/upgrade.pl 2005-03-25 21:01:29 UTC (rev 146)
@@ -27,11 +27,11 @@
##########################################################################
-#$dbh->do("DROP TABLE person");
+$dbh->do("DROP TABLE groups");
-foreach my $table (qw(subscriptions_all)) {
+foreach my $table (qw(subscriptions_all groups authors subscriptions_pauseid)) {
my $sql = fetch_sql("CREATE", $table, $schema);
- restore_and_exit("Could not fetch $table from schema") if not $sql;
+ restore_and_exit("Could not fetch table '$table' from schema") if not $sql;
eval {$dbh->do($sql);};
restore_and_exit() if $@;
}
@@ -54,41 +54,47 @@
$dbh = DBI->connect("dbi:SQLite:dbname=$live","","");
$dbh->do(qq(ATTACH DATABASE "$old" as old));
-=pod
-my $sth = $dbh->prepare("select * from old.person");
-$sth->execute;
-while (my $r = $sth->fetchrow_hashref('NAME_lc')) {
- my (@fields, @values);
- foreach my $f (keys %$r) {
- push @fields, $f;
- push @values, $r->{$f};
- }
- my $fields = join(",", @fields);
- my $placeholders = ("?, " x (@fields-1)) . "?";
+copy_table_data($dbh, "groups");
- #$fields .= ", announcement";
- #$placeholders .= " ,?";
- #push @values, 11;
-
- my $sql = "INSERT INTO person ($fields) VALUES ($placeholders)";
- #print $sql;
- my $sth = $dbh->do($sql, undef, @values);
- #$dbh->do("INSERT INTO users (fname) SELECT fname FROM old.users");
-}
-=cut
-
unlink $old;
exit;
#############################################################################
+
+sub copy_table_data {
+ my ($dbh, $table) = @_;
+
+ my $sth = $dbh->prepare("select * from old.groups");
+ $sth->execute;
+ while (my $r = $sth->fetchrow_hashref('NAME_lc')) {
+ my (@fields, @values);
+ foreach my $f (keys %$r) {
+ push @fields, $f;
+ push @values, $r->{$f};
+ }
+ my $fields = join(",", @fields);
+ my $placeholders = ("?, " x (@fields-1)) . "?";
+
+ #$fields .= ", announcement";
+ #$placeholders .= " ,?";
+ #push @values, 11;
+
+ my $sql = "INSERT INTO groups ($fields) VALUES ($placeholders)";
+ #print $sql;
+ my $sth = $dbh->do($sql, undef, @values);
+ #$dbh->do("INSERT INTO users (fname) SELECT fname FROM old.users");
+ }
+}
+
+
sub fetch_sql {
my ($type, $table, $schema) = @_;
my $sql;
for my $statement (split /;\s*/, $schema) {
if ($type eq "CREATE") {
- if ($statement =~ /^CREATE\s+TABLE\s+$table/) {
+ if ($statement =~ /CREATE\s+TABLE\s+$table\s+/) {
$sql = $statement;
last;
}
Added: branches/db_changes/lib/CPAN/Forum/Authors.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/Authors.pm 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/lib/CPAN/Forum/Authors.pm 2005-03-25 21:01:29 UTC (rev 146)
@@ -0,0 +1,11 @@
+package CPAN::Forum::Authors;
+use strict;
+use warnings;
+use Carp;
+use base 'CPAN::Forum::DBI';
+__PACKAGE__->table('authors');
+__PACKAGE__->columns(All => qw/id pauseid/);
+__PACKAGE__->has_many(uid => "CPAN::Forum::Groups");
+__PACKAGE__->has_many(subscriptions => "CPAN::Forum::Subscriptions_pauseid");
+
+1;
Modified: branches/db_changes/lib/CPAN/Forum/Groups.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/Groups.pm 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/lib/CPAN/Forum/Groups.pm 2005-03-25 21:01:29 UTC (rev 146)
@@ -4,12 +4,15 @@
use Carp;
use base 'CPAN::Forum::DBI';
__PACKAGE__->table('groups');
-__PACKAGE__->columns(All => qw/id name gtype status/);
-#__PACKAGE__->columns(Primary => qw/id name/);
-__PACKAGE__->has_many(posts => "CPAN::Forum::Posts");
+__PACKAGE__->columns(Primary => qw/id/);
+__PACKAGE__->columns(Essential => qw/id name version pauseid/);
+__PACKAGE__->columns(Others => qw/gtype status rating review_count/);
+
+__PACKAGE__->has_many(posts => "CPAN::Forum::Posts");
__PACKAGE__->has_many(subscriptions => "CPAN::Forum::Subscriptions");
+__PACKAGE__->has_a (pauseid => "CPAN::Forum::Authors");
-__PACKAGE__->set_sql(count_like => "SELECT count(*) FROM __TABLE__ WHERE %s LIKE '%s'");
-__PACKAGE__->set_sql(count => "SELECT count(*) FROM __TABLE__ WHERE %s = '%s'");
+__PACKAGE__->set_sql(count_like => "SELECT count(*) FROM __TABLE__ WHERE %s LIKE '%s'");
+__PACKAGE__->set_sql(count => "SELECT count(*) FROM __TABLE__ WHERE %s = '%s'");
1;
Modified: branches/db_changes/lib/CPAN/Forum/INC.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/INC.pm 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/lib/CPAN/Forum/INC.pm 2005-03-25 21:01:29 UTC (rev 146)
@@ -10,8 +10,10 @@
use CPAN::Forum::Groups;
use CPAN::Forum::Posts;
+use CPAN::Forum::Authors;
use CPAN::Forum::Subscriptions;
use CPAN::Forum::Subscriptions_all;
+use CPAN::Forum::Subscriptions_pauseid;
1;
Added: branches/db_changes/lib/CPAN/Forum/Subscriptions_pauseid.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum/Subscriptions_pauseid.pm 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/lib/CPAN/Forum/Subscriptions_pauseid.pm 2005-03-25 21:01:29 UTC (rev 146)
@@ -0,0 +1,11 @@
+package CPAN::Forum::Subscriptions_pauseid;
+use strict;
+use warnings;
+use Carp;
+use base 'CPAN::Forum::DBI';
+__PACKAGE__->table('subscriptions_pauseid');
+__PACKAGE__->columns(All => qw/id pauseid uid allposts starters followups announcements/);
+__PACKAGE__->has_a(uid => "CPAN::Forum::Users");
+__PACKAGE__->has_a(pauseid => "CPAN::Forum::Authors");
+
+1;
Modified: branches/db_changes/lib/CPAN/Forum.pm
===================================================================
--- branches/db_changes/lib/CPAN/Forum.pm 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/lib/CPAN/Forum.pm 2005-03-25 21:01:29 UTC (rev 146)
@@ -180,6 +180,9 @@
=head2 Changes
+Enable people to subscribe to all messages or all thread starters or all followups
+Add a table called "subscription_all"
+
Longer usernames
Search box on more pages
Search for module uses % at the beginning of the string as well
@@ -1827,9 +1830,22 @@
};
$gids = "_all";
- my $it = CPAN::Forum::Subscriptions->search(uid => $user->id);
+ my $it = CPAN::Forum::Subscriptions_pauseid->search(uid => $user->id);
while (my $s = $it->next) {
#warn $s->allposts;
+ $gids .= ($gids ? ",_" : "_") . $s->pauseid->id;
+ push @subscriptions, {
+ gid => "_" . $s->pauseid->id,
+ group => $s->pauseid->pauseid,
+ allposts => $s->allposts,
+ starters => $s->starters,
+ followups => $s->followups,
+ };
+ }
+
+ $it = CPAN::Forum::Subscriptions->search(uid => $user->id);
+ while (my $s = $it->next) {
+ #warn $s->allposts;
$gids .= ($gids ? "," : "") . $s->gid->id;
push @subscriptions, {
gid => $s->gid,
@@ -1872,6 +1888,16 @@
});
}
$self->_update_subs($s, $gid);
+ } elsif ($gid =~ /^_(\d+)$/) {
+ my $pauseid = $1;
+ my ($s) = CPAN::Forum::Subscriptions_pauseid->search(pauseid => $pauseid, uid => $user->id);
+ if (not $s) {
+ $s = CPAN::Forum::Subscriptions->create({
+ uid => $user->id,
+ pauseid => $pauseid,
+ });
+ }
+ $self->_update_subs($s, $gid);
} else {
my ($s) = CPAN::Forum::Subscriptions->search(gid => $gid, uid => $user->id);
if (not $s) {
@@ -1883,6 +1909,38 @@
$self->_update_subs($s, $gid);
}
}
+
+ # TODO: error messages in case not all the values were filled in correctly
+ if ($q->param("name") and $q->param("type")) {
+ if ($q->param("type") eq "pauseid") {
+ my $pauseid = uc $q->param("name");
+ my ($pid) = CPAN::Forum::Authors->search(pauseid => $pauseid);
+ if ($pid) {
+ my $s = CPAN::Forum::Subscriptions_pauseid->find_or_create({
+ uid => $user->id,
+ pauseid => $pid->id,
+ });
+ $self->_update_subs($s, "_new");
+ } else {
+ return $self->notes("no_such_pauseid");
+ }
+ }
+ if ($q->param("type") eq "distro") {
+ my $name = $q->param("name");
+ $name =~ s/::/-/g;
+ my ($grp) = CPAN::Forum::Groups->search(name => $name);
+ if ($grp) {
+ my $s = CPAN::Forum::Subscriptions->find_or_create({
+ uid => $user->id,
+ gid => $grp->id,
+ });
+ $self->_update_subs($s, "_new");
+ } else {
+ return $self->notes("no_such_group");
+ }
+ }
+ }
+
$self->notes("mypanok");
}
@@ -2224,6 +2282,9 @@
$self->_sendmail($it, \%mail, \%to);
$it = CPAN::Forum::Subscriptions_all->search(allposts => 1);
$self->_sendmail($it, \%mail, \%to);
+ #$self->log->debug("Post PAUSEID: " . $post->gid->pauseid);
+ #$it = CPAN::Forum::Subscriptions_pauseid->search(allposts => 1, pauseid => $post->gid->pauseid);
+ #$self->_sendmail($it, \%mail, \%to);
# subscription to thread "starters" in the current group
if ($post->thread == $post->id) {
Modified: branches/db_changes/schema/schema.sql
===================================================================
--- branches/db_changes/schema/schema.sql 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/schema/schema.sql 2005-03-25 21:01:29 UTC (rev 146)
@@ -43,7 +43,12 @@
id INTEGER PRIMARY KEY auto_increment,
name VARCHAR(255) UNIQUE NOT NULL,
status INTEGER,
- gtype INTEGER NOT NULL
+ gtype INTEGER NOT NULL,
+ version VARCHAR(100),
+ pauseid INTEGER,
+ rating VARCHAR(10),
+ review_count INTEGER
+ ,FOREIGN KEY (pauseid) REFERENCES authors(id)
);
CREATE TABLE metagroups (
@@ -127,12 +132,10 @@
starters BOOLEAN,
followups BOOLEAN,
announcements BOOLEAN
- ,FOREIGN KEY (gid) REFERENCES groups(id)
+ ,FOREIGN KEY (pauseid) REFERENCES authors(id)
,FOREIGN KEY (uid) REFERENCES users(id)
);
-
-
CREATE TABLE sessions (
id CHAR(32) NOT NULL UNIQUE,
a_session TEXT NOT NULL,
Modified: branches/db_changes/templates/mypan.tmpl
===================================================================
--- branches/db_changes/templates/mypan.tmpl 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/templates/mypan.tmpl 2005-03-25 21:01:29 UTC (rev 146)
@@ -14,7 +14,7 @@
<div class="subscription">
<table>
<tr>
- <th>Distribution</th>
+ <th>Distribution or PAUSEID</th>
<th>All messages</th>
<th>Thread starters</th>
<th>Followups</th>
@@ -35,7 +35,20 @@
<td><input type="checkbox" name="followups_<TMPL_VAR gid>" <TMPL_IF followups>CHECKED</TMPL_IF> /></td>
</tr>
</TMPL_LOOP>
+<tr>
+ <td><input name="name" size="20">
+ <select name="type">
+ <option value=""></option>
+ <option value="distro">Distribution</option>
+ <option value="pauseid">PAUSEID</option>
+ </select>
+ </td>
+ <td><input type="checkbox" name="allposts__new" <TMPL_IF allposts>CHECKED</TMPL_IF> /></td>
+ <td><input type="checkbox" name="starters__new" <TMPL_IF starters>CHECKED</TMPL_IF> /></td>
+ <td><input type="checkbox" name="followups__new" <TMPL_IF followups>CHECKED</TMPL_IF> /></td>
+</tr>
</table>
+
</div>
<p>
Modified: branches/db_changes/templates/notes.tmpl
===================================================================
--- branches/db_changes/templates/notes.tmpl 2005-03-25 08:45:02 UTC (rev 145)
+++ branches/db_changes/templates/notes.tmpl 2005-03-25 21:01:29 UTC (rev 146)
@@ -4,9 +4,26 @@
<TMPL_INCLUDE NAME="navigation.tmpl">
<TMPL_IF mypanok>
+<p>
Your subscriptions were successfully updated.
You can look at them here: <a href="/mypan/">subscription information</a>
+</p>
</TMPL_IF>
+<TMPL_IF no_such_pauseid>
+<p class="error">No such PAUSEID.</p>
+<p>
+Look at the <a href="/mypan/">subscription information</a> again.
+</p>
+</TMPL_IF>
+
+<TMPL_IF no_such_group>
+<p class="error">No such Distribution in our database.</p>
+<p>
+Look at the <a href="/mypan/">subscription information</a> again.
+</p>
+</TMPL_IF>
+
+
<TMPL_INCLUDE NAME="footer.tmpl">
More information about the Cpan-forum-commit
mailing list