diff --git a/docs/changelog/6.x.x.txt b/docs/changelog/6.x.x.txt index 7d73bd77a..9f86bc288 100644 --- a/docs/changelog/6.x.x.txt +++ b/docs/changelog/6.x.x.txt @@ -95,6 +95,9 @@ - Fixed a bug in the HTMLArea image manager that would not allow users to upload files if the gateway script was not at /index.pl - bugfix [1008283]. Add new user not working for secondary admin (Leendert Bottelberghs). + - bugfix [ 1014337 ] WSClient->new error: templateId field missing in + database + - bugfix [ 991782 ] More Fault Tolerent upgrade_5.9.9-6.0.0.pl diff --git a/docs/upgrades/upgrade_5.9.9-6.0.0.pl b/docs/upgrades/upgrade_5.9.9-6.0.0.pl index bca3399c4..8e42d2e5e 100644 --- a/docs/upgrades/upgrade_5.9.9-6.0.0.pl +++ b/docs/upgrades/upgrade_5.9.9-6.0.0.pl @@ -15,490 +15,6 @@ GetOptions( 'configFile=s'=>\$configFile, 'quiet'=>\$quiet ); -WebGUI::Session::open("../..",$configFile); - - -#-------------------------------------------- -print "\tMigrating styles.\n" unless ($quiet); -my $sth = WebGUI::SQL->read("select * from style"); -while (my $style = $sth->hashRef) { - if ($style->{styleId} == 3) { - $style->{body} =~ s/styles\/plainblack\/logo-white\.gif/plainblack.gif/ixsg; - $style->{body} =~ s/2001-2002/2001-2004/ixsg; - $style->{body} =~ s/Plain\s+Black\s+Software/Plain Black Corporation/ixsg; - } - my ($header,$footer) = split(/\^\-\;/,$style->{body}); - my ($newStyleId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='style'"); - if ($style->{styleId} > 0 && $style->{styleId} < 25) { - $newStyleId = $style->{styleId}; - } elsif ($newStyleId > 999) { - $newStyleId++; - } else { - $newStyleId = 1000; - } - my $newStyle = $session{setting}{docTypeDec}.' - - - <tmpl_var session.page.title> - <tmpl_var session.setting.companyName> - - '.$style->{styleSheet}.' - - '.$header.' - - '.$footer.' - - '; - WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values (".$newStyleId.", - ".quote($style->{name}).", ".quote($newStyle).", 'style')"); - WebGUI::SQL->write("update page set styleId=".$newStyleId." where styleId=".$style->{styleId}); - WebGUI::SQL->write("update themeComponent set id=".$newStyleId.", type='template' where id=".$style->{styleId}." and type='style'"); -} -$sth->finish; -WebGUI::SQL->write("delete from incrementer where incrementerId='styleId'"); -WebGUI::SQL->write("delete from settings where name='docTypeDec'"); -WebGUI::SQL->write("drop table style"); -WebGUI::SQL->write("alter table template add column isEditable int not null default 1"); -WebGUI::SQL->write("alter table template add column showInForms int not null default 1"); -WebGUI::SQL->write("update template set showInForms=0 where namespace='style' and templateId=10"); -WebGUI::SQL->write("update template set isEditable=0, showInForms=0 where namespace='style' and templateId in (1,2,4,5)"); -WebGUI::SQL->write("insert into template (templateId, name, template, namespace, isEditable, showInForms) values (6,'Empty','','style',0,0)"); - -my @templateManagers = WebGUI::SQL->buildArray("select userId from groupings where groupId=8"); -my $clause; -if ($#templateManagers > -1) { - $clause = "and userId not in (".join(",",@templateManagers).")"; -} -$sth = WebGUI::SQL->read("select userId,expireDate,groupAdmin from groupings where groupId=5 ".$clause); -while (my $user = $sth->hashRef) { - WebGUI::SQL->write("insert into groupings (groupId,userId,expireDate,groupAdmin) values (8, ".$user->{userId}.", - ".$user->{expireDate}.", ".$user->{groupAdmin}.")"); -} -$sth->finish; -WebGUI::SQL->write("delete from groups where groupId=5"); -WebGUI::SQL->write("delete from groupings where groupId=5"); - - -#-------------------------------------------- -print "\tMigrating extra columns to page templates.\n" unless ($quiet); -my $a = WebGUI::SQL->read("select a.wobjectId, a.templatePosition, a.sequenceNumber, a.pageId, b.templateId, c.width, c.class, c.spacer from wobject a - , page b , ExtraColumn c where a.pageId=b.pageId and a.wobjectId=c.wobjectId and a.namespace='ExtraColumn'"); -while (my $data = $a->hashRef) { - my ($template, $name) = WebGUI::SQL->quickArray("select template,name from template where namespace='Page' and templateId=".$data->{templateId}); - $name .= " w/ Extra Column"; - #eliminate the need for compatibility with old-style page templates - $template =~ s/\^(\d+)\;/_positionFormat5x($1)/eg; - my $i = 1; - while ($template =~ m/page\.position$i/) { - $i++; - } - my $position = $i; - my $replacement = '{templatePosition}.'>'; - my $spliton = "{templatePosition}.">"; - my @parts = split(/$spliton/, $template); - $template = $parts[0].$replacement.$parts[1]; - my ($id) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Page'"); - $id++; - WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values ($id, ".quote($name).", ".quote($template).", 'Page')"); - WebGUI::SQL->write("update page set templateId=$id where pageId=".$data->{pageId}); - WebGUI::SQL->write("update wobject set templatePosition=".$position." where pageId=".$data->{pageId}." and templatePosition=". - $data->{templatePosition}." and sequenceNumber>".$data->{sequenceNumber}); - WebGUI::SQL->write("delete from wobject where wobjectId=".$data->{wobjectId}); - my $b = WebGUI::SQL->read("select wobjectId from wobject where pageId=".$data->{pageId}." order by templatePosition,sequenceNumber"); - my $i = 0; - while (my ($wid) = $b->array) { - $i++; - WebGUI::SQL->write("update wobject set sequenceNumber='$i' where wobjectId=$wid"); - } - $b->finish; -} -$a->finish; -WebGUI::SQL->write("drop table ExtraColumn"); - - -#-------------------------------------------- -print "\tMigrating page templates.\n" unless ($quiet); -my $sth = WebGUI::SQL->read("select * from template where namespace='Page'"); -while (my $template = $sth->hashRef) { - #eliminate the need for compatibility with old-style page templates - $template->{template} =~ s/\^(\d+)\;/_positionFormat5x($1)/eg; - $template->{template} = ' - - - - - - - '.$template->{template}; - $template->{template} =~ s/\/_positionFormat6x($1)/eg; - $template->{template} .= ' - - - - - - -
- - -
- '; - WebGUI::SQL->write("update template set namespace='page', template=".quote($template->{template}) - ." where templateId=".$template->{templateId}." and namespace='Page'"); -} -$sth->finish; - - -#-------------------------------------------- -print "\tUpdating SQL Reports.\n" unless ($quiet); -my %dblink; -$dblink{$session{config}{dsn}}{id} = 0; -$dblink{$session{config}{dsn}}{user} = $session{config}{dbuser}; -my $sth = WebGUI::SQL->read("select DSN, databaseLinkId, username, identifier, wobjectId from SQLReport"); -while (my $data = $sth->hashRef) { - my $id = undef; - next if ($data->{databaseLinkId} > 0); - foreach my $dsn (keys %dblink) { - if ($dsn eq $data->{DSN} && $dblink{$dsn}{user} eq $data->{username}) { - $id = $dblink{$dsn}{id}; - last; - } - } - unless (defined $id) { - $id = getNextId("databaseLinkId"); - my $title = $data->{username}.'@'.$data->{DSN}; - WebGUI::SQL->write("insert into databaseLink (databaseLinkId, title, DSN, username, identifier) values ($id, ".quote($title).", - ".quote($data->{DSN}).", ".quote($data->{username}).", ".quote($data->{identifier}).")"); - $dblink{$data->{DSN}}{id} = $id; - $dblink{$data->{DSN}}{user} = $data->{username}; - } - WebGUI::SQL->write("update SQLReport set databaseLinkId=".$id." where wobjectId=".$data->{wobjectId}); -} -$sth->finish; -WebGUI::SQL->write("alter table SQLReport drop column DSN"); -WebGUI::SQL->write("alter table SQLReport drop column username"); -WebGUI::SQL->write("alter table SQLReport drop column identifier"); -use WebGUI::DatabaseLink; -my $templateId; -my $a = WebGUI::SQL->read("select a.databaseLinkId, a.dbQuery, a.template, a.wobjectId, b.title - from SQLReport a , wobject b where a.wobjectId=b.wobjectId"); -while (my $data = $a->hashRef) { - next if ($data->{dbQuery} eq ""); - my $db = WebGUI::DatabaseLink->new($data->{databaseLinkId}); - if ($data->{template} ne "") { - ($templateId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='SQLReport'"); - if ($templateId > 999) { - $templateId++; - } else { - $templateId = 1000; - } - my $b = WebGUI::SQL->unconditionalRead($data->{dbQuery},$db->dbh); - my @template = split(/\^\-\;/,$data->{template}); - my $final = ' -

