started migrating ems data

This commit is contained in:
JT Smith 2008-05-03 03:42:57 +00:00
parent 44c74c2299
commit 51019e5dca
3 changed files with 36 additions and 109 deletions

View file

@ -15,6 +15,7 @@ use WebGUI::Session;
use WebGUI::Storage;
use WebGUI::Asset;
use WebGUI::Asset::Sku::Product;
use WebGUI::Workflow;
use File::Find;
use File::Spec;
@ -57,7 +58,7 @@ finish($session); # this line required
#----------------------------------------------------------------------------
sub addCoupon {
my $session = shift;
print "\tAdding Coupons" unless $quiet;
print "\tAdding Coupons... " unless $quiet;
$session->db->write(q{
create table FlatDiscount (
@ -109,7 +110,7 @@ sub addArchiveEnabledToCollaboration {
#----------------------------------------------------------------------------
sub addShelf {
my $session = shift;
print "\tAdding Shelves" unless $quiet;
print "\tAdding Shelves... " unless $quiet;
$session->db->write(q{
create table Shelf (
@ -326,10 +327,38 @@ sub upgradeEMS {
price float not null default 0.00,
primary key (assetId, revisionDate)
)");
print "\t\tMigrating workflow activities.\n" unless ($quiet);
$session->config->addToArray("workflowActivities/None","WebGUI::Workflow::Activity::ExpireEmsCartItems");
print "\t\tMigrating old EMS data.\n" unless ($quiet);
#$db->write("alter table EventManagementSystem_metaData rename EMSEventMetaData");
$db->write("delete from WorkflowActivity where workflowId=?",['EMSworkflow00000000001']); # file no longer exists so must get rid of this entry manually
my $workflow = WebGUI::Workflow->new($session, 'EMSworkflow00000000001');
if (defined $workflow) {
$workflow->delete;
}
unlink($session->config->getWebguiRoot.'/lib/WebGUI/Workflow/Activity/CacheEMSPrereqs.pm');
my %oldRibbons = ();
my %newRibbons = ();
print "\t\tMigrating old EMS data.\n" unless ($quiet);
my $emsResults = $db->read("select assetId from asset where className='WebGUI::Asset::Wobject::EventManagementSystem'");
while (my ($emsId) = $emsResults->array) {
my $ems = WebGUI::Asset::Wobject::EventManagementSystem->new($session, $emsId);
my $ribbonResults = $db->read("select * from EventManagementSystem_discountPasses left join EventManagementSystem_products using (passId) left join products using (productId) where assetId=?",[$emsId]);
print "\t\t\tMigrating old ribbons for $emsId.\n" unless ($quiet);
while (my $ribbonData = $ribbonResults->hashRef) {
my $ribbon = $ems->addChild({
className => 'WebGUI::Asset::Sku::Ribbon',
title => $ribbonData->{title},
description => $ribbonData->{description},
sku => $ribbonData->{sku},
price => $ribbonData->{price},
seatsAvailable => $ribbonData->{maximumAttendees},
});
$oldRibbons{$ribbonData->{passId}} = $ribbon->getId;
$newRibbons{$ribbon->getId} = $ribbonData->{passId};
}
}
}

View file

@ -208,7 +208,8 @@ The unique id of the activity.
sub getActivity {
my $self = shift;
my $activityId = shift;
return WebGUI::Workflow::Activity->new($self->session, $activityId);
my $activity = WebGUI::Workflow::Activity->new($self->session, $activityId);
return $activity;
}
#-------------------------------------------------------------------

View file

@ -1,103 +0,0 @@
package WebGUI::Workflow::Activity::CacheEMSPrereqs;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2008 Plain Black Corporation.
-------------------------------------------------------------------
Please read the legal notices (docs/legal.txt) and the license
(docs/license.txt) that came with this distribution before using
this software.
-------------------------------------------------------------------
http://www.plainblack.com info@plainblack.com
-------------------------------------------------------------------
=cut
use strict;
use WebGUI::Asset;
use WebGUI::Cache;
use WebGUI::International;
use base 'WebGUI::Workflow::Activity';
=head1 NAME
Package WebGUI::Workflow::Activity::CacheEMSPrereqs
=head1 DESCRIPTION
Tell a little about what this activity does.
=head1 SYNOPSIS
See WebGUI::Workflow::Activity for details on how to use any activity.
=head1 METHODS
These methods are available from this class:
=cut
#-------------------------------------------------------------------
=head2 definition ( session, definition )
See WebGUI::Workflow::Activity::definition() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_CacheEMSPrereqs");
push(@{$definition}, {
name=>$i18n->get('activityName'),
properties=> { }
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $object = shift;
my $instance = shift;
my ($emsId) = $self->session->db->quickArray("select assetId from asset where className='WebGUI::Asset::Wobject::EventManagementSystem' limit 1");
return $self->COMPLETE unless $emsId;
my $ems = WebGUI::Asset->newByDynamicClass($self->session,$emsId);
my $start = time();
my $leftOff = $instance->getScratch("emsleftoff");
my $skip = ($leftOff ne "") ? 1 : 0;
WebGUI::Cache->new($self->session)->deleteChunk(["gAPRE"]) unless ($skip);
my $status = $self->COMPLETE;
my @events = $self->session->db->buildArray("select distinct(prerequisiteId) from EventManagementSystem_products");
foreach my $event (@events) {
$skip = 0 if ($leftOff eq $event);
next if $skip;
if ((time() - $start) > 60) { # give up so something else can run for a while
$instance->setScratch("emsleftoff",$event);
$status = $self->WAITING;
last;
}
$ems->getAllPossibleRequiredEvents($event) if $event;
}
$self->session->errorHandler->warn('EMS Cacher Ran! Status: '.$status);
return $status;
}
1;