## On create/insert, add new entry to AuditLog
-sub new
-{
- my ($class, $attrs, @rest) = @_;
+# sub new
+# {
+# my ($class, $attrs, @rest) = @_;
- $class->result_source->schema->_journal_schema->current_user(delete $attrs->{user_id});
+# $class->result_source->schema->_journal_schema->current_user(delete $attrs->{user_id});
- $class->next::method($attrs, @rest);
-}
+# $class->next::method($attrs, @rest);
+# }
sub insert
{
my ($self) = @_;
## create new transaction here?
- $self->next::method();
+ my $res = $self->next::method();
if($self->in_storage)
{
- my $s_name = $self->result_source_instance->name();
+ my $s_name = $self->result_source->source_name();
+ print STDERR "Schema: ", ref($self->result_source->schema), "\n";
my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
$al->create({
changeset => $self->result_source->schema->_journal_schema->current_changeset(),
});
}
+
+ return $res;
}
## On delete, update delete_id of AuditLog
my $self = shift;
$self->next::method(@_);
- my $journal_schema = (__PACKAGE__ . '::DB')->connect($self->journal_connection || $self->storage->connect_info);
+ my $journal_schema = DBIx::Class::Schema::Journal::DB->connect(@{ $self->journal_connection || $self->storage->connect_info });
+ print STDERR "conn", $journal_schema->storage->connect_info;
if($self->journal_storage_type)
{
$journal_schema->storage_type($self->journal_storage_type);
{
next unless($j_sources{$s_name});
$self->create_journal_for($s_name);
- $self->source($s_name)->load_component('Journal');
+ $self->class($s_name)->load_components('Journal');
+ print STDERR "$s_name :", $self->class($s_name), "\n";
}
## Set up relationship between changeset->user_id and this schema's user
return;
}
- $self->_journal_schema->source('ChangeSet')->belongs_to('user', @{$self->journal_user});
+ $self->_journal_schema->class('ChangeSet')->belongs_to('user', @{$self->journal_user});
}
sub get_audit_log_class_name
my $source = $self->source($s_name);
my $newclass = $self->get_audit_log_class_name($s_name);
DBIx::Class::Componentised->inject_base($newclass, 'DBIx::Class::Schema::Journal::DB::AuditLog');
-# $newclass->table(lc($s_name) . "_audit_log");
- $newclass->result_source_instance->name(lc($s_name) . "_audit_log");
+ $newclass->table(lc($s_name) . "_audit_log");
+ $self->_journal_schema->register_class("${s_name}AuditLog", $newclass);
- my $histclass = $self->get_audit_hisory_class_name($s_name);
+ my $histclass = $self->get_audit_history_class_name($s_name);
DBIx::Class::Componentised->inject_base($histclass, 'DBIx::Class::Schema::Journal::DB::AuditHistory');
- $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
+ $histclass->table(lc($s_name) . "_audit_history");
+# $histclass->result_source_instance->name(lc($s_name) . "_audit_hisory");
$histclass->add_columns(
map { $_ => $source->column_info($_) } $source->columns
);
+ $self->_journal_schema->register_class("${s_name}AuditHistory", $histclass);
}
sub create_changeset
DBIx::Class::Schema::Journal::DB->load_classes(qw/
ChangeSet
Change
+ AuditLog
+ AuditHistory
/);
1;
package DBIx::Class::Schema::Journal::DB::AuditHistory;
use base 'DBIx::Class::Schema::Journal::DB::Base';
+__PACKAGE__->table(__PACKAGE__->table);
__PACKAGE__->add_columns(
change_id => {
package DBIx::Class::Schema::Journal::DB::AuditLog;
use base 'DBIx::Class::Schema::Journal::DB::Base';
+__PACKAGE__->table(__PACKAGE__->table);
__PACKAGE__->add_columns(
ID => {
eval "use DBD::SQLite";
plan $@
? ( skip_all => 'needs DBD::SQLite for testing' )
- : ( tests => 2 );
+ : ( tests => 6 );
}
my $schema = DBICTest->init_schema(no_populate => 1);
ok($schema, 'Created a Schema');
-isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB');
+isa_ok($schema->_journal_schema, 'DBIx::Class::Schema::Journal::DB', 'Actually have a schema object for the journaling');
+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,
+ });
+
+isa_ok($new_cd, 'DBIx::Class::Journal', 'Created CD object');
+
+my $search = $schema->_journal_schema->resultset('CDAuditLog')->search();
+ok($search->count, 'Created an entry in the CD audit log');
+
__PACKAGE__->load_components(qw/+DBIx::Class::Schema::Journal/);
-no warnings qw/qw/;
+__PACKAGE__->journal_user(['DBICTest::Schema::Artist', {'foreign.artistid' => 'self.user_id'}]);
+no warnings qw/qw/;
__PACKAGE__->load_classes(qw/
Artist
CD