[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. ea96093513a7adfffb8835d45a6a9ebcef0be410

Shawn Moore sartak at bestpractical.com
Wed Feb 9 21:36:38 EST 2011


The branch, master has been updated
       via  ea96093513a7adfffb8835d45a6a9ebcef0be410 (commit)
      from  79cdb6b18dcfdda75d3b74587deec2d86c2dfd0a (commit)

Summary of changes:
 .../RecordHistory/Mixin/Model/RecordHistory.pm     |    7 ++++++-
 lib/Jifty/Plugin/RecordHistory/Model/Change.pm     |    9 +++++++++
 2 files changed, 15 insertions(+), 1 deletions(-)

- Log -----------------------------------------------------------------
commit ea96093513a7adfffb8835d45a6a9ebcef0be410
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Wed Feb 9 21:36:25 2011 -0500

    Defer update change creation until we add a change_field

diff --git a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
index efc32da..c73390c 100644
--- a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
@@ -109,7 +109,12 @@ sub start_change {
     );
 
     my $change = Jifty::Plugin::RecordHistory::Model::Change->new;
-    $change->create(%args);
+    if ($type eq 'update') {
+        $change->deferred_create(%args);
+    }
+    else {
+        $change->create(%args);
+    }
 
     return $self->{change} = $change;
 }
diff --git a/lib/Jifty/Plugin/RecordHistory/Model/Change.pm b/lib/Jifty/Plugin/RecordHistory/Model/Change.pm
index cf0071a..138ae7c 100644
--- a/lib/Jifty/Plugin/RecordHistory/Model/Change.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Model/Change.pm
@@ -45,6 +45,11 @@ sub create {
     return $self->SUPER::create(%args);
 }
 
+sub deferred_create {
+    my $self = shift;
+    return $self->{deferred_create} = { @_ };
+}
+
 sub record {
     my $self = shift;
     my $record = $self->record_class->new;
@@ -66,6 +71,10 @@ sub add_change_field {
     my $self = shift;
     my %args = @_;
 
+    if (my $args = delete $self->{deferred_create}) {
+        $self->create(%$args);
+    }
+
     my $change_field = Jifty::Plugin::RecordHistory::Model::ChangeField->new;
     $change_field->create(
         %args,

-----------------------------------------------------------------------



More information about the Bps-public-commit mailing list