From: Chris W. <la...@us...> - 2004-11-28 07:05:02
|
Update of /cvsroot/openinteract/OpenInteract2/pkg/comments/OpenInteract2/Action In directory sc8-pr-cvs1.sourceforge.net:/tmp/cvs-serv5931/OpenInteract2/Action Modified Files: Comments.pm Log Message: move all error/status messages to resource file; fix notification email template name; actually add the cookie to the header so we can remember email/name/url info; use CTX DateTime creation so we get the benefit of the configured timezone; cosmetic code cleanup; Index: Comments.pm =================================================================== RCS file: /cvsroot/openinteract/OpenInteract2/pkg/comments/OpenInteract2/Action/Comments.pm,v retrieving revision 1.6 retrieving revision 1.7 diff -C2 -d -r1.6 -r1.7 *** Comments.pm 16 Jun 2004 01:03:44 -0000 1.6 --- Comments.pm 28 Nov 2004 06:00:56 -0000 1.7 *************** *** 5,9 **** use strict; use base qw( OpenInteract2::Action ); - use DateTime; use HTML::Entities; use Log::Log4perl qw( get_logger ); --- 5,8 ---- *************** *** 30,34 **** $log->warn( "Cannot display summary: no object or ", "object class + ID given" ); ! return "No object or class/ID given for which to fetch a summary."; } --- 29,33 ---- $log->warn( "Cannot display summary: no object or ", "object class + ID given" ); ! return $self->_msg( 'comments.error.summary_data_missing' ); } *************** *** 43,49 **** $log->debug( "Fetching summary for '$obj_class: $obj_id'" ); my $summaries = eval { ! OpenInteract2::CommentSummary->fetch_group( ! { where => 'class = ? AND object_id = ?', ! value => [ $obj_class, scalar $obj_id ] }) }; if ( $@ ) { --- 42,49 ---- $log->debug( "Fetching summary for '$obj_class: $obj_id'" ); my $summaries = eval { ! OpenInteract2::CommentSummary->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $obj_class, scalar $obj_id ], ! }) }; if ( $@ ) { *************** *** 59,66 **** $log->is_info && $log->info( "No summary available, creating transient one" ); ! $summary = OpenInteract2::CommentSummary->new( ! { num_comments => 0, ! class => $obj_class, ! obj_id => $obj_id }); $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { --- 59,67 ---- $log->is_info && $log->info( "No summary available, creating transient one" ); ! $summary = OpenInteract2::CommentSummary->new({ ! num_comments => 0, ! class => $obj_class, ! obj_id => $obj_id ! }); $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { *************** *** 101,117 **** # ...but we pass 1-based figures to the template (how humane) ! my %params = ( lower_bound => $lower_bound + 1, ! upper_bound => $upper_bound + 1, ! page_num => $page_num, ! page_size => $page_size, ! num_comments => $request->param( 'num_comments' ) ); my $comments = eval { ! OpenInteract2::Comment->fetch_group( ! { limit => "$lower_bound,$upper_bound", ! order => 'posted_on DESC', ! column_group => 'summary' }) }; if ( $@ ) { ! $self->param_add( error_msg => "Failed to fetch comments: $@" ); $log->error( "Cannot fetch comments: $@" ); } --- 102,122 ---- # ...but we pass 1-based figures to the template (how humane) ! my %params = ( ! lower_bound => $lower_bound + 1, ! upper_bound => $upper_bound + 1, ! page_num => $page_num, ! page_size => $page_size, ! num_comments => $request->param( 'num_comments' ), ! ); my $comments = eval { ! OpenInteract2::Comment->fetch_group({ ! limit => "$lower_bound,$upper_bound", ! order => 'posted_on DESC', ! column_group => 'summary', ! }) }; if ( $@ ) { ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch_listing', "$@" ) ); $log->error( "Cannot fetch comments: $@" ); } *************** *** 161,186 **** unless ( $obj_class and $obj_id ) { $log->error( 'Class/object_id not given to find object' ); ! return "Insufficient data supplied to fetch comments by object."; } $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { $log->error( "Failed to fetch '$obj_class: $obj_id': $@" ); ! return "Failed to fetch object with supplied information. " . ! "Error logged."; } } ! my %params = ( object => $object, ! summary => $self->param( 'summary' ), ! standalone => $self->param( 'standalone' ) ); my $comments = eval { ! OpenInteract2::Comment->fetch_group( ! { where => 'class = ? and object_id = ?', ! value => [ ref $object, scalar( $object->id ) ], ! order => 'posted_on ASC' }) }; if ( $@ ) { $log->error( "Error fetching comments: $@" ); $self->param_add( ! error_msg => "Failed to fetch comments for listing: $@" ); } else { --- 166,194 ---- unless ( $obj_class and $obj_id ) { $log->error( 'Class/object_id not given to find object' ); ! return $self->_msg( 'comments.error.list_for_object_data_missing' ); } + $object = eval { $obj_class->fetch( $obj_id ) }; if ( $@ ) { $log->error( "Failed to fetch '$obj_class: $obj_id': $@" ); ! return $self->_msg( 'comments.error.cannot_fetch_object_for_listing' ); } } ! my %params = ( ! object => $object, ! summary => $self->param( 'summary' ), ! standalone => $self->param( 'standalone' ), ! ); my $comments = eval { ! OpenInteract2::Comment->fetch_group({ ! where => 'class = ? and object_id = ?', ! value => [ ref $object, scalar( $object->id ) ], ! order => 'posted_on ASC' ! }) }; if ( $@ ) { $log->error( "Error fetching comments: $@" ); $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch_by_object', "$@" ) ); } else { *************** *** 209,213 **** $log->error( "Error retrieving comment '$comment_id': $@" ); $self->param_add( ! error_msg => "Error fetching comment: $@" ); } if ( $comment ) { --- 217,221 ---- $log->error( "Error retrieving comment '$comment_id': $@" ); $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch', "$@" ) ); } if ( $comment ) { *************** *** 217,226 **** $log->error( "No comment found for given ID '$comment_id'" ); $self->param_add( ! error_msg => "No comment found for specified ID." ); } } else { $self->param_add( ! error_msg => "Cannot display comment without a comment ID." ); } --- 225,234 ---- $log->error( "No comment found for given ID '$comment_id'" ); $self->param_add( ! error_msg => $self->_msg( 'comments.error.not_found' ) ); } } else { $self->param_add( ! error_msg => $self->_msg( 'comments.error.no_id' ) ); } *************** *** 275,287 **** $object = eval { $obj_class->fetch( $comment->{object_id} ) }; if ( $@ ) { ! my $msg = "Cannot fetch object to which comment is attached: $@"; ! $self->param_add( error_msg => $msg ); $object = undef; } } else { ! my $msg = 'Cannot fetch object to which comment is attached: ' . ! 'no class specified in comment'; ! $self->param_add( error_msg => $msg ); } return $object; --- 283,294 ---- $object = eval { $obj_class->fetch( $comment->{object_id} ) }; if ( $@ ) { ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch_object', "$@" ) ); $object = undef; } } else { ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.no_class_for_object' ) ); } return $object; *************** *** 338,344 **** } ! # Stick in right now... ! $comment->{posted_on} = DateTime->now(); # Ensure URLs at least start with HTTP... --- 345,351 ---- } ! # Stick in right now (with timezone)... ! $comment->{posted_on} = CTX->create_date(); # Ensure URLs at least start with HTTP... *************** *** 355,359 **** # Escape any remaining HTMLisms ! my $pre_escaped = $comment->{content}; $comment->{content} = HTML::Entities::encode( $comment->{content} ); --- 362,369 ---- # Escape any remaining HTMLisms ! # ...but store the unescaped version for the re-editing (if this ! # is a preview) ! ! $self->param( pre_escaped => $comment->{content} ); $comment->{content} = HTML::Entities::encode( $comment->{content} ); *************** *** 385,395 **** } - $self->param( pre_escaped => $pre_escaped ); $self->param( comment => $comment ); $self->param( form_settings => \%form_settings ); if ( scalar @required_missing ) { ! my $msg = q{Data are required for the following fields: } . ! join( ', ', @required_missing ); $self->param_add( error_msg => $msg ); return $self->_show_editable; --- 395,403 ---- } $self->param( comment => $comment ); $self->param( form_settings => \%form_settings ); if ( scalar @required_missing ) { ! my $msg = $self->_msg( 'comments.error.data_missing', join( ', ', @required_missing ) ); $self->param_add( error_msg => $msg ); return $self->_show_editable; *************** *** 417,423 **** $self->param( 'default_cookie_name' ) || 'comment_info'; ! OpenInteract2::Cookie->create({ name => $cookie_name, ! value => $cookie_info, ! expires => '+6M' }); $log->is_info && $log->info( "Created 'remember' cookie with '$cookie_info'" ); --- 425,434 ---- $self->param( 'default_cookie_name' ) || 'comment_info'; ! OpenInteract2::Cookie->create({ ! name => $cookie_name, ! value => $cookie_info, ! expires => '+6M', ! HEADER => 'yes', ! }); $log->is_info && $log->info( "Created 'remember' cookie with '$cookie_info'" ); *************** *** 427,434 **** if ( $@ ) { $log->error( "Failed to add comment: $@" ); ! $self->param_add( error_msg => "Error adding comment: $@" ); } else { ! $self->param_add( status_msg => "Comment successfully added." ); # These are used for the listing page we go to next... --- 438,447 ---- if ( $@ ) { $log->error( "Failed to add comment: $@" ); ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_add', "$@" ) ); } else { ! $self->param_add( ! status_msg => $self->_msg( 'comments.status.add_ok' ) ); # These are used for the listing page we go to next... *************** *** 488,495 **** eval { OpenInteract2::CommentNotify->new({ ! class => $comment->{class}, ! object_id => $comment->{object_id}, ! name => $name, ! email => lc $email })->save() }; if ( $@ ) { --- 501,509 ---- eval { OpenInteract2::CommentNotify->new({ ! class => $comment->{class}, ! object_id => $comment->{object_id}, ! name => $name, ! email => lc $email ! })->save() }; if ( $@ ) { *************** *** 539,545 **** $log->info( "Posted wants to be notified but provided a bad ", "email address: '$comment->{poster_email}'" ); ! return join( '', 'Could not add notification since the email ' . ! "address you gave ($comment->{poster_email}) ", ! "seems to be invalid. Sorry." ); } --- 553,558 ---- $log->info( "Posted wants to be notified but provided a bad ", "email address: '$comment->{poster_email}'" ); ! return $self->_msg( 'comments.error.cannot_add_notify_bad_email', ! $comment->{poster_email} ); } *************** *** 549,561 **** my $notes = eval { OpenInteract2::CommentNotify->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $comment->{class}, ! $comment->{object_id} ] }) }; if ( $@ ) { $log->error( "Error fetching notifications for: ", "'$comment->{class}: $comment->{object_id}': $@" ); ! return 'Failed to fetch existing notifications for dupe check, ' . ! 'so I could not add yours.'; } --- 562,573 ---- my $notes = eval { OpenInteract2::CommentNotify->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $comment->{class}, $comment->{object_id} ], ! }) }; if ( $@ ) { $log->error( "Error fetching notifications for: ", "'$comment->{class}: $comment->{object_id}': $@" ); ! return $self->_msg( 'comments.error.cannot_add_notify_error_dupe_check' ); } *************** *** 564,583 **** $log->is_info && $log->info( "No notification added: already exists in thread" ); ! return 'Did not add a notification to this thread since one ' . ! 'already exists for the given email address.'; } eval { OpenInteract2::CommentNotify->new({ ! class => $comment->{class}, ! object_id => $comment->{object_id}, ! name => $comment->{poster_name}, ! email => lc $comment->{poster_email} })->save() }; if ( $@ ) { $log->error( "Failed to save notification: $@" ); ! return 'Your notification entry addition failed, sorry.'; } ! return 'Your notification entry added successfully.'; } --- 576,595 ---- $log->is_info && $log->info( "No notification added: already exists in thread" ); ! return $self->_msg( 'comments.error.cannot_add_notify_is_dupe' ); } eval { OpenInteract2::CommentNotify->new({ ! class => $comment->{class}, ! object_id => $comment->{object_id}, ! name => $comment->{poster_name}, ! email => lc $comment->{poster_email} ! })->save() }; if ( $@ ) { $log->error( "Failed to save notification: $@" ); ! return $self->_msg( 'comments.error.cannot_add_notify_persist', "$@" ); } ! return $self->_msg( 'comments.status.add_notify_ok' ); } *************** *** 587,594 **** my $notes = eval { ! OpenInteract2::CommentNotify->fetch_group( ! { where => 'class = ? AND object_id = ?', ! value => [ $comment->{class}, ! $comment->{object_id} ] }) }; if ( $@ ) { --- 599,606 ---- my $notes = eval { ! OpenInteract2::CommentNotify->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $comment->{class}, $comment->{object_id} ], ! }) }; if ( $@ ) { *************** *** 609,613 **** server_name => $server_name ); my $message = $self->generate_content( ! \%params, { name => 'comment::notification_email' } ); my $subject = $self->_create_email_subject; my $success = 0; --- 621,625 ---- server_name => $server_name ); my $message = $self->generate_content( ! \%params, { name => 'comments::notification_email' }); my $subject = $self->_create_email_subject; my $success = 0; *************** *** 621,629 **** : $note->{email}; eval { ! OpenInteract2::Util->send_email( ! { to => $to, ! from => $from_address, ! subject => $subject, ! message => $message }) }; if ( $@ ) { --- 633,642 ---- : $note->{email}; eval { ! OpenInteract2::Util->send_email({ ! to => $to, ! from => $from_address, ! subject => $subject, ! message => $message ! }) }; if ( $@ ) { *************** *** 679,696 **** $params{notes} = eval { ! OpenInteract2::CommentNotify->fetch_group( ! { where => 'class = ? AND object_id = ?', ! value => [ $obj_class, $obj_id ] }) }; if ( $@ ) { $log->error( "Error fetching notifications for ", "[$obj_class: $obj_id]: $@" ); ! $self->param_add( error_msg => "Failed to fetch notifications: $@" ); } else { my $summaries = eval { ! OpenInteract2::CommentSummary->fetch_group( ! { where => 'class = ? AND object_id = ?', ! value => [ $obj_class, $obj_id ] }) }; $params{summary} = $summaries->[0]; --- 692,712 ---- $params{notes} = eval { ! OpenInteract2::CommentNotify->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $obj_class, $obj_id ] ! }) }; if ( $@ ) { $log->error( "Error fetching notifications for ", "[$obj_class: $obj_id]: $@" ); ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch_notify', "$@" ) ); } else { my $summaries = eval { ! OpenInteract2::CommentSummary->fetch_group({ ! where => 'class = ? AND object_id = ?', ! value => [ $obj_class, $obj_id ] ! }) }; $params{summary} = $summaries->[0]; *************** *** 707,716 **** my %params = (); my $comments = eval { ! OpenInteract2::Comment->fetch_group({ limit => $recent_num, ! order => 'posted_on DESC', ! column_group => 'summary' }) }; if ( $@ ) { ! $self->param_add( error_msg => "Failed to get recent comments: $@" ); } else { --- 723,735 ---- my %params = (); my $comments = eval { ! OpenInteract2::Comment->fetch_group({ ! limit => $recent_num, ! order => 'posted_on DESC', ! column_group => 'summary', ! }) }; if ( $@ ) { ! $self->param_add( ! error_msg => $self->_msg( 'comments.error.cannot_fetch_recent', "$@" ) ); } else { |