[Cpan-forum-commit] rev 174 - in trunk: . bin lib/CPAN schema

svn at pti.co.il svn at pti.co.il
Sat Aug 26 16:01:58 IDT 2006


Author: gabor
Date: 2006-08-26 16:01:57 +0300 (Sat, 26 Aug 2006)
New Revision: 174

Modified:
   trunk/
   trunk/Build.PL
   trunk/bin/populate.pl
   trunk/bin/upgrade_to_0_12.pl
   trunk/lib/CPAN/Forum.pm
   trunk/schema/schema.sql
Log:
replace the username with the uid in the posts



Property changes on: trunk
___________________________________________________________________
Name: svk:merge
   - 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:11001
   + 8c4c90e1-83eb-0310-96eb-e7cb62807872:/local/cpan-forum:11017

Modified: trunk/Build.PL
===================================================================
--- trunk/Build.PL	2006-08-25 15:15:55 UTC (rev 173)
+++ trunk/Build.PL	2006-08-26 13:01:57 UTC (rev 174)
@@ -31,7 +31,7 @@
         'DBD::SQLite'                           => 0.31,
         'Class::DBI'                            => 0,  # It was complaining: ERROR: Version v3.0.14 of Class::DBI is installed, but we need version >= 0.96
 #       'Crypt::SSLeay'                         => 0,  # needed for http access to PAUSE
-        'Parse::CPAN::Packages'                 => 0,  # for populating and maybe also later ?
+        'Parse::CPAN::Packages'                 => '2.26',  # for populating and maybe also later ?
         'LWP::Simple'                           => 0,  # for populate
         'XML::RSS::SimpleGen'                   => 0,  # for, well RSS generation
         'Mail::Sendmail'                        => 0,  

Modified: trunk/bin/populate.pl
===================================================================
--- trunk/bin/populate.pl	2006-08-25 15:15:55 UTC (rev 173)
+++ trunk/bin/populate.pl	2006-08-26 13:01:57 UTC (rev 174)
@@ -64,7 +64,7 @@
 print "Processing $opts{source} file, adding distros to database, will take a few minutes\n";
 print "Go get a beer\n";
 my $p = Parse::CPAN::Packages->new($opts{source});
-my @distributions = $p->distributions;
+;
 
 my %message = (
     version => "",
@@ -73,17 +73,19 @@
 );
 
 LINE:
