From d66b3b891bc940ae5c0bc1fda41200f5b1b5c209 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 25 Jan 2010 22:49:22 -0800 Subject: [PATCH] Make revisedBy a property, so it gets written on ->update. Change addRev not to write to the db when it does not need to. Update tests to verify that addRev does the right thing for tagId and revisedBy. --- lib/WebGUI/Asset.pm | 7 ++++++- lib/WebGUI/AssetVersioning.pm | 11 +---------- t/Asset.t | 6 ++++-- 3 files changed, 11 insertions(+), 13 deletions(-) diff --git a/lib/WebGUI/Asset.pm b/lib/WebGUI/Asset.pm index 0334a4adf..aa44daa87 100644 --- a/lib/WebGUI/Asset.pm +++ b/lib/WebGUI/Asset.pm @@ -260,6 +260,11 @@ has assetId => ( has revisionDate => ( is => 'rw', ); +property revisedBy => ( + is => 'rw', + noFormPost => 1, + fieldType => 'guid', + ); has [qw/parentId lineage creationDate createdBy state stateChanged stateChangedBy @@ -2313,7 +2318,7 @@ sub write { my @values = map { $self->$_ } @properties; my @columnNames = map { $db->quoteIdentifier($_).'=?' } @properties; push @values, $self->getId, $self->revisionDate; - $db->write("update ".$table." set ".join(",",@columnNames)." where assetId=? and revisionDate=?",\@values); + $db->write("update ".$table." set ".join(",",@columnNames)." where assetId=? and revisionDate=?",\@values); } # update the asset's size, which also purges the cache. diff --git a/lib/WebGUI/AssetVersioning.pm b/lib/WebGUI/AssetVersioning.pm index dc19e2ef1..54a69b282 100644 --- a/lib/WebGUI/AssetVersioning.pm +++ b/lib/WebGUI/AssetVersioning.pm @@ -114,17 +114,8 @@ sub addRevision { } $session->db->commit; - my $sql = "update assetData set revisedBy=?, tagId=? where assetId=? and revisionDate=?"; - - $session->db->write($sql,[ - $session->user->userId, - $workingTag->getId, - $self->getId, - $now, - ]); - # current values, and the user set properties - my %mergedProperties = (%{$self->get}, %{$properties}, (status => 'pending')); + my %mergedProperties = (%{$self->get}, %{$properties}, (status => 'pending', revisedBy => $session->user->userId, tagId => $workingTag->getId), ); #Instantiate new revision and fill with real data my $newVersion = WebGUI::Asset->newById($session, $self->getId, $now); diff --git a/t/Asset.t b/t/Asset.t index eaa523f1f..a94ef325f 100644 --- a/t/Asset.t +++ b/t/Asset.t @@ -21,7 +21,7 @@ use Test::Deep; use Test::Exception; use WebGUI::Exception; -plan tests => 57; +plan tests => 59; my $session = WebGUI::Test->session; @@ -238,13 +238,15 @@ my $session = WebGUI::Test->session; my $testAsset = WebGUI::Asset->new($session, $testId2, $revisionDate); $testAsset->title('test title 43'); $testAsset->write(); + my $tag = WebGUI::VersionTag->getWorking($session); my $revAsset = $testAsset->addRevision({}, $now); isa_ok $revAsset, 'WebGUI::Asset'; is $revAsset->revisionDate, $now, 'revisionDate set correctly on new revision'; is $revAsset->title, 'test title 43', 'data fetch from database correct'; + is $revAsset->revisedBy, $session->user->userId, 'revisedBy is current session user'; + is $revAsset->tagId, $tag->getId, 'tagId is current working tagId'; my $count = $session->db->quickScalar('SELECT COUNT(*) from assetData where assetId=?',[$testId2]); is $count, 2, 'two records in the database'; - my $tag = WebGUI::VersionTag->getWorking($session); addToCleanup($tag); $session->db->write("delete from asset where assetId like 'wg8TestAsset00000%'");