X-Git-Url: https://git.decadent.org.uk/gitweb/?a=blobdiff_plain;f=lib%2FMaypole%2FModel%2FCDBI.pm;h=ae11c4dc1fc50d2d498d5515c93e9a16e262cccd;hb=02b642b7100a6e0a91e83aca3c4e63cd88786315;hp=3705331c8ec74de51de6f50ab4562591752bcc83;hpb=7249c53d755f2eb5b8b5bb471ff49b8dd6f3dbf0;p=maypole.git diff --git a/lib/Maypole/Model/CDBI.pm b/lib/Maypole/Model/CDBI.pm index 3705331..ae11c4d 100644 --- a/lib/Maypole/Model/CDBI.pm +++ b/lib/Maypole/Model/CDBI.pm @@ -25,8 +25,8 @@ will instead use Class::DBI classes provided. use base qw(Maypole::Model::Base Class::DBI); use Maypole::Model::CDBI::AsForm; -use CGI::Untaint::Maypole; - +use CGI::Untaint; +use Class::DBI::Plugin::Type; use Class::DBI::FromCGI; use Class::DBI::Loader; use Class::DBI::AbstractSearch; @@ -36,6 +36,8 @@ use Class::DBI::Pager; use Lingua::EN::Inflect::Number qw(to_PL); use attributes (); +use Data::Dumper; + ############################################################################### # Helper methods @@ -98,11 +100,15 @@ sub do_edit : Exported { } undef $obj if $creating; + + die "do_update failed with error : $fatal" if ($fatal); $r->template("edit"); } else { $r->template("view"); } + + $r->objects( $obj ? [$obj] : []); } @@ -112,7 +118,8 @@ sub _do_update_or_create { my $fatal; my $creating = 0; - my $h = CGI::Untaint::Maypole->new( %{$r->params} ); + + my $h = CGI::Untaint->new( %{$r->params} ); # update or create if ($obj) { @@ -133,7 +140,10 @@ sub _do_update_or_create { }; if ($fatal = $@) { - warn "$fatal" if $r->debug; + warn "FATAL ERROR: $fatal" if $r->debug; +# $self->dbi_rollback; + } else { +# $self->dbi_commit; } $creating++; } @@ -170,7 +180,9 @@ sub delete : Exported { sub do_delete { my ( $self, $r ) = @_; + # FIXME: handle fatal error with exception $_->SUPER::delete for @{ $r->objects || [] }; +# $self->dbi_commit; $r->objects( [ $self->retrieve_all ] ); $r->{template} = "list"; $self->list($r); @@ -580,7 +592,9 @@ sub setup_database { ); $config->{classes} = [ $config->{loader}->classes ]; $config->{tables} = [ $config->{loader}->tables ]; - warn( 'Loaded tables: ' . join ',', @{ $config->{tables} } ) + + my @table_class = map { $_ . " => " . $config->{loader}->_table2class($_) } @{ $config->{tables} }; + warn( 'Loaded tables to classes: ' . join ', ', @table_class ) if $namespace->debug; }