| 1 | package DBIx::Class::Schema::Journal::DB; | ||||||||||
| 2 | |||||||||||
| 3 | 2 | ▶ | use base 'DBIx::Class::Schema'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 2 | __PACKAGE__->mk_classdata('nested_changesets'); | |||||||||
| 6 | 2 | __PACKAGE__->mk_group_accessors( simple => 'current_user' ); | |||||||||
| 7 | 2 | __PACKAGE__->mk_group_accessors( simple => 'current_session' ); | |||||||||
| 8 | 2 | __PACKAGE__->mk_group_accessors( simple => '_current_changeset_container' ); | |||||||||
| 9 | |||||||||||
| 10 | 2 | DBIx::Class::Schema::Journal::DB->load_classes(qw(ChangeSet ChangeLog)); | |||||||||
| 11 | |||||||||||
| 12 | 2 | require DBIx::Class::Schema::Journal::DB::AuditLog; | |||||||||
| 13 | 2 | require DBIx::Class::Schema::Journal::DB::AuditHistory; | |||||||||
| 14 | |||||||||||
| 15 | sub _current_changeset { | ||||||||||
| 16 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
_current_changeset: not called CC=2 SCAR=17.9
| |||||||||||
| 17 | 0 | my $ref = $self->_current_changeset_container; | |||||||||
| 18 | 0 | ▶ | $ref && $ref->{changeset}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 19 | } | ||||||||||
| 20 | |||||||||||
| 21 | # this is for localization of the current changeset | ||||||||||
| 22 | sub current_changeset { | ||||||||||
| 23 | 0 | ▶ | my ( $self, @args ) = @_; | ||||||||
|
Subroutine
current_changeset: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||
| 24 | |||||||||||
| 25 | 0 | ▶ | $self->throw_exception("setting current_changeset is not supported, use txn_do to create a new changeset") if @args; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 26 | |||||||||||
| 27 | 0 | my $id = $self->_current_changeset; | |||||||||
| 28 | |||||||||||
| 29 | 0 | ▶ | $self->throw_exception("Can't call current_changeset outside of a transaction") unless $id; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 30 | |||||||||||
| 31 | 0 | return $id; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | sub journal_create_changeset { | ||||||||||
| 35 | 0 | ▶ | my ( $self, @args ) = @_; | ||||||||
|
Subroutine
journal_create_changeset: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||
| 36 | |||||||||||
| 37 | 0 | my %changesetdata = ( @args, ID => undef ); | |||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | delete $changesetdata{parent_id} unless $self->nested_changesets; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 40 | |||||||||||
| 41 | 0 | ▶ | if( defined( my $user = $self->current_user() ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 42 | { | ||||||||||
| 43 | 0 | $changesetdata{user_id} = $user; | |||||||||
| 44 | } | ||||||||||
| 45 | 0 | ▶ | if( defined( my $session = $self->current_session() ) ) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 46 | { | ||||||||||
| 47 | 0 | $changesetdata{session_id} = $session; | |||||||||
| 48 | } | ||||||||||
| 49 | |||||||||||
| 50 | ## Create a new changeset, then run $code as a transaction | ||||||||||
| 51 | 0 | my $cs = $self->resultset('ChangeSet'); | |||||||||
| 52 | |||||||||||
| 53 | 0 | $cs->create({ %changesetdata }); | |||||||||
| 54 | } | ||||||||||
| 55 | |||||||||||
| 56 | sub journal_create_change { | ||||||||||
| 57 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
journal_create_change: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 58 | 0 | $self->resultset("ChangeLog")->create({ changeset_id => $self->current_changeset }); | |||||||||
| 59 | } | ||||||||||
| 60 | |||||||||||
| 61 | sub journal_update_or_create_log_entry | ||||||||||
| 62 | { | ||||||||||
| 63 | 0 | ▶ | my ($self, $row, @cols) = @_; | ||||||||
|
Subroutine
journal_update_or_create_log_entry: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 64 | |||||||||||
| 65 | 0 | my $s_name = $row->result_source->source_name; | |||||||||
| 66 | |||||||||||
| 67 | 0 | my %id = map { $_ => $row->get_column($_)} $row->primary_columns; | |||||||||
| 68 | |||||||||||
| 69 | 0 | $self->resultset("${s_name}AuditLog")->update_or_create({ @cols, %id }); | |||||||||
| 70 | } | ||||||||||
| 71 | |||||||||||
| 72 | sub journal_record_in_history | ||||||||||
| 73 | { | ||||||||||
| 74 | 0 | ▶ | my ($self, $row, @cols) = @_; | ||||||||
|
Subroutine
journal_record_in_history: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||
| 75 | |||||||||||
| 76 | 0 | my $s_name = $row->result_source->source_name; | |||||||||
| 77 | |||||||||||
| 78 | 0 | $self->resultset("${s_name}AuditHistory")->create({ $row->get_columns, @cols }); | |||||||||
| 79 | } | ||||||||||
| 80 | |||||||||||
| 81 | |||||||||||
| 82 | 2 | 1; | |||||||||