-foreach my $d (@distributions) {
+my $cnt;
+foreach my $d ($p->latest_distributions) {
+    $cnt++;
 
     # skip scripts
     if (not $d->prefix or $d->prefix =~ m{^\w/\w\w/\w+/scripts/}) {
-        warn "no prefix line $.\n";
+        warn "no prefix line $cnt\n";
         next LINE;
     }
 
     my $name        = $d->dist;
     if (not $name) {
-        warn "No name: line: $. prefix:" . $d->prefix . "\n";
+        warn "No name: line: $cnt prefix:" . $d->prefix . "\n";
         next LINE;
     }
     

Modified: trunk/bin/upgrade_to_0_12.pl
===================================================================
--- trunk/bin/upgrade_to_0_12.pl	2006-08-25 15:15:55 UTC (rev 173)
+++ trunk/bin/upgrade_to_0_12.pl	2006-08-26 13:01:57 UTC (rev 174)
@@ -5,14 +5,20 @@
 use lib "lib";
 
 use File::Copy qw(move copy);
+use Getopt::Long qw(GetOptions);
 use DBI;
 use Cwd qw(cwd);
 
 # tell application db is closed...
 
+my %opts;
+GetOptions(\%opts, "dir=s") or die;
+die "$0 --dir DB_DIR\n" 
+    if not $opts{dir};
+
 my $time   = time;
 my $failed;
-my $db_file = 'db/forum.db';
+my $db_file = "$opts{dir}/forum.db";
 my $backup = $db_file . "_$time";
 print "Backup: $backup\n";
 copy $db_file, $backup;
@@ -28,7 +34,29 @@
     $dbh->do($sql);
 }
 #$failed = 1;
+{
+    my $sth_select = $dbh->prepare("SELECT id, username FROM users");
+    $sth_select->execute();
+    my %uid_of;
+    while (my $h = $sth_select->fetchrow_hashref('NAME_lc')) {
+        $uid_of{ $h->{username} } = $h->{id};
+    }
 
+    my $sth_get_posts = $dbh->prepare("SELECT * FROM posts_old ORDER BY id");
+    my $sth_insert_post = $dbh->prepare("INSERT INTO posts VALUES(?,?,?,?,?,?,?,?,?)");
+
+    $sth_get_posts->execute;
+    while (my $h = $sth_get_posts->fetchrow_hashref('NAME_lc')) {
+        $sth_insert_post->execute(
+                $h->{id}, $h->{gid}, $uid_of{ $h->{uid} },
+                $h->{parent}, $h->{thread}, $h->{hidden}, $h->{subject},
+                $h->{text}, $h->{date});
+    }
+    $dbh->do("DROP TABLE posts_old");
+}
+
+$dbh->do("VACUUM");
+
 if ($failed) {
 	print "Upgraded failed.\n";
     unlink $db_file;
@@ -61,4 +89,17 @@
 );
 
 DROP TABLE sessions;
+ALTER TABLE posts RENAME TO posts_old;
+CREATE TABLE posts (
+			id               INTEGER PRIMARY KEY,
+			gid              INTEGER NOT NULL,
+			uid              INTEGER NOT NULL,
+			parent           INTEGER,
+			thread           INTEGER,
+			hidden           BOOLEAN,
+			subject          VARCHAR(255) NOT NULL,
+			text             VARCHAR(100000) NOT NULL,
+			date             TIMESTAMP
+);
 
+

Modified: trunk/lib/CPAN/Forum.pm
===================================================================
--- trunk/lib/CPAN/Forum.pm	2006-08-25 15:15:55 UTC (rev 173)
+++ trunk/lib/CPAN/Forum.pm	2006-08-26 13:01:57 UTC (rev 174)
@@ -252,15 +252,16 @@
 personal infromation:
     update users set email = 'test_' || id || '@cpanforum.com' where id in(select id from users);
     update users set password = 'testpw';
+    update users set username = 'test_' || id where id in(select id from users);
+    update users set fname='', lname='';
 
-    -- maybe even change the usernames? but I think the ids are already public
-    -- so it won't bring any additional privacy or security
-
     delete from sessions;
 
     delete from configure;  -- ???
     delete user_in_group;   -- ???
 
+    update posts set uid=myuid where (select users.uid myuid from users where posts.uid=users.username;
+    select posts.id pid, users.id uid, users.username from posts, users where posts.uid=users.username;
 
 
 Removed the use of CPAN::Forum::Build - need to see what was it doing and
@@ -526,6 +527,7 @@
     $self->log->debug("Cookie received: "  . ($self->query->cookie($cookiename) || "") );
     CGI::Session->name($cookiename);
     $self->session_config(
+        #CGI_SESSION_OPTIONS => [ "driver:File", $self->query, {Directory => "/tmp"}],
         #CGI_SESSION_OPTIONS => [ "driver:SQLite", $self->query, {Handle => $dbh}],
         COOKIE_PARAMS       => {
                 -expires => '+24h',
@@ -759,7 +761,7 @@
             thread_count => $thread_count-1,
             #date         => strftime("%e/%b", localtime $post->date),
             date         => scalar localtime $post->date,
-            postername   => $post->uid,
+            postername   => $post->uid->username,
             };
     }
     #@resp = reverse @resp if $to; # Otherwise we fetched in DESC order
@@ -1413,9 +1415,14 @@
     }
 
     my $pid;
+    my $username = $self->session->param("username");
+    my ($user) = CPAN::Forum::Users->search({ username => $username });
+    if (not $user) {
+        return $self->internal_error("Unknonw username: $username");
+    }
     eval {
         my $post = CPAN::Forum::Posts->create({
-            uid     => $self->session->param("username"),
+            uid     => $user->id,
             gid     => $parent_post ? $parent_post->gid : $q->param("new_group_id"),
             subject => $q->param("new_subject"),
             text    => $new_text,
@@ -1452,7 +1459,7 @@
     my @responses = map {{id => $_->id}} CPAN::Forum::Posts->search(parent => $post->id);
 
     my %post = (
-        postername  => $post->uid,
+        postername  => $post->uid->username,
         date        => _post_date($post->date),
         parentid    => $post->parent,
         responses   => \@responses,
@@ -2219,9 +2226,9 @@
     # and this reveals the e-mail of the administrator. not a good idea I guess.
     $rss->webmaster($admin->email);
 
-    my $prefix = "";
     while (my $post = $it->next() and $limit--) {
-        $rss->item($url. "posts/" . $post->id(), $prefix . $post->subject); # TODO _subject_escape ?
+        my $title = sprintf "[%s] %s", $post->gid->name, $post->subject;
+        $rss->item($url. "posts/" . $post->id(), $title); # TODO _subject_escape ?
     }
 #   $rss->save("file.rss");
 
@@ -2395,6 +2402,7 @@
 sub _my_sendmail {
     my ($self, @args) = @_;
 
+    return if $ENV{NO_CPAN_FORUM_MAIL};
     # for testing
     if (defined &_test_my_sendmail) {
         $self->_test_my_sendmail(@_);

Modified: trunk/schema/schema.sql
===================================================================
--- trunk/schema/schema.sql	2006-08-25 15:15:55 UTC (rev 173)
+++ trunk/schema/schema.sql	2006-08-26 13:01:57 UTC (rev 174)
@@ -136,4 +136,7 @@
 			,FOREIGN KEY (uid) REFERENCES users(id)
 );
 
+CREATE UNIQUE INDEX groups_name ON groups (name);
+CREATE INDEX posts_thread ON posts (thread);
+CREATE INDEX posts_gid ON posts (gid);
 



More information about the Cpan-forum-commit mailing list