-
- - -

- - - -

    - -
  • -
    -
-
- '.$template[0].' - '; - my $i; - unless ($b->errorCode) { - foreach my $col ($b->getColumnNames) { - my $replacement = ''; - $template[1] =~ s/\^$i\;/$replacement/g; - $i++; - } - } - $template[1] =~ s/\^rownum\;/\/g; - $final .= $template[1].' - - '.$template[2].' - - - '; - WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values ($templateId, - ".quote($data->{title}).",".quote($final).",'SQLReport')"); - } else { - $templateId = 1; - } - WebGUI::SQL->write("update wobject set templateId=$templateId where wobjectId=".$data->{wobjectId}); -} -$a->finish; -WebGUI::SQL->write("alter table SQLReport drop column template"); -WebGUI::SQL->write("alter table SQLReport drop column convertCarriageReturns"); - - -#-------------------------------------------- -print "\tConverting items into articles.\n" unless ($quiet); -my $sth = WebGUI::SQL->read("select * from template where namespace='Item'"); -while (my $template = $sth->hashRef) { - $template->{name} =~ s/Default (.*?)/$1/i; - if ($template->{templateId} < 1000) { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Article' and templateId<1000"); - $template->{templateId}++; - } else { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Article'"); - if ($template->{templateId} > 999) { - $template->{templateId}++; - } else { - $template->{templateId} = 1000; - } - } - WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", - ".quote($template->{name}).", ".quote($template->{template}).", 'Article')"); -} -$sth->finish; -WebGUI::SQL->write("delete from template where namespace='Item'"); -WebGUI::SQL->write("update wobject set namespace='Article' where namespace='Item'"); -my $sth = WebGUI::SQL->read("select * from Item"); -while (my $data = $sth->hashRef) { - WebGUI::SQL->write("insert into Article (wobjectId,linkURL,attachment) values (".$data->{wobjectId}.", - ".quote($data->{linkURL}).", ".quote($data->{attachment}).")"); -} -$sth->finish; -WebGUI::SQL->write("drop table Item"); - - -#-------------------------------------------- -print "\tSequencing user submissions.\n" unless ($quiet); -WebGUI::SQL->write("alter table USS_submission add column sequenceNumber int not null"); -WebGUI::SQL->write("alter table USS add column USS_id int not null"); -WebGUI::SQL->write("alter table USS_submission add column USS_id int not null"); -my $ussId = 1000; -my $a = WebGUI::SQL->read("select wobjectId from USS"); -while (my ($wobjectId) = $a->array) { - WebGUI::SQL->write("update USS set USS_id=$ussId where wobjectId=$wobjectId"); - my $b = WebGUI::SQL->read("select USS_submissionId from USS_submission where wobjectId=$wobjectId order by dateSubmitted"); - my $seq = 1; - while (my ($subId) = $b->array) { - WebGUI::SQL->write("update USS_submission set sequenceNumber=$seq, USS_id=$ussId where USS_submissionId=$subId"); - $seq++; - } - $b->finish; - $ussId++; -} -$a->finish; -WebGUI::SQL->write("alter table USS_submission drop column wobjectId"); -WebGUI::SQL->write("alter table USS add column submissionFormTemplateId int not null default 1"); -WebGUI::SQL->write("alter table USS_submission add column contentType varchar(35) not null default 'mixed'"); -WebGUI::SQL->write("update USS_submission set contentType='html' where convertCarriageReturns=0"); -WebGUI::SQL->write("alter table USS_submission drop column convertCarriageReturns"); -WebGUI::SQL->write("insert into incrementer (incrementerId,nextValue) values ('USS_id',$ussId)"); -WebGUI::SQL->write("alter table USS_submission add column userDefined1 text"); -WebGUI::SQL->write("alter table USS_submission add column userDefined2 text"); -WebGUI::SQL->write("alter table USS_submission add column userDefined3 text"); -WebGUI::SQL->write("alter table USS_submission add column userDefined4 text"); -WebGUI::SQL->write("alter table USS_submission add column userDefined5 text"); - - -#-------------------------------------------- -print "\tConverting FAQs into USS Submissions.\n" unless ($quiet); -my %tempMatch = (); -my $sth = WebGUI::SQL->read("select * from template where namespace='FAQ'"); -while (my $template = $sth->hashRef) { - my $oldTid = $template->{templateId}; - $template->{name} =~ s/Default (.*?)/$1/i; - if ($template->{templateId} < 1000) { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS' and templateId<1000"); - $template->{templateId}++; - } else { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS'"); - if ($template->{templateId} > 999) { - $template->{templateId}++; - } else { - $template->{templateId} = 1000; - } - } - $tempMatch{$oldTid} = $template->{templateId}; - $template->{template} =~ s/\/\/igs; - my $replacement = ' - - [] - - - - - '; - $template->{template} =~ s/\\s*\\s*\<\/tmpl_if\>/$replacement/igs; - $replacement = ' - '; - $template->{template} =~ s/\\s*\"\>/$replacement/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", - ".quote($template->{name}).", ".quote($template->{template}).", 'USS')"); -} -$sth->finish; -foreach my $oldTid (keys %tempMatch) { - WebGUI::SQL->write("update wobject set templateId=".$tempMatch{$oldTid}." where templateId=".$oldTid." and namespace='FAQ'"); -} -WebGUI::SQL->write("delete from template where namespace='FAQ'"); -my $a = WebGUI::SQL->read("select a.wobjectId,a.groupIdEdit,a.ownerId,a.lastEdited,b.username,a.dateAdded from wobject a left join users b on - a.ownerId=b.userId where a.namespace='FAQ'"); -while (my $data = $a->hashRef) { - $data->{lastEdited} = 0 unless ($data->{lastEdited}); - $ussId = getNextId("USS_id"); - WebGUI::SQL->write("insert into USS (wobjectId, USS_id, groupToContribute, submissionsPerPage, filterContent, sortBy, sortOrder, - submissionFormTemplateId) values ( - ".$data->{wobjectId}.", $ussId, ".$data->{groupIdEdit}.", 1000, 'none', 'sequenceNumber', 'asc', 2)"); - my $b = WebGUI::SQL->read("select * from FAQ_question where wobjectId=".$data->{wobjectId}); - while (my $sub = $b->hashRef) { - my $subId = getNextId("USS_submissionId"); - my $forum = WebGUI::Forum->create({}); - WebGUI::SQL->write("insert into USS_submission (USS_submissionId, USS_id, title, username, userId, content, - dateUpdated, dateSubmitted, forumId,contentType) values ( $subId, $ussId, ".quote($sub->{question}).", - ".quote($data->{username}).", ".$data->{ownerId}.", ".quote($sub->{answer}).", ".$data->{lastEdited}.", - ".$data->{dateAdded}.", ".$forum->get("forumId").", 'html')"); - } - $b->finish; -} -$a->finish; -WebGUI::SQL->write("update wobject set namespace='USS' where namespace='FAQ'"); -WebGUI::SQL->write("drop table FAQ"); -WebGUI::SQL->write("drop table FAQ_question"); -WebGUI::SQL->write("delete from incrementer where incrementerId='FAQ_questionId'"); - - -#-------------------------------------------- -print "\tMigrating Link Lists to USS Submissions.\n" unless ($quiet); -my %tempMatch = (); -my $sth = WebGUI::SQL->read("select * from template where namespace='LinkList'"); -while (my $template = $sth->hashRef) { - my $oldTid = $template->{templateId}; - $template->{name} =~ s/Default (.*?)/$1/i; - if ($template->{templateId} < 1000) { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS' and templateId<1000"); - $template->{templateId}++; - } else { - ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS'"); - if ($template->{templateId} > 999) { - $template->{templateId}++; - } else { - $template->{templateId} = 1000; - } - } - $tempMatch{$oldTid} = $template->{templateId}; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\//igs; - $template->{template} =~ s/\<\/tmpl\_if\>\s*\<\/tmpl\_if\>/\<\/tmpl_if>/igs; - my $replacement = ' - - [] - - - - '; - $template->{template} =~ s/\\s*\\s*/$replacement/igs; - $replacement = ' - '; - $template->{template} =~ s/\\s*\"\>/$replacement/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - $template->{template} =~ s/\/\/igs; - WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", - ".quote($template->{name}).", ".quote($template->{template}).", 'USS')"); -} -$sth->finish; -foreach my $oldTid (keys %tempMatch) { - WebGUI::SQL->write("update wobject set templateId=".$tempMatch{$oldTid}." where templateId=".$oldTid." and namespace='LinkList'"); -} -WebGUI::SQL->write("delete from template where namespace='LinkList'"); -my $a = WebGUI::SQL->read("select a.wobjectId,a.groupIdEdit,a.ownerId,a.lastEdited,b.username,a.dateAdded from wobject a left join users b on - a.ownerId=b.userId where a.namespace='LinkList'"); -while (my $data = $a->hashRef) { - $data->{lastEdited} = 0 unless ($data->{lastEdited}); - $ussId = getNextId("USS_id"); - WebGUI::SQL->write("insert into USS (wobjectId, USS_id, groupToContribute, submissionsPerPage, filterContent, sortBy, sortOrder, - submissionFormTemplateId) values ( - ".$data->{wobjectId}.", $ussId, ".$data->{groupIdEdit}.", 1000, 'none', 'sequenceNumber', 'asc', 3)"); - my $b = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$data->{wobjectId}); - while (my $sub = $b->hashRef) { - my $subId = getNextId("USS_submissionId"); - my $forum = WebGUI::Forum->create({}); - WebGUI::SQL->write("insert into USS_submission (USS_submissionId, USS_id, title, username, userId, content, - dateUpdated, dateSubmitted, forumId,contentType,userDefined1, userDefined2) values ( $subId, $ussId, ".quote($sub->{name}).", - ".quote($data->{username}).", ".$data->{ownerId}.", ".quote($sub->{description}).", ".$data->{lastEdited}.", - ".$data->{dateAdded}.", ".$forum->get("forumId").", 'html', ".quote($sub->{url}).", ".quote($sub->{newWindow}).")"); - } - $b->finish; -} -$a->finish; -WebGUI::SQL->write("update wobject set namespace='USS' where namespace='LinkList'"); -WebGUI::SQL->write("drop table LinkList"); -WebGUI::SQL->write("drop table LinkList_link"); -WebGUI::SQL->write("delete from incrementer where incrementerId='LinkList_linkId'"); - - #-------------------------------------------- print "\tUpdating config file.\n" unless ($quiet); @@ -540,14 +56,532 @@ foreach my $wobject (@{$wobjects}) { push(@newWobjects,$wobject); } } -push(@newWobjects,"IndexedSearch"); -push(@newWobjects,"WSClient"); +unless (grep /^IndexedSearch$/, @newWobjects){ push(@newWobjects,"IndexedSearch"); } +unless (grep /^WSClient$/, @newWobjects){ push(@newWobjects,"WSClient"); } $conf->set("wobjects"=>\@newWobjects); $conf->set("emailRecoveryLoggingEnabled"=>1); $conf->set("passwordChangeLoggingEnabled"=>1); $conf->set("useSharedInternationalCache"=>1); $conf->write; +WebGUI::Session::open("../..",$configFile); + +# Find out what tables are available. +my @tables = WebGUI::SQL->buildArray("SHOW TABLES"); + +my $sth; +#-------------------------------------------- +print "\tMigrating styles.\n" unless ($quiet); +if ( grep /^style$/i, @tables ){ + $sth = WebGUI::SQL->read("select * from style"); + while (my $style = $sth->hashRef) { + if ($style->{styleId} == 3) { + $style->{body} =~ s/styles\/plainblack\/logo-white\.gif/plainblack.gif/ixsg; + $style->{body} =~ s/2001-2002/2001-2004/ixsg; + $style->{body} =~ s/Plain\s+Black\s+Software/Plain Black Corporation/ixsg; + } + my ($header,$footer) = split(/\^\-\;/,$style->{body}); + my ($newStyleId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='style'"); + if ($style->{styleId} > 0 && $style->{styleId} < 25) { + $newStyleId = $style->{styleId}; + } elsif ($newStyleId > 999) { + $newStyleId++; + } else { + $newStyleId = 1000; + } + my $newStyle = $session{setting}{docTypeDec}.' + + + <tmpl_var session.page.title> - <tmpl_var session.setting.companyName> + + '.$style->{styleSheet}.' + + '.$header.' + + '.$footer.' + + '; + WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values (".$newStyleId.", + ".quote($style->{name}).", ".quote($newStyle).", 'style')"); + WebGUI::SQL->write("update page set styleId=".$newStyleId." where styleId=".$style->{styleId}); + WebGUI::SQL->write("update themeComponent set id=".$newStyleId.", type='template' where id=".$style->{styleId}." and type='style'"); + } + $sth->finish; + WebGUI::SQL->write("delete from incrementer where incrementerId='styleId'"); + WebGUI::SQL->write("delete from settings where name='docTypeDec'"); + WebGUI::SQL->write("drop table style"); + WebGUI::SQL->write("alter table template add column isEditable int not null default 1"); + WebGUI::SQL->write("alter table template add column showInForms int not null default 1"); + WebGUI::SQL->write("update template set showInForms=0 where namespace='style' and templateId=10"); + WebGUI::SQL->write("update template set isEditable=0, showInForms=0 where namespace='style' and templateId in (1,2,4,5)"); + WebGUI::SQL->write("insert into template (templateId, name, template, namespace, isEditable, showInForms) values (6,'Empty','','style',0,0)"); + + my @templateManagers = WebGUI::SQL->buildArray("select userId from groupings where groupId=8"); + my $clause; + if ($#templateManagers > -1) { + $clause = "and userId not in (".join(",",@templateManagers).")"; + } + $sth = WebGUI::SQL->read("select userId,expireDate,groupAdmin from groupings where groupId=5 ".$clause); + while (my $user = $sth->hashRef) { + WebGUI::SQL->write("insert into groupings (groupId,userId,expireDate,groupAdmin) values (8, ".$user->{userId}.", + ".$user->{expireDate}.", ".$user->{groupAdmin}.")"); + } + $sth->finish; + WebGUI::SQL->write("delete from groups where groupId=5"); + WebGUI::SQL->write("delete from groupings where groupId=5"); +} else { + print "\t\tstyle table does not exist.\n" unless ($quiet); +} + + +#-------------------------------------------- +print "\tMigrating extra columns to page templates.\n" unless ($quiet); +if ( grep /^ExtraColumn$/i, @tables ){ + my $a = WebGUI::SQL->read("select a.wobjectId, a.templatePosition, a.sequenceNumber, a.pageId, b.templateId, c.width, c.class, c.spacer from wobject a + , page b , ExtraColumn c where a.pageId=b.pageId and a.wobjectId=c.wobjectId and a.namespace='ExtraColumn'"); + while (my $data = $a->hashRef) { + my ($template, $name) = WebGUI::SQL->quickArray("select template,name from template where namespace='Page' and templateId=".$data->{templateId}); + $name .= " w/ Extra Column"; + #eliminate the need for compatibility with old-style page templates + $template =~ s/\^(\d+)\;/_positionFormat5x($1)/eg; + my $i = 1; + while ($template =~ m/page\.position$i/) { + $i++; + } + my $position = $i; + my $replacement = '{templatePosition}.'>'; + my $spliton = "{templatePosition}.">"; + my @parts = split(/$spliton/, $template); + $template = $parts[0].$replacement.$parts[1]; + my ($id) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Page'"); + $id++; + WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values ($id, ".quote($name).", ".quote($template).", 'Page')"); + WebGUI::SQL->write("update page set templateId=$id where pageId=".$data->{pageId}); + WebGUI::SQL->write("update wobject set templatePosition=".$position." where pageId=".$data->{pageId}." and templatePosition=". + $data->{templatePosition}." and sequenceNumber>".$data->{sequenceNumber}); + WebGUI::SQL->write("delete from wobject where wobjectId=".$data->{wobjectId}); + my $b = WebGUI::SQL->read("select wobjectId from wobject where pageId=".$data->{pageId}." order by templatePosition,sequenceNumber"); + my $i = 0; + while (my ($wid) = $b->array) { + $i++; + WebGUI::SQL->write("update wobject set sequenceNumber='$i' where wobjectId=$wid"); + } + $b->finish; + } + $a->finish; + WebGUI::SQL->write("drop table ExtraColumn"); +} else { + print "\t\tExtraColumn table does not exist.\n" unless ($quiet); +} + +#-------------------------------------------- +print "\tMigrating page templates.\n" unless ($quiet); +my $sth = WebGUI::SQL->read("select * from template where namespace='Page'"); +while (my $template = $sth->hashRef) { + #eliminate the need for compatibility with old-style page templates + $template->{template} =~ s/\^(\d+)\;/_positionFormat5x($1)/eg; + + unless ($template->{template} =~ m/draggable\.js/) { + $template->{template} = ' + + + + + + + '.$template->{template}; + + $template->{template} =~ s/\/_positionFormat6x($1)/eg; + $template->{template} .= ' + + + + + + +
+ + +
+ '; + WebGUI::SQL->write("update template set namespace='page', template=".quote($template->{template}) + ." where templateId=".$template->{templateId}." and namespace='Page'"); + } +} + $sth->finish; + + +#-------------------------------------------- +print "\tUpdating SQL Reports.\n" unless ($quiet); +if( grep /^identifier$/i, WebGUI::SQL->buildArray("SHOW COLUMNS FROM SQLReport") ){ + my %dblink; + $dblink{$session{config}{dsn}}{id} = 0; + $dblink{$session{config}{dsn}}{user} = $session{config}{dbuser}; + my $sth = WebGUI::SQL->read("select DSN, databaseLinkId, username, identifier, wobjectId from SQLReport"); + while (my $data = $sth->hashRef) { + my $id = undef; + next if ($data->{databaseLinkId} > 0); + foreach my $dsn (keys %dblink) { + if ($dsn eq $data->{DSN} && $dblink{$dsn}{user} eq $data->{username}) { + $id = $dblink{$dsn}{id}; + last; + } + } + unless (defined $id) { + $id = getNextId("databaseLinkId"); + my $title = $data->{username}.'@'.$data->{DSN}; + WebGUI::SQL->write("insert into databaseLink (databaseLinkId, title, DSN, username, identifier) values ($id, ".quote($title).", + ".quote($data->{DSN}).", ".quote($data->{username}).", ".quote($data->{identifier}).")"); + $dblink{$data->{DSN}}{id} = $id; + $dblink{$data->{DSN}}{user} = $data->{username}; + } + WebGUI::SQL->write("update SQLReport set databaseLinkId=".$id." where wobjectId=".$data->{wobjectId}); + } + $sth->finish; + WebGUI::SQL->write("alter table SQLReport drop column DSN"); + WebGUI::SQL->write("alter table SQLReport drop column username"); + WebGUI::SQL->write("alter table SQLReport drop column identifier"); +} else { + print "\t\tDSN mods already done.\n" unless ($quiet); +} + +if( grep /^template$/i, WebGUI::SQL->buildArray("SHOW COLUMNS FROM SQLReport") ){ + + use WebGUI::DatabaseLink; + my $templateId; + my $a = WebGUI::SQL->read("select a.databaseLinkId, a.dbQuery, a.template, a.wobjectId, b.title + from SQLReport a , wobject b where a.wobjectId=b.wobjectId"); + while (my $data = $a->hashRef) { + next if ($data->{dbQuery} eq ""); + my $db = WebGUI::DatabaseLink->new($data->{databaseLinkId}); + if ($data->{template} ne "") { + ($templateId) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='SQLReport'"); + if ($templateId > 999) { + $templateId++; + } else { + $templateId = 1000; + } + my $b = WebGUI::SQL->unconditionalRead($data->{dbQuery},$db->dbh); + my @template = split(/\^\-\;/,$data->{template}); + my $final = ' +

