1 package DBIx::Class::Schema::Journal::DB;
3 use base 'DBIx::Class::Schema';
5 __PACKAGE__->mk_classdata('nested_changesets');
6 __PACKAGE__->mk_group_accessors( simple => 'current_user' );
7 __PACKAGE__->mk_group_accessors( simple => 'current_session' );
8 __PACKAGE__->mk_group_accessors( simple => '_current_changeset_container' );
10 DBIx::Class::Schema::Journal::DB->load_classes(qw/
18 sub _current_changeset {
20 my $ref = $self->_current_changeset_container;
21 $ref && $ref->{changeset};
24 # this is for localization of the current changeset
25 sub current_changeset {
26 my ( $self, @args ) = @_;
28 $self->throw_exception("setting current_changeset is not supported, use txn_do to create a new changeset") if @args;
30 my $id = $self->_current_changeset;
32 $self->throw_exception("Can't call current_changeset outside of a transaction") unless $id;
37 sub journal_create_changeset {
38 my ( $self, @args ) = @_;
40 my %changesetdata = ( @args, ID => undef );
42 delete $changesetdata{parent_id} unless $self->nested_changesets;
44 if( defined( my $user = $self->current_user() ) )
46 $changesetdata{user_id} = $user;
48 if( defined( my $session = $self->current_session() ) )
50 $changesetdata{session_id} = $session;
53 ## Create a new changeset, then run $code as a transaction
54 my $cs = $self->resultset('ChangeSet');
56 $cs->create({ %changesetdata });