Fix "inserting audit_log twice" bug, start on allowing using the same schema
Jess Robinson [Fri, 11 May 2007 14:21:39 +0000 (14:21 +0000)]
lib/DBIx/Class/Journal.pm
lib/DBIx/Class/Schema/Journal.pm
t/lib/DBICTest.pm

index 4d362a9..19304d5 100644 (file)
@@ -17,6 +17,7 @@ sub insert
 {
     my ($self) = @_;
 
+    return if($self->in_storage);
     ## create new transaction here?
     my $res = $self->next::method();
     if($self->in_storage)
index 634f96e..493837d 100644 (file)
@@ -23,6 +23,15 @@ sub exception_action
     $self->next::method(@_);
 }
 
+# sub load_classes
+# {
+#     my $class = shift;
+
+
+#     $class->next::method(@_);
+    
+# }
+
 sub connection
 {
     my $self = shift;
@@ -30,11 +39,20 @@ sub connection
 
 #   print STDERR join(":", $self->sources), "\n";
 
-    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)
+    my $journal_schema;
+    if(!defined($self->journal_connection))
+    {
+        ## If no connection, use the same schema/storage etc as the user
+        DBIx::Class::Componentised->inject_base(ref $self, 'DBIx::Class::Schema::Journal::DB');
+          $journal_schema = $self;
+    }
+    else
     {
-        $journal_schema->storage_type($self->journal_storage_type);
+        $journal_schema = DBIx::Class::Schema::Journal::DB->connect(@{ $self->journal_connection });
+        if($self->journal_storage_type)
+        {
+            $journal_schema->storage_type($self->journal_storage_type);
+        }
     }
 
     ## get our own private version of the journaling sources
index 354d9c9..bd6725a 100644 (file)
@@ -46,9 +46,12 @@ sub init_schema {
     my $self = shift;
     my %args = @_;
     my $db_file = "t/var/DBIxClass.db";
+    my $db_audit = 't/var/Audit.db';
 
     unlink($db_file) if -e $db_file;
     unlink($db_file . "-journal") if -e $db_file . "-journal";
+    unlink($db_audit) if -e $db_audit;
+    unlink($db_audit . "-journal") if -e $db_audit . "-journal";
     mkdir("t/var") unless -d "t/var";
 
     my $dsn = $ENV{"DBICTEST_DSN"} || "dbi:SQLite:${db_file}";