+
+ + +

+ + + +

    + +
  • +
    +
+
+ '.$template[0].' + '; + my $i; + unless ($b->errorCode) { + foreach my $col ($b->getColumnNames) { + my $replacement = ''; + $template[1] =~ s/\^$i\;/$replacement/g; + $i++; + } + } + $template[1] =~ s/\^rownum\;/\/g; + $final .= $template[1].' + + '.$template[2].' + + + '; + WebGUI::SQL->write("insert into template (templateId, name, template, namespace) values ($templateId, + ".quote($data->{title}).",".quote($final).",'SQLReport')"); + } else { + $templateId = 1; + } + WebGUI::SQL->write("update wobject set templateId=$templateId where wobjectId=".$data->{wobjectId}); + } + $a->finish; + WebGUI::SQL->write("alter table SQLReport drop column template"); + WebGUI::SQL->write("alter table SQLReport drop column convertCarriageReturns"); +} else { + print "\t\ttemplate mods already done.\n" unless ($quiet); +} + +#-------------------------------------------- +print "\tConverting items into articles.\n" unless ($quiet); +if ( grep /^Item$/i, @tables ){ + my $sth = WebGUI::SQL->read("select * from template where namespace='Item'"); + while (my $template = $sth->hashRef) { + $template->{name} =~ s/Default (.*?)/$1/i; + if ($template->{templateId} < 1000) { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Article' and templateId<1000"); + $template->{templateId}++; + } else { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='Article'"); + if ($template->{templateId} > 999) { + $template->{templateId}++; + } else { + $template->{templateId} = 1000; + } + } + WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", + ".quote($template->{name}).", ".quote($template->{template}).", 'Article')"); + } + $sth->finish; + WebGUI::SQL->write("delete from template where namespace='Item'"); + WebGUI::SQL->write("update wobject set namespace='Article' where namespace='Item'"); + my $sth = WebGUI::SQL->read("select * from Item"); + while (my $data = $sth->hashRef) { + WebGUI::SQL->write("insert into Article (wobjectId,linkURL,attachment) values (".$data->{wobjectId}.", + ".quote($data->{linkURL}).", ".quote($data->{attachment}).")"); + } + $sth->finish; + WebGUI::SQL->write("drop table Item"); +} else { + print "\t\tItems table does not exist.\n" unless ($quiet); +} + +#-------------------------------------------- +my $ussId = 1000; +print "\tSequencing user submissions.\n" unless ($quiet); +if( !(grep /^userDefined5$/, (WebGUI::SQL->buildArray("SHOW COLUMNS FROM USS_submission")) ) ){ + WebGUI::SQL->write("alter table USS_submission add column sequenceNumber int not null"); + WebGUI::SQL->write("alter table USS add column USS_id int not null"); + WebGUI::SQL->write("alter table USS_submission add column USS_id int not null"); + my $a = WebGUI::SQL->read("select wobjectId from USS"); + while (my ($wobjectId) = $a->array) { + WebGUI::SQL->write("update USS set USS_id=$ussId where wobjectId=$wobjectId"); + my $b = WebGUI::SQL->read("select USS_submissionId from USS_submission where wobjectId=$wobjectId order by dateSubmitted"); + my $seq = 1; + while (my ($subId) = $b->array) { + WebGUI::SQL->write("update USS_submission set sequenceNumber=$seq, USS_id=$ussId where USS_submissionId=$subId"); + $seq++; + } + $b->finish; + $ussId++; + } + $a->finish; + WebGUI::SQL->write("alter table USS_submission drop column wobjectId"); + WebGUI::SQL->write("alter table USS add column submissionFormTemplateId int not null default 1"); + WebGUI::SQL->write("alter table USS_submission add column contentType varchar(35) not null default 'mixed'"); + WebGUI::SQL->write("update USS_submission set contentType='html' where convertCarriageReturns=0"); + WebGUI::SQL->write("alter table USS_submission drop column convertCarriageReturns"); + WebGUI::SQL->write("insert into incrementer (incrementerId,nextValue) values ('USS_id',$ussId)"); + WebGUI::SQL->write("alter table USS_submission add column userDefined1 text"); + WebGUI::SQL->write("alter table USS_submission add column userDefined2 text"); + WebGUI::SQL->write("alter table USS_submission add column userDefined3 text"); + WebGUI::SQL->write("alter table USS_submission add column userDefined4 text"); + WebGUI::SQL->write("alter table USS_submission add column userDefined5 text"); +} else { + print "\t\tAlready Sequenced.\n" unless ($quiet); +} + +#-------------------------------------------- + print "\tConverting FAQs into USS Submissions.\n" unless ($quiet); +if ( grep /^FAQ$/i, @tables ){ + my %tempMatch = (); + my $sth = WebGUI::SQL->read("select * from template where namespace='FAQ'"); + while (my $template = $sth->hashRef) { + my $oldTid = $template->{templateId}; + $template->{name} =~ s/Default (.*?)/$1/i; + if ($template->{templateId} < 1000) { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS' and templateId<1000"); + $template->{templateId}++; + } else { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS'"); + if ($template->{templateId} > 999) { + $template->{templateId}++; + } else { + $template->{templateId} = 1000; + } + } + $tempMatch{$oldTid} = $template->{templateId}; + $template->{template} =~ s/\/\/igs; + my $replacement = ' + + [
] +
+ + + + '; + $template->{template} =~ s/\\s*\\s*\<\/tmpl_if\>/$replacement/igs; + $replacement = ' + '; + $template->{template} =~ s/\\s*\"\>/$replacement/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", + ".quote($template->{name}).", ".quote($template->{template}).", 'USS')"); + } + $sth->finish; + foreach my $oldTid (keys %tempMatch) { + WebGUI::SQL->write("update wobject set templateId=".$tempMatch{$oldTid}." where templateId=".$oldTid." and namespace='FAQ'"); + } + WebGUI::SQL->write("delete from template where namespace='FAQ'"); + my $a = WebGUI::SQL->read("select a.wobjectId,a.groupIdEdit,a.ownerId,a.lastEdited,b.username,a.dateAdded from wobject a left join users b on + a.ownerId=b.userId where a.namespace='FAQ'"); + while (my $data = $a->hashRef) { + $data->{lastEdited} = 0 unless ($data->{lastEdited}); + $ussId = getNextId("USS_id"); + WebGUI::SQL->write("insert into USS (wobjectId, USS_id, groupToContribute, submissionsPerPage, filterContent, sortBy, sortOrder, + submissionFormTemplateId) values ( + ".$data->{wobjectId}.", $ussId, ".$data->{groupIdEdit}.", 1000, 'none', 'sequenceNumber', 'asc', 2)"); + my $b = WebGUI::SQL->read("select * from FAQ_question where wobjectId=".$data->{wobjectId}); + while (my $sub = $b->hashRef) { + my $subId = getNextId("USS_submissionId"); + my $forum = WebGUI::Forum->create({}); + WebGUI::SQL->write("insert into USS_submission (USS_submissionId, USS_id, title, username, userId, content, + dateUpdated, dateSubmitted, forumId,contentType) values ( $subId, $ussId, ".quote($sub->{question}).", + ".quote($data->{username}).", ".$data->{ownerId}.", ".quote($sub->{answer}).", ".$data->{lastEdited}.", + ".$data->{dateAdded}.", ".$forum->get("forumId").", 'html')"); + } + $b->finish; + } + $a->finish; + WebGUI::SQL->write("update wobject set namespace='USS' where namespace='FAQ'"); + WebGUI::SQL->write("drop table FAQ"); + WebGUI::SQL->write("drop table FAQ_question"); + WebGUI::SQL->write("delete from incrementer where incrementerId='FAQ_questionId'"); +} else { + print "\t\tAlready converted.\n" unless ($quiet); +} + +#-------------------------------------------- +print "\tMigrating Link Lists to USS Submissions.\n" unless ($quiet); +if ( grep /^LinkList$/i, @tables ){ + my %tempMatch = (); + my $sth = WebGUI::SQL->read("select * from template where namespace='LinkList'"); + while (my $template = $sth->hashRef) { + my $oldTid = $template->{templateId}; + $template->{name} =~ s/Default (.*?)/$1/i; + if ($template->{templateId} < 1000) { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS' and templateId<1000"); + $template->{templateId}++; + } else { + ($template->{templateId}) = WebGUI::SQL->quickArray("select max(templateId) from template where namespace='USS'"); + if ($template->{templateId} > 999) { + $template->{templateId}++; + } else { + $template->{templateId} = 1000; + } + } + $tempMatch{$oldTid} = $template->{templateId}; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\//igs; + $template->{template} =~ s/\<\/tmpl\_if\>\s*\<\/tmpl\_if\>/\<\/tmpl_if>/igs; + my $replacement = ' + + [] + + + + '; + $template->{template} =~ s/\\s*\\s*/$replacement/igs; + $replacement = ' + '; + $template->{template} =~ s/\\s*\"\>/$replacement/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + $template->{template} =~ s/\/\/igs; + WebGUI::SQL->write("insert into template (templateId,name,template,namespace) values (".$template->{templateId}.", + ".quote($template->{name}).", ".quote($template->{template}).", 'USS')"); + } + $sth->finish; + foreach my $oldTid (keys %tempMatch) { + WebGUI::SQL->write("update wobject set templateId=".$tempMatch{$oldTid}." where templateId=".$oldTid." and namespace='LinkList'"); + } + WebGUI::SQL->write("delete from template where namespace='LinkList'"); + my $a = WebGUI::SQL->read("select a.wobjectId,a.groupIdEdit,a.ownerId,a.lastEdited,b.username,a.dateAdded from wobject a left join users b on + a.ownerId=b.userId where a.namespace='LinkList'"); + while (my $data = $a->hashRef) { + $data->{lastEdited} = 0 unless ($data->{lastEdited}); + $ussId = getNextId("USS_id"); + WebGUI::SQL->write("insert into USS (wobjectId, USS_id, groupToContribute, submissionsPerPage, filterContent, sortBy, sortOrder, + submissionFormTemplateId) values ( + ".$data->{wobjectId}.", $ussId, ".$data->{groupIdEdit}.", 1000, 'none', 'sequenceNumber', 'asc', 3)"); + my $b = WebGUI::SQL->read("select * from LinkList_link where wobjectId=".$data->{wobjectId}); + while (my $sub = $b->hashRef) { + my $subId = getNextId("USS_submissionId"); + my $forum = WebGUI::Forum->create({}); + WebGUI::SQL->write("insert into USS_submission (USS_submissionId, USS_id, title, username, userId, content, + dateUpdated, dateSubmitted, forumId,contentType,userDefined1, userDefined2) values ( $subId, $ussId, ".quote($sub->{name}).", + ".quote($data->{username}).", ".$data->{ownerId}.", ".quote($sub->{description}).", ".$data->{lastEdited}.", + ".$data->{dateAdded}.", ".$forum->get("forumId").", 'html', ".quote($sub->{url}).", ".quote($sub->{newWindow}).")"); + } + $b->finish; + } + $a->finish; + WebGUI::SQL->write("update wobject set namespace='USS' where namespace='LinkList'"); + WebGUI::SQL->write("drop table LinkList"); + WebGUI::SQL->write("drop table LinkList_link"); + WebGUI::SQL->write("delete from incrementer where incrementerId='LinkList_linkId'"); +} else { + print "\t\tLinkList table does not exist.\n" unless ($quiet); +} #-------------------------------------------- print "\tUpdating Authentication.\n" unless ($quiet); @@ -567,89 +601,98 @@ while (my $authHash = $authSth->hashRef){ #-------------------------------------------- print "\tRemoving unneeded files and directories.\n" unless ($quiet); -# can't delete macros and wobjects in this version or upgrade will fail. must delete in future release -#unlink("../../lib/WebGUI/Wobject/Item.pm"); -#unlink("../../lib/WebGUI/Wobject/LinkList.pm"); -#unlink("../../lib/WebGUI/Wobject/FAQ.pm"); -#unlink("../../lib/WebGUI/Wobject/ExtraColumn.pm"); -unlink("../../lib/WebGUI/Authentication.pm"); -unlink("../../lib/WebGUI/Operation/Account.pm"); -#unlink("../../lib/WebGUI/Macro/m_currentMenuHorizontal.pm"); -#unlink("../../lib/WebGUI/Macro/M_currentMenuVertical.pm"); -#unlink("../../lib/WebGUI/Macro/s_specificMenuHorizontal.pm"); -#unlink("../../lib/WebGUI/Macro/S_specificMenuVertical.pm"); -#unlink("../../lib/WebGUI/Macro/t_topMenuHorizontal.pm"); -#unlink("../../lib/WebGUI/Macro/T_topMenuVertical.pm"); -#unlink("../../lib/WebGUI/Macro/p_previousMenuHorizontal.pm"); -#unlink("../../lib/WebGUI/Macro/P_previousMenuVertical.pm"); -#unlink("../../lib/WebGUI/Macro/C_crumbTrail.pm"); -#unlink("../../lib/WebGUI/Macro/FlexMenu.pm"); -#unlink("../../lib/WebGUI/Macro/PreviousDropMenu.pm"); -#unlink("../../lib/WebGUI/Macro/Synopsis.pm"); -#unlink("../../lib/WebGUI/Macro/rootmenuHorizontal.pm"); -#unlink("../../lib/WebGUI/Macro/RootTab.pm"); -#unlink("../../lib/WebGUI/Macro/SpecificDropMenu.pm"); -#unlink("../../lib/WebGUI/Macro/TopDropMenu.pm"); -#unlink("../../lib/WebGUI/Macro/Question_search.pm"); -unlink("../../lib/WebGUI/Operation/Search.pm"); -rmtree("../../lib/WebGUI/Authentication"); -rmtree("../../www/extras/toolbar/default"); +my @unlinks = ( "../../lib/WebGUI/Wobject/Item.pm", \ + "../../lib/WebGUI/Wobject/LinkList.pm", \ + "../../lib/WebGUI/Wobject/FAQ.pm", \ + "../../lib/WebGUI/Wobject/ExtraColumn.pm", \ + "../../lib/WebGUI/Authentication.pm", \ + "../../lib/WebGUI/Operation/Account.pm", \ + "../../lib/WebGUI/Macro/m_currentMenuHorizontal.pm", \ + "../../lib/WebGUI/Macro/M_currentMenuVertical.pm", \ + "../../lib/WebGUI/Macro/s_specificMenuHorizontal.pm", \ + "../../lib/WebGUI/Macro/S_specificMenuVertical.pm", \ + "../../lib/WebGUI/Macro/t_topMenuHorizontal.pm", \ + "../../lib/WebGUI/Macro/T_topMenuVertical.pm", \ + "../../lib/WebGUI/Macro/p_previousMenuHorizontal.pm", \ + "../../lib/WebGUI/Macro/P_previousMenuVertical.pm", \ + "../../lib/WebGUI/Macro/C_crumbTrail.pm", \ + "../../lib/WebGUI/Macro/FlexMenu.pm", \ + "../../lib/WebGUI/Macro/PreviousDropMenu.pm", \ + "../../lib/WebGUI/Macro/Synopsis.pm", \ + "../../lib/WebGUI/Macro/rootmenuHorizontal.pm", \ + "../../lib/WebGUI/Macro/RootTab.pm", \ + "../../lib/WebGUI/Macro/SpecificDropMenu.pm", \ + "../../lib/WebGUI/Macro/TopDropMenu.pm", \ + "../../lib/WebGUI/Macro/Question_search.pm", \ + "../../lib/WebGUI/Operation/Search.pm" ); +unlink(@unlinks); +my @rmtrees = ( "../../lib/WebGUI/Authentication", \ + "../../www/extras/toolbar/default" ); +rmtree(@rmtrees); #-------------------------------------------- print "\tMigrating wobject privileges.\n" unless ($quiet); -WebGUI::SQL->write("alter table page add column wobjectPrivileges int not null default 0"); -WebGUI::SQL->write("update page set wobjectPrivileges=$session{setting}{wobjectPrivileges}"); -WebGUI::SQL->write("delete from settings where name='wobjectPrivileges'"); +if( !(grep /^wobjectPrivileges$/i, WebGUI::SQL->buildArray("SHOW COLUMNS FROM page")) ){ + WebGUI::SQL->write("alter table page add column wobjectPrivileges int not null default 0"); + WebGUI::SQL->write("update page set wobjectPrivileges=$session{setting}{wobjectPrivileges}"); + WebGUI::SQL->write("delete from settings where name='wobjectPrivileges'"); +} else { + print "\t\tMigration already done.\n" unless ($quiet); +} #-------------------------------------------- -print "\tMigrating surveys.\n" unless ($quiet); -WebGUI::SQL->write("alter table Survey_response rename Survey_questionResponse"); -WebGUI::SQL->write("update Survey_questionResponse set userId='1' where userId='c4ca4238'"); -WebGUI::SQL->write("alter table Survey_questionResponse drop primary key"); -WebGUI::SQL->write("alter table Survey_questionResponse add primary key (Survey_questionId, Survey_answerId, Survey_responseId)"); -WebGUI::SQL->write("create table Survey_response (Survey_id int, Survey_responseId int not null primary key, userId varchar(11), - username varchar(255), ipAddress varchar(15), startDate int, endDate int, isComplete int not null default 0)"); -my $a = WebGUI::SQL->read("select Survey_id from Survey"); -while (my ($surveyId) = $a->array) { - my $b = WebGUI::SQL->read("select distinct userId from Survey_questionResponse where Survey_id=$surveyId"); - while (my ($userId) = $b->array) { - my ($username,$ipAddress) = WebGUI::SQL->quickArray("select username,ipAddress from Survey_questionResponse where Survey_id=$surveyId and - userId=".quote($userId)); - WebGUI::SQL->write("insert into Survey_response (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values ($surveyId, - ".getNextId("Survey_responseId")." ,".quote($userId).", ".quote($username).", 1, ".quote($ipAddress).")"); +if( !(grep /^gotoQuestion$/i, WebGUI::SQL->buildArray("SHOW COLUMNS FROM Survey_question")) ){ + print "\tMigrating surveys.\n" unless ($quiet); + WebGUI::SQL->write("alter table Survey_response rename Survey_questionResponse"); + WebGUI::SQL->write("update Survey_questionResponse set userId='1' where userId='c4ca4238'"); + WebGUI::SQL->write("alter table Survey_questionResponse drop primary key"); + WebGUI::SQL->write("alter table Survey_questionResponse add primary key (Survey_questionId, Survey_answerId, Survey_responseId)"); + WebGUI::SQL->write("create table Survey_response (Survey_id int, Survey_responseId int not null primary key, userId varchar(11), + username varchar(255), ipAddress varchar(15), startDate int, endDate int, isComplete int not null default 0)"); + my $a = WebGUI::SQL->read("select Survey_id from Survey"); + while (my ($surveyId) = $a->array) { + my $b = WebGUI::SQL->read("select distinct userId from Survey_questionResponse where Survey_id=$surveyId"); + while (my ($userId) = $b->array) { + my ($username,$ipAddress) = WebGUI::SQL->quickArray("select username,ipAddress from Survey_questionResponse where Survey_id=$surveyId and + userId=".quote($userId)); + WebGUI::SQL->write("insert into Survey_response (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values ($surveyId, + ".getNextId("Survey_responseId")." ,".quote($userId).", ".quote($username).", 1, ".quote($ipAddress).")"); + } + $b->finish; + $b = WebGUI::SQL->read("select distinct ipAddress from Survey_questionResponse where Survey_id=$surveyId and userId='1'"); + while (my ($ipAddress) = $b->array) { + WebGUI::SQL->write("insert into Survey_response (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values ( + $surveyId, ".getNextId("Survey_responseId")." ,'1', 'Visitor', 1, ".quote($ipAddress).")"); + } + $b->finish; } - $b->finish; - $b = WebGUI::SQL->read("select distinct ipAddress from Survey_questionResponse where Survey_id=$surveyId and userId='1'"); - while (my ($ipAddress) = $b->array) { - WebGUI::SQL->write("insert into Survey_response (Survey_id, Survey_responseId, userId, username, isComplete, ipAddress) values ( - $surveyId, ".getNextId("Survey_responseId")." ,'1', 'Visitor', 1, ".quote($ipAddress).")"); + $a->finish; + $a = WebGUI::SQL->read("select Survey_id, Survey_responseId, userId, ipAddress from Survey_response"); + while (my $data = $a->hashRef) { + my ($end) = WebGUI::SQL->quickArray("select max(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}." + and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); + my ($start) = WebGUI::SQL->quickArray("select min(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}." + and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); + WebGUI::SQL->write("update Survey_response set startDate=$start, endDate=$end where Survey_responseId=".$data->{Survey_responseId}); + WebGUI::SQL->write("update Survey_questionResponse set Survey_responseId=".$data->{Survey_responseId}." where Survey_id=".$data->{Survey_id}." + and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); } - $b->finish; + $a->finish; + WebGUI::SQL->write("alter table Survey_questionResponse drop column userId"); + WebGUI::SQL->write("alter table Survey_questionResponse drop column username"); + WebGUI::SQL->write("alter table Survey_questionResponse drop column ipAddress"); + WebGUI::SQL->write("alter table Survey add column questionsPerPage int not null default 1"); + WebGUI::SQL->write("alter table Survey add column responseTemplateId int not null default 1"); + WebGUI::SQL->write("alter table Survey add column reportcardTemplateId int not null default 1"); + WebGUI::SQL->write("alter table Survey add column overviewTemplateId int not null default 1"); + WebGUI::SQL->write("alter table Survey add column maxResponsesPerUser int not null default 1"); + WebGUI::SQL->write("alter table Survey add column questionsPerResponse int not null default 9999999"); + WebGUI::SQL->write("alter table Survey_question add column gotoQuestion int"); +} else { + print "\t\tMigration already done.\n" unless ($quiet); } -$a->finish; -$a = WebGUI::SQL->read("select Survey_id, Survey_responseId, userId, ipAddress from Survey_response"); -while (my $data = $a->hashRef) { - my ($end) = WebGUI::SQL->quickArray("select max(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}." - and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); - my ($start) = WebGUI::SQL->quickArray("select min(dateOfResponse) from Survey_questionResponse where Survey_id=".$data->{Survey_id}." - and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); - WebGUI::SQL->write("update Survey_response set startDate=$start, endDate=$end where Survey_responseId=".$data->{Survey_responseId}); - WebGUI::SQL->write("update Survey_questionResponse set Survey_responseId=".$data->{Survey_responseId}." where Survey_id=".$data->{Survey_id}." - and ((userId=".quote($data->{userId})." and userId<>1) or (userId=1 and ipAddress=".quote($data->{ipAddress})."))"); -} -$a->finish; -WebGUI::SQL->write("alter table Survey_questionResponse drop column userId"); -WebGUI::SQL->write("alter table Survey_questionResponse drop column username"); -WebGUI::SQL->write("alter table Survey_questionResponse drop column ipAddress"); -WebGUI::SQL->write("alter table Survey add column questionsPerPage int not null default 1"); -WebGUI::SQL->write("alter table Survey add column responseTemplateId int not null default 1"); -WebGUI::SQL->write("alter table Survey add column reportcardTemplateId int not null default 1"); -WebGUI::SQL->write("alter table Survey add column overviewTemplateId int not null default 1"); -WebGUI::SQL->write("alter table Survey add column maxResponsesPerUser int not null default 1"); -WebGUI::SQL->write("alter table Survey add column questionsPerResponse int not null default 9999999"); -WebGUI::SQL->write("alter table Survey_question add column gotoQuestion int"); - + #-------------------------------------------- print "\tMigrating Navigation Macro's.\n" unless ($quiet); my %dbFields = ( @@ -841,8 +884,7 @@ $replace{'t'} = { my ($sth, $data, $code, $table, $column, %identifier); foreach $table (keys %dbFields){ - $sth = WebGUI::SQL->read("SELECT * FROM $table "); - die "Cannot read from table $table ".$! if ($!); + unless ($sth = WebGUI::SQL->read("SELECT * FROM $table")) {die "Cannot read from table $table ";} while ($data = $sth->hashRef){ foreach $column (@{$dbFields{$table}{fields}}){ $code = $data->{$column}; @@ -957,7 +999,7 @@ sub _positionFormat6x { sub addNavigation { my $properties = shift; # use Data::Dumper; print "\n\n". Dumper($properties); - my $navId = getNextId("navigationId"); + my $navId = (getNextId("navigationId") || WebGUI::SQL->quickArray("SELECT MAX(navigationId) FROM Navigation") + 1); my $identifier = $properties->{identifier}."_".$navId; WebGUI::SQL->write("INSERT INTO Navigation(navigationId, identifier) VALUES ($navId, ".quote($identifier).")"); my ($update, @set); diff --git a/lib/WebGUI/Wobject/WSClient.pm b/lib/WebGUI/Wobject/WSClient.pm index c865f4f0d..6806764cb 100644 --- a/lib/WebGUI/Wobject/WSClient.pm +++ b/lib/WebGUI/Wobject/WSClient.pm @@ -94,9 +94,6 @@ sub new { fieldType => 'text', defaultValue => $session{'config'}{'soapproxy'}, }, - templateId => { - defaultValue => 1, - }, uri => { fieldType => 'text', defaultValue => $session{'config'}{'soapuri'}