Changeset 406 for veekun/trunk/lib/Vee/Controller/Forum/Create.pm
- Timestamp:
- 02/08/08 02:44:39 (2 years ago)
- Files:
-
- 1 modified
-
veekun/trunk/lib/Vee/Controller/Forum/Create.pm (modified) (13 diffs)
Legend:
- Unmodified
- Added
- Removed
-
veekun/trunk/lib/Vee/Controller/Forum/Create.pm
r384 r406 50 50 51 51 # 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/; 53 53 $c->vee_abort('No thread id specified. This should not happen. Sorry?') unless $c->req->params->{id}; 54 54 … … 60 60 } 61 61 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} ); 63 63 if (@bbcode_errors) { 64 64 $c->vee_abort("Your post contains invalid bbcode. Please go back and fix it."); … … 73 73 # TODO: apply this to thread creation too? not as common.. and merge as well? 74 74 my $last_post = $c->model('DBIC::Posts')->search({ 75 thread id => $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} }, 77 77 }, { 78 order_by => 'time DESC',78 order_by => 'time DESC', 79 79 })->single; 80 80 81 81 my $post; 82 82 # only do merging/prevention if the last post is this user's 83 if ($last_post and $last_post->user id == $c->user->obj->id and $last_post->flags !~ /deleted/) {84 if ($last_post-> messageeq $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) { 85 85 $c->vee_abort("You have already posted that message recently."); 86 86 } … … 90 90 $post = $c->model('DBIC')->schema->txn_do( sub { 91 91 my $edit = $c->model('DBIC::Edits')->create({ 92 post id => $last_post->id,93 user id => $c->user->obj->id,94 time => time,95 old message => $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, 96 96 }); 97 $last_post-> message(98 $last_post-> message.97 $last_post->content( 98 $last_post->content . 99 99 "\n[hr][i]Automerged:[/i]\n" . 100 100 $parsed_message 101 101 ); 102 $last_post->last editid( $edit->id );102 $last_post->last_edit_id( $edit->id ); 103 103 $last_post->time( time ); 104 104 $last_post->update; 105 105 106 $thread->last postid( $last_post->id );107 $thread->last time( time );106 $thread->last_post_id( $last_post->id ); 107 $thread->last_post_time( time ); 108 108 $thread->update; 109 109 … … 114 114 $post = $c->model('DBIC')->schema->txn_do( sub { 115 115 my $post = $c->model('DBIC::Posts')->create({ 116 thread id => $thread->id,117 user id => $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, 121 121 }); 122 122 # update thread's last-post stats 123 $thread->last postid( $post->id );124 $thread->last time( time );125 $thread->post ct( $thread->postct + 1 );123 $thread->last_post_id( $post->id ); 124 $thread->last_post_time( time ); 125 $thread->post_count( $thread->post_count + 1 ); 126 126 $thread->update; 127 127 # update forum's last-post stats 128 $thread->forum->last postid( $post->id );129 $thread->forum->post ct( $thread->forum->postct + 1 );128 $thread->forum->last_post_id( $post->id ); 129 $thread->forum->post_count( $thread->forum->post_count + 1 ); 130 130 $thread->forum->update; 131 131 # update user's postcount 132 $c->user->obj->post ct( $c->user->postct + 1 );132 $c->user->obj->post_count( $c->user->post_count + 1 ); 133 133 $c->user->obj->update; 134 134 return $post; … … 149 149 my $s = $c->stash; 150 150 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} ); 152 152 if (@bbcode_errors) { 153 153 $c->vee_abort("Your post contains invalid bbcode. Please go back and fix it."); … … 156 156 157 157 my $rows = $c->site_opts->{page_sizes}{posts_preview}; 158 my $offset = $c->model('DBIC::Posts')->count({ thread id => $thread->id }, { order_by => 'me.time ASC' } );158 my $offset = $c->model('DBIC::Posts')->count({ thread_id => $thread->id }, { order_by => 'me.time ASC' } ); 159 159 $offset = $offset - $rows; 160 160 161 my $posts_rs = $c->model('DBIC::Posts')->search({ thread id => $thread->id }, {161 my $posts_rs = $c->model('DBIC::Posts')->search({ thread_id => $thread->id }, { 162 162 order_by => 'me.time ASC', 163 163 offset => $offset, … … 167 167 # form generation stuff 168 168 my $reply_fields = { 169 message=> { type => 'textarea', rows => '10', cols => '100' },169 content => { type => 'textarea', rows => '10', cols => '100' }, 170 170 id => { type => 'hidden' }, 171 171 }; … … 207 207 208 208 # 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/; 210 210 $c->vee_abort("You must enter a subject.") unless $c->req->params->{subject} =~ /\S/; 211 211 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} ); 213 213 if (@bbcode_errors) { 214 214 $c->detach('thread_preview'); … … 229 229 my $thread = $c->model('DBIC')->schema->txn_do( sub { 230 230 my $thread = $c->model('DBIC::Threads')->create({ 231 forum id=> $forum->id,232 subject => $subject,233 first postid=> 0,234 last postid=> 0,235 last time=> time,236 post ct=> 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, 238 238 }); 239 239 # create the post 240 240 my $post = $c->model('DBIC::Posts')->create({ 241 thread id => $thread->id,242 user id => $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 ), 246 246 }); 247 247 # update thread's last-post stats 248 $thread->first postid( $post->id );249 $thread->last postid( $post->id );248 $thread->first_post_id( $post->id ); 249 $thread->last_post_id( $post->id ); 250 250 $thread->update; 251 251 # update forum's last-post stats 252 $forum->last postid( $post->id );253 $forum->post ct( $forum->postct + 1 );254 $forum->thread ct( $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 ); 255 255 $forum->update; 256 256 # update user's postcount 257 $c->user->obj->post ct( $c->user->postct + 1 );257 $c->user->obj->post_count( $c->user->post_count + 1 ); 258 258 $c->user->obj->update; 259 259 return $thread; … … 275 275 my $subject = $c->req->params->{subject}; 276 276 my $blurb = $c->req->params->{blurb}; 277 my $ message = $c->req->params->{message};277 my $content = $c->req->params->{content}; 278 278 my $forum = $c->model('DBIC::Forums')->find( $c->req->params->{id} ) 279 279 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?'); … … 283 283 } 284 284 285 my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode( $message);285 my ($parsed_message, @bbcode_errors) = Vee::BBCode::validate_bbcode($content); 286 286 if (@bbcode_errors) { 287 287 $c->vee_abort("Your post contains invalid bbcode. Please fix it."); … … 290 290 # form generation stuff 291 291 my $reply_fields = { 292 message=> { type => 'textarea', rows => '10', cols => '100' },292 content => { type => 'textarea', rows => '10', cols => '100' }, 293 293 id => { type => 'hidden' }, 294 294 subject => { type => 'text', maxlength => 48 },
