Polls now use JSON instead of Storable to store graph info because Storable is not portable between OS/processors.

This commit is contained in:
Doug Bell 2007-08-14 17:07:28 +00:00
parent a2e3b54eb7
commit 8b8feb6af3
4 changed files with 128 additions and 24 deletions

View file

@ -2,6 +2,7 @@
- Data Forms set reply to to the same as the from field
- Config file bugs fixed, see gotcha.txt for details.
- Added export to context menu in asset manager
- Polls now use JSON instead of Storable to serialize graph config
7.4.2

View file

@ -13,6 +13,14 @@ save you many hours of grief.
* You must upgrade to Config::JSON 1.1.0 or higher prior to upgrading.
Due to a bug in CPAN you should type "force install Config::JSON" in
order to upgrade to this version.
* For Poll Wobjects, we're using a new way to store the graph
configuration. If you were having problems with your Poll graphs,
you will need to re-create the graph's configuration. It may not
be possible to read your graph configuration, so if you have
problems with the Poll graphs you will need to re-create the graph's
configuration. After you create a new configuration, everything will
work fine.
7.4.0

View file

@ -21,6 +21,7 @@ my $quiet; # this line required
my $session = start(); # this line required
# upgrade functions go here
reserializePollGraphConfigs($session);
finish($session); # this line required
@ -32,6 +33,41 @@ finish($session); # this line required
# # and here's our code
#}
#-------------------------------------------------
sub reserializePollGraphConfigs {
my $session = shift;
print "\tRe-serializing Poll Graph configuration... " unless ($quiet);
use Storable;
$Storable::canonical = 1;
use JSON;
my $sth = $session->db->read(
"SELECT assetId, revisionDate, graphConfiguration FROM Poll"
);
while (my %data = $sth->hash) {
next unless $data{graphConfiguration};
my ($assetId, $revisionDate, $graphConfiguration)
= @data{'assetId', 'revisionDate', 'graphConfiguration'};
my $thawed = eval { Storable::thaw($graphConfiguration) };
if ($@) {
print "\n\t!!! Could not fix graph configuration for assetId '$assetId' revisionDate '$revisionDate' !!!";
next;
}
$graphConfiguration = objToJson( $thawed );
$session->db->write(
"UPDATE Poll SET graphConfiguration=? WHERE assetId=? AND revisionDate=?",
[$graphConfiguration, $assetId, $revisionDate],
);
}
print "OK!\n" unless $quiet;
}
# ---- DO NOT EDIT BELOW THIS LINE ----

View file

@ -21,7 +21,7 @@ use WebGUI::Utility;
use WebGUI::Asset::Wobject;
use WebGUI::Image::Graph;
use WebGUI::Storage::Image;
use Storable;
use JSON;
our @ISA = qw(WebGUI::Asset::Wobject);
@ -179,6 +179,23 @@ sub duplicate {
return $newAsset;
}
#----------------------------------------------------------------------------
=head2 freezeGraphConfig
Serializes graph configuration. Returns a scalar containing the serialized
structure.
=cut
sub freezeGraphConfig {
my $self = shift;
my $obj = shift;
return JSON::objToJson($obj);
}
#-------------------------------------------------------------------
sub getEditForm {
my $self = shift;
@ -254,10 +271,7 @@ sub getEditForm {
if (WebGUI::Image::Graph->getPluginList($self->session)) {
my $config = {};
if ($self->get('graphConfiguration')) {
$config = Storable::thaw($self->get('graphConfiguration'));
}
my $config = $self->getGraphConfig;
$tabform->addTab('graph', 'Graphing');
$tabform->getTab('graph')->yesNo(
@ -272,6 +286,23 @@ sub getEditForm {
return $tabform;
}
#----------------------------------------------------------------------------
=head2 getGraphConfig
Gets and thaws the graph configuration. Returns a reference to the original
data structure.
=cut
sub getGraphConfig {
my $self = shift;
my $config = $self->get("graphConfiguration");
return unless $config;
return $self->thawGraphConfig($config);
}
#-------------------------------------------------------------------
=head2 indexContent ( )
@ -316,7 +347,7 @@ sub processPropertiesFromFormPost {
if (WebGUI::Image::Graph->getPluginList($self->session)) {
my $graph = WebGUI::Image::Graph->processConfigurationForm($self->session);
$property->{graphConfiguration} = Storable::freeze($graph->getConfiguration);
$self->setGraphConfig( $graph->getConfiguration );
}
$self->update($property);
@ -331,6 +362,23 @@ sub purge {
$self->SUPER::purge();
}
#----------------------------------------------------------------------------
=head2 setGraphConfig
Freezes and stores the configuration for the graphing of this poll.
=cut
sub setGraphConfig {
my $self = shift;
my $obj = shift;
$self->update({
graphConfiguration => $self->freezeGraphConfig($obj),
});
}
#-------------------------------------------------------------------
sub setVote {
my $self = shift;
@ -341,6 +389,21 @@ sub setVote {
".$self->session->db->quote($answer).", ".$self->session->db->quote($userId).", '$ip')");
}
#----------------------------------------------------------------------------
=head2 thawGraphConfig
Deserializes the graph configuration and returns the data structure.
=cut
sub thawGraphConfig {
my $self = shift;
my $string = shift;
return JSON::jsonToObj($string);
}
#-------------------------------------------------------------------
sub view {
my $self = shift;
@ -387,27 +450,23 @@ sub view {
$var{answer_loop} = \@answers;
if ($self->getValue('generateGraph')) {
my $config = {};
if ($self->get('graphConfiguration')) {
$config = Storable::thaw($self->get('graphConfiguration'));
my $config = $self->getGraphConfig;
if ($config) {
my $graph = WebGUI::Image::Graph->loadByConfiguration($self->session, $config);
$graph->addDataset(\@dataset);
$graph->setLabels(\@labels);
if ($config) {
my $graph = WebGUI::Image::Graph->loadByConfiguration($self->session, $config);
$graph->addDataset(\@dataset);
$graph->setLabels(\@labels);
$graph->draw;
$graph->draw;
my $storage = WebGUI::Storage::Image->createTemp($self->session);
my $filename = 'poll'.$self->session->id->generate.".png";
$graph->saveToStorageLocation($storage, $filename);
my $storage = WebGUI::Storage::Image->createTemp($self->session);
my $filename = 'poll'.$self->session->id->generate.".png";
$graph->saveToStorageLocation($storage, $filename);
$var{graphUrl} = $storage->getUrl($filename);
$var{hasImageGraph} = 1;
} else {
$self->session->errorHandler->error('The graph configuration hash of the Poll ('.$self->getUrl.') is corrupt.');
}
}
$var{graphUrl} = $storage->getUrl($filename);
$var{hasImageGraph} = 1;
} else {
$self->session->errorHandler->error('The graph configuration hash of the Poll ('.$self->getUrl.') is corrupt.');
}
}
return $self->processTemplate(\%var,undef,$self->{_viewTemplate});