[prev in list] [next in list] [prev in thread] [next in thread] 

List:       bricolage-devel
Subject:    Re: Story version corruption
From:       "David E. Wheeler" <david () kineticode ! com>
Date:       2009-02-17 19:04:06
Message-ID: A4BF781A-FA78-46D9-BDB5-144E2307E106 () kineticode ! com
[Download RAW message or body]

On Feb 16, 2009, at 8:24 PM, David E. Wheeler wrote:

> Well, I did find a way in which version numbers can get mucked up,  
> but it'd be kind of hard for it to happen. It would basically  
> require very slow publishes. I'm not completely convinced that my  
> recently-committed fixes will address the issue, though I certainly  
> hope so. The attached patch has the relevant fixes, including for  
> Scott's Bug #1417. Please do apply this to your Bricolage instance,  
> Matt, and let me know if the problem of story version number  
> corruption goes away or continues.

Trying to attach the patch again, this time as a .txt file.

Best,

David


["fixes.patch.txt" (fixes.patch.txt)]

Index: lib/Bric/Biz/Asset/Business.pm
===================================================================
--- lib/Bric/Biz/Asset/Business.pm	(revision 8407)
+++ lib/Bric/Biz/Asset/Business.pm	(revision 8412)
@@ -2162,7 +2162,7 @@
         $self->_set(['_checkout'], []);
     }
 
-    # Is this necessary? Seems kind of pointless. [David 2002-09-19]
+    # Once we've saved, clear the checkin flag.
     $self->_set(['_checkin'], []) if $ci;
 
     # Revert stores the old element for deletion. So save it to delete it.
Index: lib/Bric/Biz/Asset/Template.pm
===================================================================
--- lib/Bric/Biz/Asset/Template.pm	(revision 8407)
+++ lib/Bric/Biz/Asset/Template.pm	(revision 8412)
@@ -2160,17 +2160,24 @@
 =cut
 
 sub _update_template {
-        my ($self) = @_;
+    my ($self) = @_;
 
-        my $sql = 'UPDATE ' . TABLE .
-                  ' SET ' . join(', ', map {"$_=?" } COLS) .
-                  ' WHERE id=? ';
+    my @cols   = COLS;
+    my @fields = FIELDS;
+    unless ($self->_get('_checkin')) {
+        # Do not update current_version unless we're checking in.
+        @cols   = grep { $_ ne 'current_version' } @cols;
+        @fields = grep { $_ ne 'current_version' } @fields;
+    }
 
-        my $sth = prepare_c($sql, undef);
+    my $sql = 'UPDATE ' . TABLE .
+              ' SET ' . join(', ', map {"$_ = ?" } @cols) .
+              ' WHERE id = ?';
 
-        execute($sth, $self->_get(FIELDS), $self->_get('id'));
+    my $sth = prepare_c($sql, undef);
+    execute($sth, $self->_get(@fields), $self->_get('id'));
 
-        return $self;
+    return $self;
 }
 
 ################################################################################
Index: lib/Bric/Biz/Asset/Business/Media.pm
===================================================================
--- lib/Bric/Biz/Asset/Business/Media.pm	(revision 8407)
+++ lib/Bric/Biz/Asset/Business/Media.pm	(revision 8412)
@@ -2134,11 +2134,19 @@
 sub _update_media {
     my $self = shift;
 
-    my $sql = 'UPDATE ' . TABLE . ' SET '. join(', ', map {"$_=?"} COLS) .
-      ' WHERE id=? ';
+    my @cols   = COLS;
+    my @fields = FIELDS;
+    unless ($self->_get('_checkin')) {
+        # Do not update current_version unless we're checking in.
+        @cols   = grep { $_ ne 'current_version' } @cols;
+        @fields = grep { $_ ne 'current_version' } @fields;
+    }
 
+    my $sql = 'UPDATE ' . TABLE . ' SET '. join(', ', map {"$_ = ?"} @cols) .
+      ' WHERE id = ?';
+
     my $sth = prepare_c($sql, undef);
-    execute($sth, $self->_get(FIELDS), $self->_get('id'));
+    execute($sth, $self->_get(@fields), $self->_get('id'));
     return $self;
 }
 
Index: lib/Bric/Biz/Asset/Business/Story.pm
===================================================================
--- lib/Bric/Biz/Asset/Business/Story.pm	(revision 8407)
+++ lib/Bric/Biz/Asset/Business/Story.pm	(revision 8412)
@@ -2393,11 +2393,20 @@
 sub _update_story {
     my ($self) = @_;
     return unless $self->_get__dirty();
-    my $sql = 'UPDATE ' . TABLE . ' SET ' . join(', ', map { "$_ = ?" } COLS) .
-      ' WHERE id=? ';
 
+    my @cols   = COLS;
+    my @fields = FIELDS;
+    unless ($self->_get('_checkin')) {
+        # Do not update current_version unless we're checking in.
+        @cols   = grep { $_ ne 'current_version' } @cols;
+        @fields = grep { $_ ne 'current_version' } @fields;
+    }
+
+    my $sql = 'UPDATE ' . TABLE . ' SET ' . join(', ', map { "$_ = ?" } @cols) .
+      ' WHERE id = ?';
+
     my $sth = prepare_c($sql, undef);
-    execute($sth, $self->_get(FIELDS), $self->_get('id'));
+    execute($sth, $self->_get(@fields), $self->_get('id'));
     return $self;
 }
 
Index: lib/Bric/Biz/Asset.pm
===================================================================
--- lib/Bric/Biz/Asset.pm	(revision 8407)
+++ lib/Bric/Biz/Asset.pm	(revision 8412)
@@ -1721,14 +1721,14 @@
     throw_gen(error => "Cannot checkin non checked out versions")
       unless $self->_get('checked_out');
 
-    my $version = $self->_get('version');
-    $version++;
-    $self->_set({ user__id => undef,
-                  version   => $version,
-                  current_version => $version,
-                  checked_out => 0,
-                  _checkin => 1
-                });
+    my $version = $self->_get('current_version') + 1;
+    $self->_set({
+        user__id        => undef,
+        version         => $version,
+        current_version => $version,
+        checked_out     => 0,
+        _checkin        => 1
+    });
 
     return $self;
 }
Index: lib/Bric/Util/DBI.pm
===================================================================
--- lib/Bric/Util/DBI.pm	(revision 8407)
+++ lib/Bric/Util/DBI.pm	(revision 8412)
@@ -808,7 +808,7 @@
     # Map inverse alias inactive to active.
     $param->{'active'} = ($param->{'inactive'} ? 0 : 1)
       if exists $param->{'inactive'};
-    unless ($param->{published_version}) {
+    unless ($param->{published_version} or $param->{version_id}) {
         # checked_out has some special cases
         # deal with the checked_out param.  The all argument is actually
         # the default behavior.




[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic