Show
Ignore:
Timestamp:
02/08/08 02:44:39 (2 years ago)
Author:
eevee
Message:

Database refactoring. Renamed columns and tables to be more consistent and more readable. (#58)

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • veekun/trunk/lib/Vee/Controller/Forum/Create.pm

    r384 r406  
    5050 
    5151    # TODO: make these redir to an actual post page when one exists 
    52     $c->vee_abort('Please enter a message.') unless $c->req->params->{message} =~ /\S/; 
     52    $c->vee_abort('Please enter a message.') unless $c->req->params->{content} =~ /\S/; 
    5353    $c->vee_abort('No thread id specified.  This should not happen.  Sorry?') unless $c->req->params->{id}; 
    5454 
     
    6060    } 
    6161 
    62     my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{message} ); 
     62    my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{content} ); 
    6363    if (@bbcode_errors) { 
    6464        $c->vee_abort("Your post contains invalid bbcode.  Please go back and fix it."); 
     
    7373    # TODO: apply this to thread creation too?  not as common..  and merge as well? 
    7474    my $last_post = $c->model('DBIC::Posts')->search({ 
    75         threadid => $thread->id, 
    76         time     => { '>=', time - $c->site_opts->{post_automerge_time} }, 
     75        thread_id => $thread->id, 
     76        time      => { '>=', time - $c->site_opts->{post_automerge_time} }, 
    7777    }, { 
    78         order_by => 'time DESC', 
     78        order_by  => 'time DESC', 
    7979    })->single; 
    8080 
    8181    my $post; 
    8282    # only do merging/prevention if the last post is this user's         
    83     if ($last_post and $last_post->userid == $c->user->obj->id and $last_post->flags !~ /deleted/) { 
    84         if ($last_post->message eq $parsed_message) { 
     83    if ($last_post and $last_post->user_id == $c->user->obj->id and $last_post->flags !~ /deleted/) { 
     84        if ($last_post->content eq $parsed_message) { 
    8585            $c->vee_abort("You have already posted that message recently."); 
    8686        } 
     
    9090        $post = $c->model('DBIC')->schema->txn_do( sub { 
    9191            my $edit = $c->model('DBIC::Edits')->create({ 
    92                 postid     => $last_post->id, 
    93                 userid     => $c->user->obj->id, 
    94                 time       => time, 
    95                 oldmessage => $last_post->message, 
     92                post_id     => $last_post->id, 
     93                user_id     => $c->user->obj->id, 
     94                time        => time, 
     95                old_content => $last_post->content, 
    9696            }); 
    97             $last_post->message( 
    98                 $last_post->message . 
     97            $last_post->content( 
     98                $last_post->content . 
    9999                "\n[hr][i]Automerged:[/i]\n" . 
    100100                $parsed_message 
    101101            ); 
    102             $last_post->lasteditid( $edit->id ); 
     102            $last_post->last_edit_id( $edit->id ); 
    103103            $last_post->time( time ); 
    104104            $last_post->update; 
    105105 
    106             $thread->lastpostid( $last_post->id ); 
    107             $thread->lasttime( time ); 
     106            $thread->last_post_id( $last_post->id ); 
     107            $thread->last_post_time( time ); 
    108108            $thread->update; 
    109109 
     
    114114        $post = $c->model('DBIC')->schema->txn_do( sub { 
    115115            my $post = $c->model('DBIC::Posts')->create({ 
    116                 threadid => $thread->id, 
    117                 userid   => $c->user->obj->id, 
    118                 time     => time, 
    119                 format   => 'bbcode', 
    120                 message  => $parsed_message, 
     116                thread_id => $thread->id, 
     117                user_id   => $c->user->obj->id, 
     118                time      => time, 
     119                format    => 'bbcode', 
     120                content   => $parsed_message, 
    121121            }); 
    122122            # update thread's last-post stats 
    123             $thread->lastpostid( $post->id ); 
    124             $thread->lasttime( time ); 
    125             $thread->postct( $thread->postct + 1 ); 
     123            $thread->last_post_id( $post->id ); 
     124            $thread->last_post_time( time ); 
     125            $thread->post_count( $thread->post_count + 1 ); 
    126126            $thread->update; 
    127127            # update forum's last-post stats 
    128             $thread->forum->lastpostid( $post->id ); 
    129             $thread->forum->postct( $thread->forum->postct + 1 ); 
     128            $thread->forum->last_post_id( $post->id ); 
     129            $thread->forum->post_count( $thread->forum->post_count + 1 ); 
    130130            $thread->forum->update; 
    131131            # update user's postcount 
    132             $c->user->obj->postct( $c->user->postct + 1 ); 
     132            $c->user->obj->post_count( $c->user->post_count + 1 ); 
    133133            $c->user->obj->update; 
    134134            return $post; 
     
    149149    my $s = $c->stash; 
    150150 
    151     my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{message} ); 
     151    my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{content} ); 
    152152    if (@bbcode_errors) { 
    153153        $c->vee_abort("Your post contains invalid bbcode.  Please go back and fix it."); 
     
    156156     
    157157    my $rows = $c->site_opts->{page_sizes}{posts_preview}; 
    158     my $offset = $c->model('DBIC::Posts')->count({ threadid => $thread->id }, { order_by => 'me.time ASC' } ); 
     158    my $offset = $c->model('DBIC::Posts')->count({ thread_id => $thread->id }, { order_by => 'me.time ASC' } ); 
    159159    $offset = $offset - $rows; 
    160160 
    161     my $posts_rs = $c->model('DBIC::Posts')->search({ threadid => $thread->id }, { 
     161    my $posts_rs = $c->model('DBIC::Posts')->search({ thread_id => $thread->id }, { 
    162162        order_by => 'me.time ASC', 
    163163        offset   => $offset, 
     
    167167    # form generation stuff 
    168168    my $reply_fields = { 
    169         message => { type => 'textarea', rows => '10', cols => '100' }, 
     169        content => { type => 'textarea', rows => '10', cols => '100' }, 
    170170        id => { type => 'hidden' }, 
    171171    }; 
     
    207207 
    208208    # TODO: make these redir to an actual post page when one exists 
    209     $c->vee_abort("You must enter a message.") unless $c->req->params->{message} =~ /\S/; 
     209    $c->vee_abort("You must enter a message.") unless $c->req->params->{content} =~ /\S/; 
    210210    $c->vee_abort("You must enter a subject.") unless $c->req->params->{subject} =~ /\S/; 
    211211     
    212     my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{message} ); 
     212    my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $c->req->params->{content} ); 
    213213    if (@bbcode_errors) { 
    214214        $c->detach('thread_preview'); 
     
    229229    my $thread = $c->model('DBIC')->schema->txn_do( sub { 
    230230        my $thread = $c->model('DBIC::Threads')->create({ 
    231             forumid     => $forum->id, 
    232             subject     => $subject, 
    233             firstpostid => 0, 
    234             lastpostid  => 0, 
    235             lasttime    => time, 
    236             postct      => 1, 
    237             blurb       => $blurb, 
     231            forum_id       => $forum->id, 
     232            subject        => $subject, 
     233            first_post_id => 0, 
     234            last_post_id   => 0, 
     235            last_post_time => time, 
     236            post_count     => 1, 
     237            blurb          => $blurb, 
    238238        }); 
    239239        # create the post 
    240240        my $post = $c->model('DBIC::Posts')->create({ 
    241             threadid => $thread->id, 
    242             userid   => $c->user->obj->id, 
    243             time     => time, 
    244             format   => 'bbcode', 
    245             message  => Vee::Utils::fix_newlines( $parsed_message ), 
     241            thread_id => $thread->id, 
     242            user_id   => $c->user->obj->id, 
     243            time      => time, 
     244            format    => 'bbcode', 
     245            content   => Vee::Utils::fix_newlines( $parsed_message ), 
    246246        }); 
    247247        # update thread's last-post stats 
    248         $thread->firstpostid( $post->id ); 
    249         $thread->lastpostid( $post->id ); 
     248        $thread->first_post_id( $post->id ); 
     249        $thread->last_post_id( $post->id ); 
    250250        $thread->update; 
    251251        # update forum's last-post stats 
    252         $forum->lastpostid( $post->id ); 
    253         $forum->postct( $forum->postct + 1 ); 
    254         $forum->threadct( $forum->threadct + 1 ); 
     252        $forum->last_post_id( $post->id ); 
     253        $forum->post_count( $forum->post_count + 1 ); 
     254        $forum->thread_count( $forum->thread_count + 1 ); 
    255255        $forum->update; 
    256256        # update user's postcount 
    257         $c->user->obj->postct( $c->user->postct + 1 ); 
     257        $c->user->obj->post_count( $c->user->post_count + 1 ); 
    258258        $c->user->obj->update; 
    259259        return $thread; 
     
    275275    my $subject = $c->req->params->{subject}; 
    276276    my $blurb   = $c->req->params->{blurb}; 
    277     my $message = $c->req->params->{message}; 
     277    my $content = $c->req->params->{content}; 
    278278    my $forum = $c->model('DBIC::Forums')->find( $c->req->params->{id} ) 
    279279        or $c->vee_abort('There is no forum with an id of ', $c->req->params->{id}, '.  It may have been deleted while you were typing?'); 
     
    283283    } 
    284284     
    285     my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $message ); 
     285    my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode($content); 
    286286    if (@bbcode_errors) { 
    287287        $c->vee_abort("Your post contains invalid bbcode.  Please fix it."); 
     
    290290    # form generation stuff 
    291291    my $reply_fields = { 
    292         message => { type => 'textarea', rows => '10', cols => '100' }, 
     292        content => { type => 'textarea', rows => '10', cols => '100' }, 
    293293        id => { type => 'hidden' }, 
    294294        subject => { type => 'text', maxlength => 48 },