Re: [Perl-workflow-devel] patch for passing in date format
Brought to you by:
jonasbn
|
From: jonasbn <jo...@gm...> - 2007-08-12 11:27:59
|
Hi Jim,
Thanks very much for the patch.
I made a branch in an attempt to apply it, so after some attempts I
got around to actual patching (I should not work when I am tired),
anyway I am experiencing some problems with your patch, which I
attempt to apply the following way:
hyperstation ~/Desktop/Workflow-0.28
% patch -p2 <dateformat.patch
patching file lib/Workflow/Action/InputField.pm
Hunk #1 FAILED at 17.
1 out of 1 hunk FAILED -- saving rejects to file lib/Workflow/Action/
InputField.pm.rej
patching file lib/Workflow/Persister/DBI.pm
Hunk #1 FAILED at 17.
Hunk #2 FAILED at 47.
Hunk #3 FAILED at 188.
Hunk #4 FAILED at 254.
Hunk #5 FAILED at 268.
Hunk #6 FAILED at 298.
Hunk #7 FAILED at 373.
Hunk #8 FAILED at 535.
Hunk #9 succeeded at 713 with fuzz 2.
8 out of 9 hunks FAILED -- saving rejects to file lib/Workflow/
Persister/DBI.pm.rej
patching file t/TestUtil.pm
Hunk #1 FAILED at 95.
1 out of 1 hunk FAILED -- saving rejects to file t/TestUtil.pm.rej
patching file t/persister_dbi.t
Hunk #1 FAILED at 5.
Hunk #2 FAILED at 18.
Hunk #3 FAILED at 25.
Hunk #4 FAILED at 38.
Hunk #5 FAILED at 56.
Hunk #6 FAILED at 64.
Hunk #7 FAILED at 95.
Hunk #8 FAILED at 106.
8 out of 8 hunks FAILED -- saving rejects to file t/persister_dbi.t.rej
hyperstation ~/Desktop/Workflow-0.28
I went away from the branch and attempted to work on a unpacked
release tar-ball instead, but I get the same errors.
I had to correct a few lines in your patch since some of the lines
were broken into two lines.
-my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d
%H:%M' );
Should be one line I believe. If you can send me the same patch as an
attachment it would be appreciated.
Any other suggestions or advice?
jonasbn
--
AIM: BjonasN Gtalk: jo...@gm...
ICQ: 62401545 MSN: jo...@io...
On 10/08/2007, at 19.13, Jim Brandt wrote:
> Hello,
>
> Pasted below is a patch that allows you to pass in a date format for
> Persister::DBI. A few notes:
>
> * It perpetuates the issue I brought up with subclassing I mentioned
> before since you need to set up date_format and parser in your own
> init
> if you subclass Persister::DBI and don't call SUPER::init.
>
> * I think a took care of a few warnings from the TODO:
>
> - Eliminate warnings from DBD::Mock
>
> should be fixed
>
> - Investigate failings tests in t/persister_dbi.t,
>
> Yes, this was related to dates. $NOW was set at the top of the file
> and
> then used throughout, so the time could be off by the end of the file.
> This was easy to see in the debugger if you stopped the program for a
> while and then continued.
>
> I improved it by putting the actual code in each call when the date is
> needed, but I think this issue can still come up if the second flips
> while running. It should be less likely now.
>
> I didn't update any versions. Let me know if you can use the diff for
> some reason.
>
> Thanks,
> Jim
>
>
>
> diff -urX workflow.exclude
> orig/Workflow-0.28/lib/Workflow/Action/InputField.pm
> working/Workflow-0.28/lib/Workflow/Action/InputField.pm
> --- orig/Workflow-0.28/lib/Workflow/Action/InputField.pm 2007-07-06
> 10:43:11.000000000 -0400
> +++ working/Workflow-0.28/lib/Workflow/Action/InputField.pm 2007-08-10
> 11:35:40.000000000 -0400
> @@ -17,7 +17,8 @@
> sub new {
> my ( $class, $params ) = @_;
> my $log = get_logger();
> - $log->debug( "Instantiating new field '$params->{name}'" );
> + $log->debug( "Instantiating new field '$params->{name}'" )
> + if $params->{name};
>
> my $self = bless( {}, $class );
>
> diff -urX workflow.exclude
> orig/Workflow-0.28/lib/Workflow/Persister/DBI.pm
> working/Workflow-0.28/lib/Workflow/Persister/DBI.pm
> --- orig/Workflow-0.28/lib/Workflow/Persister/DBI.pm 2007-07-06
> 10:43:11.000000000 -0400
> +++ working/Workflow-0.28/lib/Workflow/Persister/DBI.pm 2007-08-10
> 12:49:31.000000000 -0400
> @@ -17,11 +17,10 @@
> $Workflow::Persister::DBI::VERSION = '1.19';
>
> my @FIELDS = qw( handle dsn user password driver
> - workflow_table history_table );
> + workflow_table history_table date_format parser);
> __PACKAGE__->mk_accessors( @FIELDS );
>
> my ( $log );
> -my $parser = DateTime::Format::Strptime->new( pattern => '%Y-%m-%d
> %H:%M' );
> my @WF_FIELDS = ();
> my @HIST_FIELDS = ();
>
> @@ -48,10 +47,16 @@
> $log->info( "Assigned workflow table '", $self-
> >workflow_table, "'; ",
> "history table '", $self->history_table, "'" );
>
> - for ( qw( dsn user password ) ) {
> + # Default to old date format if not provided so we don't break
> old
> configurations.
> + $self->date_format( '%Y-%m-%d %H:%M' );
> +
> + for ( qw( dsn user password date_format ) ) {
> $self->$_( $params->{ $_ } ) if ( $params->{ $_ } );
> }
>
> + my $parser = DateTime::Format::Strptime->new( pattern =>
> $self->date_format );
> + $self->parser($parser);
> +
> my $dbh = eval {
> DBI->connect( $self->dsn, $self->user, $self->password )
> || die "Cannot connect to database: $DBI::errstr";
> @@ -183,7 +188,7 @@
> my @fields = @WF_FIELDS[1,2,3];
> my @values = ( $wf->type,
> $wf->state,
> - DateTime->now->strftime( '%Y-%m-%d %H:%M' ) );
> + DateTime->now->strftime( $self->date_format() ) );
> my $dbh = $self->handle;
>
> my $id = $self->workflow_id_generator->pre_fetch_id( $dbh );
> @@ -249,7 +254,7 @@
> my $row = $sth->fetchrow_arrayref;
> return undef unless ( $row );
> return { state => $row->[0],
> - last_update => $parser->parse_datetime( $row->[1] ), };
> + last_update => $self->parser->parse_datetime( $row->
> [1] ), };
> }
>
> sub update_workflow {
> @@ -263,7 +268,7 @@
> WHERE $WF_FIELDS[0] = ?
> };
> $sql = sprintf( $sql, $self->workflow_table );
> - my $update_date = DateTime->now->strftime( '%Y-%m-%d %H:%M' );
> + my $update_date = DateTime->now->strftime( $self->date_format
> () );
>
> if ( $log->is_debug ) {
> $log->debug( "Will use SQL\n$sql" );
> @@ -293,7 +298,7 @@
> my $id = $generator->pre_fetch_id( $dbh );
> my @fields = @HIST_FIELDS[1..6];
> my @values = ( $wf->id, $h->action, $h->description, $h-
> >state,
> - $h->user, $h->date->strftime( '%Y-%m-%d %H:%
> M' ) );
> + $h->user, $h->date->strftime(
> $self->date_format() ) );
> if ( $id ) {
> push @fields, $HIST_FIELDS[0];
> push @values, $id;
> @@ -368,7 +373,7 @@
> description => $row->[3],
> state => $row->[4],
> user => $row->[5],
> - date => $parser->parse_datetime( $row->[6] ),
> + date => $self->parser->parse_datetime( $row->
> [6] ),
> });
> $log->is_debug &&
> $log->debug( "Fetched history object '$row->[0]'" );
> @@ -530,6 +535,15 @@
>
> Password for C<user> to login with.
>
> +=item B<date_format>
> +
> +Date format to use when working with the database. Accepts a
> format string
> +that can be processed by the DateTime module. See
> +L<http://search.cpan.org/~drolsky/DateTime-0.39/lib/
> DateTime.pm#strftime_Specifiers>
> +for the format options.
> +
> +The default is '%Y-%m-%d %H:%M' for backward compatibility.
> +
> =item B<workflow_table>
>
> Table to use for persisting workflow. Default is 'workflow'.
> @@ -699,4 +713,4 @@
>
> Chris Winters E<lt>ch...@cw...<gt>, original author.
>
> -=cut
> \ No newline at end of file
> +=cut
> diff -urX workflow.exclude orig/Workflow-0.28/t/TestUtil.pm
> working/Workflow-0.28/t/TestUtil.pm
> --- orig/Workflow-0.28/t/TestUtil.pm 2007-07-06 10:43:11.000000000
> -0400
> +++ working/Workflow-0.28/t/TestUtil.pm 2007-08-10
> 11:31:31.000000000 -0400
> @@ -95,6 +95,7 @@
> name => 'TestPersister',
> class => 'Workflow::Persister::DBI',
> dsn => 'DBI:Mock:',
> + user => 'DBTester',
> );
> $factory->add_config( persister => [ \%persister ] );
> }
> diff -urX workflow.exclude orig/Workflow-0.28/t/persister_dbi.t
> working/Workflow-0.28/t/persister_dbi.t
> --- orig/Workflow-0.28/t/persister_dbi.t 2007-07-06
> 10:43:11.000000000 -0400
> +++ working/Workflow-0.28/t/persister_dbi.t 2007-08-10
> 11:27:49.000000000 -0400
> @@ -5,7 +5,7 @@
> use strict;
> use lib 't';
> use TestUtil;
> -use constant NUM_TESTS => 41;
> +use constant NUM_TESTS => 43;
> use Test::More;
>
> eval "require DBI";
> @@ -18,7 +18,6 @@
>
> my $TICKET_CLASS = 'TestApp::Ticket';
> my $DATE_FORMAT = '%Y-%m-%d %H:%M';
> -my $NOW = DateTime->now->strftime( $DATE_FORMAT );
>
> require_ok( 'Workflow::Persister::DBI' );
>
> @@ -26,6 +25,8 @@
> name => 'TestPersister',
> class => 'Workflow::Persister::DBI',
> dsn => 'DBI:Mock:',
> + user => 'DBTester',
> + date_format => $DATE_FORMAT,
> });
>
> my $factory = Workflow::Factory->instance;
> @@ -37,6 +38,9 @@
> my $persister = $factory->get_persister( 'TestPersister' );
> my $handle = $persister->handle;
>
> +is ($persister->dsn(), 'DBI:Mock:', 'Got back dsn from config.');
> +is ($persister->date_format(), '%Y-%m-%d %H:%M', 'Got back date
> format
> from config.');
> +
> my ( $wf );
>
> {
> @@ -52,7 +56,7 @@
> qr/^INSERT INTO workflow \( type, state, last_update,
> workflow_id \)/,
> [ 'type', 'state', 'current date',
> 'random ID of correct length' ],
> - [ 'Ticket', 'INITIAL', $NOW,
> + [ 'Ticket', 'INITIAL', DateTime->now->strftime
> ( $DATE_FORMAT ),
> sub { my ( $val ) = @_; return ( length( $val ), 8 ) } ]
> );
>
> @@ -60,7 +64,7 @@
> TestUtil->check_workflow_history(
> $hst_history,
> [ $wf_id, 'Create workflow', 'Create new workflow',
> - 'INITIAL', 'n/a', $NOW,
> + 'INITIAL', 'n/a', DateTime->now->strftime( $DATE_FORMAT ),
> sub { my ( $val ) = @_; return ( length( $val ), 8 ) } ]
> );
> $handle->{mock_clear_history} = 1;
> @@ -91,7 +95,7 @@
> 'due date', 'last update' ],
> [ $ticket_id, $ticket_info{type}, $ticket_info{subject},
> $ticket_info{description}, $ticket_info{creator},
> $old_state,
> - $ticket_info{due_date}->strftime( '%Y-%m-%d' ), $NOW ]
> + $ticket_info{due_date}->strftime( '%Y-%m-%d' ),
> DateTime->now->strftime( $DATE_FORMAT ) ]
> );
>
> my $link_create = $history->[1];
> @@ -102,7 +106,7 @@
> TestUtil->check_workflow_history(
> $hst_update,
> [ $wf_id, 'Create ticket', $history_desc,
> - 'TIX_CREATED', $ticket_info{creator}, $NOW,
> + 'TIX_CREATED', $ticket_info{creator},
> DateTime->now->strftime( $DATE_FORMAT ),
> sub { my ( $val ) = @_; return ( length( $val ), 8 ) } ]
> );
>
>
>
> --
> Jim Brandt
> Administrative Computing Services
> University at Buffalo
>
>
>
> ----------------------------------------------------------------------
> ---
> This SF.net email is sponsored by: Splunk Inc.
> Still grepping through log files to find problems? Stop.
> Now Search log events and configuration files using AJAX and a
> browser.
> Download your FREE copy of Splunk now >> http://get.splunk.com/
> _______________________________________________
> Perl-workflow-devel mailing list
> Per...@li...
> https://lists.sourceforge.net/lists/listinfo/perl-workflow-devel
|