| 1 | package DBIx::dbMan::Extension::EditObjects; | ||
| 2 | |||
| 3 | use strict; | ||
| 4 | use base 'DBIx::dbMan::Extension'; | ||
| 5 | |||
| 6 | our $VERSION = '0.03'; | ||
| 7 | |||
| 8 | 1; | ||
| 9 | |||
| 10 | sub IDENTIFICATION { return "000001-000043-000003"; } | ||
| 11 | |||
| 12 | sub preference { return 0; } | ||
| 13 | |||
| 14 | sub known_actions { return [ qw/EDIT_OBJECT/ ]; } | ||
| 15 | |||
| 16 | sub handle_action { | ||
| 17 | my ($obj,%action) = @_; | ||
| 18 | |||
| 19 | $action{processed} = 1; | ||
| 20 | if ($action{action} eq 'EDIT_OBJECT' and not $action{type}) { | ||
| 21 | $action{action} = 'NONE'; | ||
| 22 | unless ($obj->{-dbi}->current) { | ||
| 23 | $obj->{-interface}->error("No current connection selected."); | ||
| 24 | return %action; | ||
| 25 | } | ||
| 26 | my $sth = $obj->{-dbi}->table_info({ TABLE_NAME => $action{what} }); | ||
| 27 | unless (defined $sth) { | ||
| 28 | $obj->{-interface}->error("Object ".$action{what}." not found."); | ||
| 29 | return %action; | ||
| 30 | } | ||
| 31 | my $ret = $sth->fetchall_arrayref(); | ||
| 32 | unless (defined $ret) { | ||
| 33 | $sth->finish; | ||
| 34 | $obj->{-interface}->error("Object ".$action{what}." not found."); | ||
| 35 | return %action; | ||
| 36 | } | ||
| 37 | $sth->finish; | ||
| 38 | my $found = 0; | ||
| 39 | my $type = ''; | ||
| 40 | for (@$ret) { | ||
| 41 | if ($_->[2] eq $action{what}) { | ||
| 42 | $type = $_->[3]; ++$found; | ||
| 43 | } | ||
| 44 | } | ||
| 45 | unless ($found) { | ||
| 46 | $obj->{-interface}->error("Object ".$action{what}." not found."); | ||
| 47 | return %action; | ||
| 48 | } | ||
| 49 | $action{type} = $type; | ||
| 50 | $action{action} = 'EDIT_OBJECT'; | ||
| 51 | delete $action{processed}; | ||
| 52 | } | ||
| 53 | |||
| 54 | return %action; | ||
| 55 | } |