From f715c29c67d5aac661bbf5bc57622939eee342d9 Mon Sep 17 00:00:00 2001 From: JT Smith Date: Fri, 5 Oct 2007 17:50:45 +0000 Subject: [PATCH] fix: Dashboard content positioning field problem --- docs/changelog/7.x.x.txt | 1 + docs/upgrades/upgrade_7.4.8-7.4.9.pl | 37 +++++++++++++++++++----- lib/WebGUI/Asset/Wobject/Dashboard.pm | 41 ++++++++++++++++++++------- 3 files changed, 61 insertions(+), 18 deletions(-) diff --git a/docs/changelog/7.x.x.txt b/docs/changelog/7.x.x.txt index 5d6fa3f5b..45271cf33 100644 --- a/docs/changelog/7.x.x.txt +++ b/docs/changelog/7.x.x.txt @@ -5,6 +5,7 @@ - fix: purging old asset revisions on large sites never completes - fix: Can't add assets when not using preload.perl. - fix: wiki recent + - fix: Dashboard content positioning field problem - fix: graphing doesn't work with GraphicsMagick - fix: Calendar generated iCal for last 30 days instead of next 30 days - fix: hover help doesn't appear for matrix fields diff --git a/docs/upgrades/upgrade_7.4.8-7.4.9.pl b/docs/upgrades/upgrade_7.4.8-7.4.9.pl index 74383b515..9798af8e2 100644 --- a/docs/upgrades/upgrade_7.4.8-7.4.9.pl +++ b/docs/upgrades/upgrade_7.4.8-7.4.9.pl @@ -12,7 +12,7 @@ use lib "../../lib"; use strict; use Getopt::Long; use WebGUI::Session; - +use WebGUI::ProfileField; my $toVersion = "7.4.9"; # make this match what version you're going to my $quiet; # this line required @@ -21,10 +21,12 @@ my $quiet; # this line required my $session = start(); # this line required removeOrphanedGroupings($session); # upgrade functions go here +fixDashboardContentPositions($session); finish($session); # this line required + #------------------------------------------------- sub removeOrphanedGroupings { my $session = shift; @@ -34,12 +36,33 @@ sub removeOrphanedGroupings { } -##------------------------------------------------- -#sub exampleFunction { -# my $session = shift; -# print "\tWe're doing some stuff here that you should know about.\n" unless ($quiet); -# # and here's our code -#} +#------------------------------------------------- +sub fixDashboardContentPositions { + my $session = shift; + my $db = $session->db; + print "\tFixing broken dashboard content positions.\n" unless ($quiet); + foreach my $dashboardId ($db->quickArray("select assetId from asset where className='WebGUI::Asset::Wobject::Dashboard'")) { + my $newContentPositionId = "contentPositions".$dashboardId; + $newContentPositionId =~ s/-/_/g; + my $newField = WebGUI::ProfileField->create($session, $newContentPositionId, { + label=>'\'Dashboard User Preference - Content Positions\'', + visible=>0, + protected=>1, + editable=>0, + required=>0, + fieldType=>'textarea' + }); + my $oldContentPositionId = $dashboardId."contentPositions"; + my $userPositioning = $db->read("select userId, `".$oldContentPositionId."` from userProfileData"); + while (my ($userId, $positions) = $userPositioning->array) { + $db->write("update userProfileData set $newContentPositionId = ? where userId=?", [$positions, $userId]); + } + my $oldField = WebGUI::ProfileField->new($session, $oldContentPositionId); + if (defined $oldField) { + $oldField->delete; + } + } +} diff --git a/lib/WebGUI/Asset/Wobject/Dashboard.pm b/lib/WebGUI/Asset/Wobject/Dashboard.pm index 51b5a8921..6137f00e3 100644 --- a/lib/WebGUI/Asset/Wobject/Dashboard.pm +++ b/lib/WebGUI/Asset/Wobject/Dashboard.pm @@ -95,15 +95,29 @@ sub definition { return $class->SUPER::definition($session, $definition); } +#------------------------------------------------------------------- +sub discernUserId { + my $self = shift; + return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId; +} + #------------------------------------------------------------------- sub getContentPositions { my $self = shift; my $dummy = $self->initialize unless $self->get("isInitialized"); my $u = WebGUI::User->new($self->session, $self->discernUserId); - return $u->profileField($self->getId.'contentPositions') + return $u->profileField($self->getContentPositionsId) || $self->getContentPositionsDefault; } +#------------------------------------------------------------------- +sub getContentPositionsId { + my $self = shift; + my $id = "contentPositions".$self->getId; + $id =~ s/-/_/g; + return $id; +} + #------------------------------------------------------------------- =head2 getContentPositionsDefault ( ) @@ -117,13 +131,7 @@ sub getContentPositionsDefault { my $dummy = $self->initialize unless $self->get("isInitialized"); # The default positions are saved under the "Visitor" user my $u = WebGUI::User->new($self->session, 1); - return $u->profileField($self->getId.'contentPositions'); -} - -#------------------------------------------------------------------- -sub discernUserId { - my $self = shift; - return ($self->canManage && $self->session->var->isAdminOn) ? '1' : $self->session->user->userId; + return $u->profileField($self->getContentPositionsId); } #------------------------------------------------------------------- @@ -154,13 +162,13 @@ sub getEditForm { #------------------------------------------------------------------- sub initialize { my $self = shift; - my $userPrefField = WebGUI::ProfileField->create($self->session,$self->getId.'contentPositions',{ + my $userPrefField = WebGUI::ProfileField->create($self->session,$self->getContentPositionsId,{ label=>'\'Dashboard User Preference - Content Positions\'', visible=>0, protected=>1, editable=>0, required=>0, - fieldType=>'text' + fieldType=>'textarea' }); $self->update({isInitialized=>1}); } @@ -201,6 +209,17 @@ sub processPropertiesFromFormPost { } } +#------------------------------------------------------------------- +sub purge { + my $self = shift; + my $userPrefField = WebGUI::ProfileField->new($self->session,$self->getContentPositionsId); + if (defined $userPrefField) { + $userPrefField->delete; + } + $self->SUPER::purge(@_); +} + + #------------------------------------------------------------------- sub view { my $self = shift; @@ -309,7 +328,7 @@ sub www_setContentPositions { return 'empty' unless $self->get("isInitialized"); my $dummy = $self->initialize unless $self->get("isInitialized"); my $u = WebGUI::User->new($self->session, $self->discernUserId); - my $success = $u->profileField($self->getId.'contentPositions',$self->session->form->process("map")) eq $self->session->form->process("map"); + my $success = $u->profileField($self->getContentPositionsId,$self->session->form->process("map")) eq $self->session->form->process("map"); return "Map set: ".$self->session->form->process("map") if $success; return "Map failed to set."; }