[Bast-commits] r3218 - in trunk/DBIx-Class-Journal/lib/DBIx/Class:
. Schema Schema/Journal Schema/Journal/DB
castaway at dev.catalyst.perl.org
castaway at dev.catalyst.perl.org
Sun Apr 29 18:34:17 GMT 2007
Author: castaway
Date: 2007-04-29 18:34:17 +0100 (Sun, 29 Apr 2007)
New Revision: 3218
Modified:
trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeSet.pm
Log:
Add settings for current_user/session/changeset, overload insert()
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2007-04-28 22:21:44 UTC (rev 3217)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Journal.pm 2007-04-29 17:34:17 UTC (rev 3218)
@@ -1,12 +1,37 @@
package DBIx::Class::Journal;
use base qw/DBIx::Class/;
-__PACKAGE__->load_components(qw/AccessorGroup/);
-__PACKAGE__->mk_group_accessors('simple' => qw/
- journal_dsn
- journal_sources
- /);
+## On create/insert, add new entry to AuditLog
+sub new
+{
+ my ($class, $attrs, @rest) = @_;
+ $class->result_source->schema->_journal_schema->current_user(delete $attrs->{user_id});
+
+ $self->next::method($attrs, @rest);
+}
+
+sub insert
+{
+ my ($self) = @_;
+
+ ## create new transaction here?
+ $self->next::method();
+ if($self->in_storage)
+ {
+ my $s_name = $self->result_source_instance->name();
+ my $al = $self->result_source->schema->_journal_schema->resultset("${s_name}AuditLog");
+ $al->create({
+ changeset => $self->result_source->schema->_journal_schema->current_changeset(),
+ });
+}
+
+## On delete, update delete_id of AuditLog
+
+## On update, copy previous row's contents to AuditHistory
+
+
+
1;
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeSet.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeSet.pm 2007-04-28 22:21:44 UTC (rev 3217)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB/ChangeSet.pm 2007-04-29 17:34:17 UTC (rev 3218)
@@ -14,7 +14,7 @@
},
user_id => {
data_type => 'integer',
- is_nullable => 0,
+ is_nullable => 1,
is_foreign_key => 1,
},
set_date => {
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2007-04-28 22:21:44 UTC (rev 3217)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal/DB.pm 2007-04-29 17:34:17 UTC (rev 3218)
@@ -2,6 +2,10 @@
use base 'DBIx::Class::Schema';
+__PACKAGE__->mk_classdata('current_user');
+__PACKAGE__->mk_classdata('current_session');
+__PACKAGE__->mk_classdata('current_changeset');
+
DBIx::Class::Schema::Journal::DB->load_classes();
1;
Modified: trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm
===================================================================
--- trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2007-04-28 22:21:44 UTC (rev 3217)
+++ trunk/DBIx-Class-Journal/lib/DBIx/Class/Schema/Journal.pm 2007-04-29 17:34:17 UTC (rev 3218)
@@ -24,11 +24,13 @@
## get our own private version of the journaling sources
$self->_journal_schema($journal_schema->compose_namespace(blessed($self) . '::Journal'));
+ ## Create auditlog+history per table
my %j_sources = @{$self->journal_sources} ? map { $_ => 1 } @{$self->journal_sources} : map { $_ => 1 } $self->sources;
foreach my $s_name ($self->sources)
{
next unless($j_sources{$s_name});
$self->create_journal_for($s_name);
+ $self->source($s_name)->load_component('Journal');
}
## Set up relationship between changeset->user_id and this schema's user
@@ -38,9 +40,7 @@
return;
}
- ## get our own private version of the journaling sources
- $self->_journal_schema->compose_namespace(blessed($self) . '::Journal');
- DBIx::Class::Schema::Journal::DB::ChangeSet->belongs_to('user', @{$self->journal_user});
+ $self->_journal_schema->source('ChangeSet')->belongs_to('user', @{$self->journal_user});
}
sub get_audit_log_class_name
@@ -76,4 +76,19 @@
}
+sub create_changeset
+{
+ my ($self, $code) = @_;
+
+ ## Create a new changeset, then run $code as a transaction
+ my $cs = $self->result_source->schema->_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(),
+ });
+ $self->result_source->schema->_journal_schema->current_changeset($changeset->ID);
+
+ $self->txn_do($code);
+}
+
1;
More information about the Bast-commits
mailing list