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 # this is for localization of the current changeset
11 sub current_changeset {
12 my ( $self, @args ) = @_;
14 $self->throw_error("setting current_changeset is not supported, use txn_do to create a new changeset") if @args;
16 my $ref = $self->_current_changeset_container;
18 return $ref && $ref->{changeset};
21 DBIx::Class::Schema::Journal::DB->load_classes(qw/
28 sub journal_create_changeset {
29 my ( $self, @args ) = @_;
31 my %changesetdata = ( @args, ID => undef );
33 delete $changesetdata{parent_id} unless $self->nested_changesets;
35 if( defined( my $user = $self->current_user() ) )
37 $changesetdata{user_id} = $user;
39 if( defined( my $session = $self->current_session() ) )
41 $changesetdata{session_id} = $session;
44 ## Create a new changeset, then run $code as a transaction
45 my $cs = $self->resultset('ChangeSet');
47 $cs->create({ %changesetdata });