[Bps-public-commit] jifty-plugin-recordhistory branch, master, updated. 0.03-2-g8252a58

Shawn Moore sartak at bestpractical.com
Fri Feb 18 16:44:22 EST 2011


The branch, master has been updated
       via  8252a58ced1ea2e2165c481bd1ee30d06b9ea4d1 (commit)
      from  db3c40eb7d184e98c7df35fc31b09bd00a723532 (commit)

Summary of changes:
 lib/Jifty/Plugin/RecordHistory.pm                  |   16 ++++++++++
 .../RecordHistory/Mixin/Model/RecordHistory.pm     |   31 +++++++++++--------
 2 files changed, 34 insertions(+), 13 deletions(-)

- Log -----------------------------------------------------------------
commit 8252a58ced1ea2e2165c481bd1ee30d06b9ea4d1
Author: Shawn M Moore <sartak at bestpractical.com>
Date:   Fri Feb 18 16:44:13 2011 -0500

    Implement and document cascaded_delete

diff --git a/lib/Jifty/Plugin/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory.pm
index c96e434..3b0e16a 100644
--- a/lib/Jifty/Plugin/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory.pm
@@ -42,6 +42,22 @@ and using the mixin to your record class(es) to enjoy transaction history. The
 mixin even hooks into Jifty itself to observe record creation, updates, and
 deletions.
 
+=head2 Configuration
+
+When you're importing the mixin you have several options to control the behavior
+of history. Here are the defaults:
+
+    use Jifty::Plugin::RecordHistory::Mixin::Model::RecordHistory (
+        cascaded_delete => 1,
+    );
+
+If C<cascaded_delete> is true, then
+L<Jifty::Plugin::RecordHistory::Model::Change> and
+L<Jifty::Plugin::RecordHistory::Model::ChangeField> records are deleted at the
+same time the original record they refer to is deleted. If C<cascaded_delete>
+is false, then the Change and ChangeField records persist even if the original
+record is deleted.
+
 =head2 Grouping
 
 By default, the only mechanism that groups together change_fields onto a single
diff --git a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
index 89e994b..6f4ed74 100644
--- a/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
+++ b/lib/Jifty/Plugin/RecordHistory/Mixin/Model/RecordHistory.pm
@@ -11,7 +11,10 @@ our @EXPORT = qw(
 
 sub import {
     my $class = shift;
-    my %args  = @_;
+    my %args  = (
+        cascaded_delete => 1,
+        @_,
+    );
 
     my $caller = caller;
 
@@ -58,20 +61,22 @@ sub import {
         );
     });
 
-    # we hook into before_delete so we can still access ->changes etc
-    $caller->add_trigger(before_delete => sub {
-        my $self = shift;
+    if ($args{cascaded_delete}) {
+        # we hook into before_delete so we can still access ->changes etc
+        $caller->add_trigger(before_delete => sub {
+            my $self = shift;
 
-        my $changes = $self->changes;
-        while (my $change = $changes->next) {
-            my $change_fields = $change->change_fields;
-            while (my $change_field = $change_fields->next) {
-                $change_field->delete;
-            }
+            my $changes = $self->changes;
+            while (my $change = $changes->next) {
+                my $change_fields = $change->change_fields;
+                while (my $change_field = $change_fields->next) {
+                    $change_field->delete;
+                }
 
-            $change->delete;
-        }
-    });
+                $change->delete;
+            }
+        });
+    }
 
     # wrap update actions in a change so we can group them as one change with
     # many field changes

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



More information about the Bps-public-commit mailing list