return;
}
+ $self->_journal_schema->deploy();
$self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
+ $self->_journal_schema->storage->disconnect();
}
sub get_audit_log_class_name
$self->_journal_schema->register_class("${s_name}AuditHistory", $histclass);
}
-sub create_changeset
+sub txn_do
{
my ($self, $code) = @_;
## Create a new changeset, then run $code as a transaction
- my $cs = $self->result_source->schema->_journal_schema->resultset('ChangeSet');
+ my $cs = $self->_journal_schema->resultset('ChangeSet');
my $changeset = $cs->create({
- user_id => $self->result_source->schema->_journal_schema->current_user(),
- session_id => $self->result_source->schema->_journal_schema->current_session(),
+ user_id => $self->_journal_schema->current_user(),
+ session_id => $self->_journal_schema->current_session(),
});
- $self->result_source->schema->_journal_schema->current_changeset($changeset->ID);
+ $self->_journal_schema->current_changeset($changeset->ID);
- $self->txn_do($code);
+ $self->next::method($code);
}
1;
sub new
{
- my ($self, $data, @rest) = @_;
+ my ($self, $data, $source, @rest) = @_;
$data->{created} = {
- changeset_id => $self->result_source->schema->_journal_schema->current_changeset,
+ changeset_id => $source->schema->current_changeset,
};
- $self->next::method($data, @rest);
+ $self->next::method($data, $source, @rest);
}
1;
isa_ok($schema->_journal_schema->source('CDAuditHistory'), 'DBIx::Class::ResultSource', 'CDAuditHistory source exists');
isa_ok($schema->_journal_schema->source('ArtistAuditLog'), 'DBIx::Class::ResultSource', 'ArtistAuditLog source exists');
-my $new_cd = $schema->resultset('CD')->create({
- title => 'Angry young man',
- artist => 0,
- year => 2000,
+my $new_cd = $schema->txn_do( sub {
+ return $schema->resultset('CD')->create({
+ title => 'Angry young man',
+ artist => 0,
+ year => 2000,
});
-
+});
isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object');
my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();