Merge branch 'master' into WebGUI8

This commit is contained in:
Graham Knop 2010-04-13 07:50:02 -05:00
commit 2400f19099
797 changed files with 33894 additions and 27196 deletions

View file

@ -71,7 +71,7 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $session = $self->session;
my $epoch = $self->session->datetime->time();
my $epoch = time();
my $getAnArchive = WebGUI::Asset::Wobject::StoryArchive->getIsa($session);
ARCHIVE: while (my $archive = $getAnArchive->()) {
next ARCHIVE unless $archive && $archive->get("archiveAfter");

View file

@ -72,7 +72,7 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $session = $self->session;
my $epoch = $session->datetime->time();
my $epoch = time();
my $getCs = WebGUI::Asset::Wobject::Collaboration->getIsa($session);
CS: while (1) {
my $cs = eval { $getCs->(); };

View file

@ -100,6 +100,7 @@ sub execute {
my $getCalendar = WebGUI::Asset::Wobject::Calendar->getIsa($session);
CALENDAR: while (my $calendar = $getCalendar->()) {
next unless defined $calendar;
my $calendarTitle = $calendar->getTitle;
my $calendarId = $calendar->getId;
if ( $calendar->get( "state" ) ne "published" ) {

View file

@ -115,7 +115,7 @@ sub execute {
# Stop if there are no records preceding ageToDelete
next USERLOOP unless @deleteTimes;
my $inTimes = WebGUI::SQL::quoteAndJoin( \@deleteTimes );
my $inTimes = $db->quoteAndJoin( \@deleteTimes );
$db->write( "DELETE FROM userLoginLog WHERE userId = ? AND timeStamp IN ($inTimes)", [$userId] );
} ## end while ( my (@userIdData) ...
} ## end else [ if ( not $self->get("retainLastAlways"...

View file

@ -0,0 +1,109 @@
package WebGUI::Workflow::Activity::CleanupEMSSubmissions;
=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 base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::International;
=head1 NAME
Package WebGUI::Workflow::Activity::CleanupEMSSubmissions
=head1 DESCRIPTION
Uses the settings in the help desk to determine whether the resolved tickets should be closed or not.
=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::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmissionForm" );
push(@{$definition}, {
name => $i18n->get("activity title cleanup submissions"),
properties => {}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $session = $self->session;
my $root = WebGUI::Asset->getRoot($session);
# keep track of how much time it's taking
my $start = time;
my $limit = 2_500;
my $timeLimit = 60;
my $list = $root->getLineage( ['descendants'], { returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
for my $emsForm ( @$list ) {
my $daysBeforeCleanup = $emsForm->get('daysBeforeCleanup') ;
next if ! $daysBeforeCleanup;
my $whereClause = q{ submissionStatus='denied' };
if( $emsForm->get('deleteCreatedItems') ) {
$whereClause = ' ( ' . $whereClause . q{ or submissionStatus='created' } . ' ) ';
}
my $checkDate = time - ( 60*60*24* $daysBeforeCleanup );
$whereClause .= q{ and assetData.lastModified < } . $checkDate;
my $res = $emsForm->getLineage(['children'],{ returnObjects => 1,
joinClass => 'WebGUI::Asset::EMSSubmission',
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => $whereClause,
} );
for my $submission ( @$res ) {
$submission->purge;
$limit--;
return $self->WAITING(1) if ! $limit or time > $start + $timeLimit;
}
}
return $self->COMPLETE;
}
1;

View file

@ -20,6 +20,7 @@ use base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::DateTime;
use DateTime::Duration;
use WebGUI::Mail::Send;
=head1 NAME
@ -106,19 +107,7 @@ sub execute {
my $self = shift;
my $session = $self->session;
my $sql = <<END_SQL;
select r.Survey_responseId, r.username, r.userId, upd.email, upd.firstName, upd.lastName, r.startDate, s.timeLimit, s.doAfterTimeLimit, ad.title, ad.url
from Survey s, Survey_response r, assetData ad, userProfileData upd
where r.isComplete = 0
and s.timeLimit > 0
and ( unix_timestamp() - r.startDate ) > ( s.timeLimit * 60 )
and r.assetId = s.assetId
and ad.assetId = s.assetId
and ad.revisionDate = s.revisionDate
and upd.userId = r.userId
END_SQL
my $refs = $self->session->db->buildArrayRefOfHashRefs($sql);
my $refs = $self->session->db->buildArrayRefOfHashRefs( $self->getSql );
for my $ref (@{$refs}) {
if($self->get("deleteExpired")){
$session->log->debug("deleting response: $ref->{Survey_responseId} ");
@ -141,6 +130,8 @@ END_SQL
responseId => $ref->{Survey_responseId},
deleted => $self->get("deleteExpired"),
companyName => $self->session->setting->get("companyName"),
username => $ref->{username},
userId => $ref->{userId},
};
my $template = WebGUI::Asset->newById($self->session,$self->get('emailTemplateId'));
my $message = $template->processTemplate($var, $self->get("emailTemplateId"));
@ -158,4 +149,35 @@ END_SQL
return $self->COMPLETE;
}
=head2 getSql
Returns the SQL used to look up incomplete survey responses.
Factored out into a separate subroutine for the sake of testability.
=cut
sub getSql {
# Use a left outer join on userProfileData so that we still get back responses for users that have been deleted
return <<END_SQL;
select
r.Survey_responseId, r.username, r.userId, r.startDate,
upd.email, upd.firstName, upd.lastName,
s.timeLimit, s.doAfterTimeLimit,
ad.title, ad.url
from
Survey_response r left outer join userProfileData upd on r.userId = upd.userId, Survey s, assetData ad
where
r.isComplete = 0
and s.timeLimit > 0
and ( unix_timestamp() - r.startDate ) > ( s.timeLimit * 60 )
and r.assetId = s.assetId
and ad.assetId = s.assetId
and ad.revisionDate = s.revisionDate
and s.revisionDate = r.revisionDate
END_SQL
}
1;

View file

@ -81,7 +81,7 @@ sub execute {
return $self->COMPLETE;
}
my @userIds = $self->session->db->buildArray("SELECT a.userId FROM authentication AS a INNER JOIN users AS u ON a.userId = u.userId WHERE a.authMethod = 'WebGUI' AND a.fieldName = 'emailValidationKey' AND u.status = 'Deactivated' AND u.dateCreated < ?", [$self->session->datetime->time - $self->get('interval')]);
my @userIds = $self->session->db->buildArray("SELECT a.userId FROM authentication AS a INNER JOIN users AS u ON a.userId = u.userId WHERE a.authMethod = 'WebGUI' AND a.fieldName = 'emailValidationKey' AND u.status = 'Deactivated' AND u.dateCreated < ?", [time - $self->get('interval')]);
foreach my $userId (@userIds) {
WebGUI::User->new($self->session, $userId)->delete;
}

View file

@ -0,0 +1,184 @@
package WebGUI::Workflow::Activity::ExtendCalendarRecurrences;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 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 base 'WebGUI::Workflow::Activity';
use WebGUI::International;
use WebGUI::Asset;
use DateTime;
=head1 NAME
WebGUI::Workflow::Activity::ExtendCalendarRecurrences
=head1 DESCRIPTION
Generates events for all active calendar recurring events up to 2 years in the
future.
=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, $session, $definition ) = @_;
my $i18n = WebGUI::International->new( $session, 'Activity_ExtendCalendarRecurrences' );
push( @$definition, { name => $i18n->get('topicName') } );
return $class->SUPER::definition( $session, $definition );
}
#-------------------------------------------------------------------
=head2 execute ( [ object ] )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my ( $self, $obj, $instance ) = @_;
my $timeLimit = time + 55;
my $piped = $instance->getScratch('recurrences')
|| $self->generateRecurrenceList();
while (time < $timeLimit ) {
return $self->COMPLETE unless $piped;
my ( $recurId, $rest ) = split /\|/, $piped, 2;
$self->processRecurrence( $recurId, $timeLimit )
and $piped = $rest;
}
$instance->setScratch( recurrences => $piped );
return $self->WAITING(1);
} ## end sub execute
#-------------------------------------------------------------------
=head2 findRecurrenceIds ( calendarId )
Find all recurIds for the given calendarId.
=cut
sub findRecurrenceIds {
my ( $self, $calendarId ) = @_;
my $sql = q{
SELECT r.recurId
FROM Event_recur r
INNER JOIN Event e ON r.recurId = e.recurId
INNER JOIN asset a ON e.assetId = a.assetId
WHERE a.parentId = ?
};
return $self->session->db->buildArrayRef( $sql, [ $calendarId ] );
}
#-------------------------------------------------------------------
=head2 findCalendarIds
Returns an arrayref of assetIds for all Calendar assets in the asset tree.
=cut
sub findCalendarIds {
my $self = shift;
my $root = WebGUI::Asset->getRoot( $self->session );
return $root->getLineage( ['descendants'], { includeOnlyClasses => ['WebGUI::Asset::Wobject::Calendar'] } );
}
#-------------------------------------------------------------------
=head2 findLastEventId ( recurId )
Returns the assetId of the most WebGUI::Asset::Event generated for the given
recurrence.
=cut
sub findLastEventId {
my ( $self, $recurId ) = @_;
my $sql = q{
SELECT assetId
FROM Event
WHERE recurId = ?
ORDER BY startDate
LIMIT 1
};
return $self->session->db->quickScalar( $sql, [$recurId] );
}
#-------------------------------------------------------------------
=head2 generateRecurrenceList ()
Returns a string of pipe-seperated recurrence IDs for all the calendars in the
asset tree. This is called exactly once per workflow instance.
=cut
sub generateRecurrenceList {
my $self = shift;
return join( '|', map { @{ $self->findRecurrenceIds($_) } } @{ $self->findCalendarIds } );
}
#-------------------------------------------------------------------
=head2 processRecurrence (recurId, timeLimit)
Generates as many WebGUI::Asset::Event objects as it can before timeLimit is
up or the recurrence is finished for the given recurId. Returns true if it
exhausted the recurrence, false otherwise.
=cut
sub processRecurrence {
my ( $self, $recurId, $timeLimit ) = @_;
my $eventId = $self->findLastEventId($recurId);
my $event = WebGUI::Asset::Event->new( $self->session, $eventId );
my $recur = $event->getRecurrence;
my $start = $event->getDateTimeStart->truncate(to => 'day');
my $limit = DateTime->today->add( years => 2 );
my $end = $event->limitedEndDate($limit);
my $set = $event->dateSet( $recur, $start, $end );
my $i = $set->iterator;
while ( my $d = $i->next ) {
return if ( time > $timeLimit );
$event->generateRecurrence($d);
}
return 1;
} ## end sub processRecurrence
1;

View file

@ -194,7 +194,7 @@ sub execute {
from=>$cs->get("mailAddress")
});
$send->addText($i18n->get("rejected because no user account"));
$send->send;
$send->queue;
}
next;
}
@ -232,7 +232,7 @@ sub execute {
from=>$cs->get("mailAddress")
});
$send->addText($i18n->get("rejected because not allowed"));
$send->send;
$send->queue;
}
# just in case there are a lot of messages, we should release after a minutes worth of retrieving
last if (time() > $start + $ttl);

View file

@ -91,20 +91,33 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my ($self, undef, $instance) = @_;
my $message = $instance->getScratch('LowStockMessage') || '';
my $session = $self->session;
my $messageHeader =<<EOHEAD;
<table>
<tr><th>Quantity</th><th>Product</th></tr>
EOHEAD
my $message = $instance->getScratch('LowStockMessage') || $messageHeader;
my $counter = $instance->getScratch('LowStockLast') || 0;
my $belowThreshold = $instance->getScratch('LowStockBelow') || 0;
my $productIterator = WebGUI::Asset::Sku::Product->getIsa($self->session, $counter);
my $productIterator = WebGUI::Asset::Sku::Product->getIsa($session, $counter);
my $warningLimit = $self->get('warningLimit');
my $finishTime = time() + $self->getTTL;
my $expired = 0;
PRODUCT: foreach my $product ($productIterator->()) {
PRODUCT: while (1) {
my $product = eval { $productIterator->() };
if (my $e = Exception::Class->caught()) {
$session->log->error($@);
next PRODUCT;
}
last PRODUCT unless $product;
VARIANT: foreach my $collateral ( @{ $product->getAllCollateral('variantsJSON') }) {
if ($collateral->{quantity} <= $warningLimit) {
##Build message
$belowThreshold = 1;
$message .= $product->getUrl(sprintf 'func=editVariant;vid=%s', $collateral->{variantId})
. "\n";
$message .= sprintf qq{<tr><td>%d</td><td><a href="%s">%s</a></td></tr>\n},
$collateral->{quantity},
$session->url->getSiteURL.$session->url->gateway($product->getUrl(sprintf 'func=editVariant;vid=%s', $collateral->{variantId})),
$collateral->{varSku};
}
}
$counter++;
@ -126,7 +139,8 @@ sub execute {
$instance->deleteScratch('LowStockLast');
$instance->deleteScratch('LowStockBelow');
if ($belowThreshold) {
my $inbox = WebGUI::Inbox->new($self->session);
$message .= '</table>';
my $inbox = WebGUI::Inbox->new($session);
$inbox->addMessage({
status => 'unread',
subject => $self->get('subject'),

View file

@ -107,7 +107,8 @@ sub execute {
$mail->addText($message);
$mail->addFooter;
$self->session->user({user=>$previousUser});
return $mail->send ? $self->COMPLETE : $self->ERROR;
$mail->queue;
return $self->COMPLETE;
}

View file

@ -120,7 +120,7 @@ sub _notify {
my $html = sprintf $i18n->get('email message'), $dataHashRef->{count}, $s, $hostname, $hostname;
$mail->addHtml($html);
$mail->send();
$mail->queue();
}
1;

View file

@ -0,0 +1,262 @@
package WebGUI::Workflow::Activity::PayoutVendors;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 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 Business::PayPal::API qw{ MassPay };
use Data::Dumper;
use WebGUI::Mail::Send;
use base 'WebGUI::Workflow::Activity';
=head1 NAME
Package WebGUI::Workflow::Activity::PayoutVendors
=head1 DESCRIPTION
Pays profits to vendors, currently via paypal, but others may be added in the future.
=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 ()
See WebGUI::Workflow::Activity for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Workflow_Activity_PayoutVendors");
tie my %properties, 'Tie::IxHash', (
paypalUsername => {
fieldType => 'text',
label => $i18n->get('PayPal username'),
},
paypalPassword => {
fieldType => 'password',
label => $i18n->get('PayPal password'),
},
paypalSignature => {
fieldType => 'text',
label => $i18n->get('PayPal signature'),
},
useSandbox => {
fieldType => 'yesNo',
label => $i18n->get('Use in Sandbox (test-mode)'),
defaultValue => 0,
},
currencyCode => {
fieldType => 'text',
label => $i18n->get('Currency code'),
maxlength => 3,
size => 3,
defaultValue => 'USD',
},
paypalSubject => {
fieldType => 'text',
label => $i18n->get('Subject for vendor notification email'),
defaultValue => $i18n->get('Vendor payout from').' ' . $session->setting->get('companyUrl'),
},
notificationGroupId => {
fieldType => 'group',
label => $i18n->get('Notify on error'),
},
);
push @{ $definition }, {
name => $i18n->get('Vendor Payout'),
properties => \%properties,
};
return $class->SUPER::definition( $session, $definition );
}
#-------------------------------------------------------------------
=head2 payoutVendor (vendorId)
Sends unsent vendor payouts to paypal.
=head3 vendorId
The vendor to be sent his payouts.
=cut
sub payoutVendor {
my $self = shift;
my $vendorId = shift;
my $db = $self->session->db;
my $payoutId = $self->session->id->generate;
# Instanciate vendor and check if he exists.
my $vendor = WebGUI::Shop::Vendor->new( $self->session, $vendorId );
unless ( $vendor ) {
$self->session->log->error( "Could not instanciate vendor with id [$vendorId] for payout" );
return undef;
}
# check to see that the vendor has a payout address
if ($vendor->get('paymentInformation') eq '') {
$self->session->log->warn("Vendor ".$vendor->getId." hasn't specified a payout address.");
return undef;
}
# Fetch all transactionItems that are scheduled for payout to the vendor.
my $sth = $db->read(
'select itemId, vendorPayoutAmount from transactionItem '
. ' where vendorId=? and vendorPayoutStatus=? and vendorPayoutAmount > 0',
[
$vendorId,
'Scheduled',
]
);
# Process all transaction items and log them in the db.
my $totalAmount = 0;
while ( my $item = $sth->hashRef ) {
$totalAmount += $item->{ vendorPayoutAmount };
$db->write( 'insert into vendorPayoutLog_items (payoutId, transactionItemId, amount) values (?,?,?)', [
$payoutId,
$item->{ itemId },
$item->{ vendorPayoutAmount },
] );
}
my $itemCount = $sth->rows;
$sth->finish;
# Do PayPal MassPay request
my $pp = new Business::PayPal::API(
Username => $self->get('paypalUsername'),
Password => $self->get('paypalPassword'),
Signature => $self->get('paypalSignature'),
sandbox => $self->get('useSandbox'),
);
my %response = $pp->MassPay(
EmailSubject => $self->get('paypalSubject'),
currencyID => $self->get('currencyCode'),
MassPayItems => [ {
ReceiverEmail => $vendor->get('paymentInformation'),
Amount => $totalAmount,
UniqueID => $payoutId,
Note => "Payout for $itemCount sold items",
} ],
);
# Process paypal response
my $payoutDetails = {
payoutId => $payoutId,
isSuccessful => $response{ Ack } eq 'Success' ? 1 : 0,
paypalTimestamp => $response{ Timestamp },
correlationId => $response{ CorrelationID },
amount => $totalAmount,
currency => $self->get('currencyCode'),
paymentInformation => $vendor->get('paymentInformation'),
};
if ( $response{ Ack } ne 'Success' ) {
# An error occurred, keep the error codes
my $errorCode = $response{ Error }->[ 0 ]->{ ErrorCode };
my $errorMessage = $response{ Error }->[ 0 ]->{ LongMessage };
# TODO: Send out email.
my $mail = WebGUI::Mail::Send->create($self->session, {
toGroup => $self->get('notificationGroupId'),
subject => 'Vendor payout error',
});
$mail->addText(
"An error occurred during an automated vendor payout attempt. Response details:\n"
. Dumper( \%response )
. "\n\nVendor information:\n"
. Dumper( $vendor->get )
);
$mail->queue;
$payoutDetails->{ errorCode } = $errorCode;
$payoutDetails->{ errorMessage } = $errorMessage;
}
else {
# The transaction was successful, so change the state of the transactionItems to Paid.
$db->write(
'update transactionItem set vendorPayoutStatus=? where itemId in ( '
.' select transactionItemId from vendorPayoutLog_items where payoutId=? '
.')',
[
'Paid',
$payoutId,
]
);
}
# Persist response data to db
$db->setRow( 'vendorPayoutLog', 'payoutId', $payoutDetails, $payoutId );
};
#-------------------------------------------------------------------
=head2 execute ()
See WebGUI::Workflow::Activity for details.
=cut
sub execute {
my $self = shift;
my $object = shift;
my $instance = shift;
my $start = time;
my $ttl = $self->getTTL;
# Fetch vendors eligible for payout.
my $sth = $self->session->db->read(
"select distinct vendorId from transactionItem where vendorPayoutStatus='Scheduled' and vendorPayoutAmount > 0"
);
# Pay on a vendor by vendor basis.
while ( (my $vendorId) = $sth->array ) {
$self->payoutVendor( $vendorId );
# Make sure we won't run longer than allowed.
if ( ( time - $start + 1 ) >= $ttl ) {
$sth->finish;
return $self->WAITING( 1 );
}
}
$sth->finish;
return $self->COMPLETE;
}
1;

View file

@ -0,0 +1,122 @@
package WebGUI::Workflow::Activity::ProcessEMSApprovals;
=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 base 'WebGUI::Workflow::Activity';
use WebGUI::Asset;
use WebGUI::International;
use WebGUI::VersionTag;
=head1 NAME
Package WebGUI::Workflow::Activity::ProcessEMSApprovals
=head1 DESCRIPTION
Uses the settings in the help desk to determine whether the resolved tickets should be closed or not.
=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::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new( $session, "Asset_EMSSubmissionForm" );
push(@{$definition}, {
name => $i18n->get("activity title approve submissions"),
properties => {}
});
return $class->SUPER::definition($session,$definition);
}
#-------------------------------------------------------------------
=head2 execute ( )
See WebGUI::Workflow::Activity::execute() for details.
=cut
sub execute {
my $self = shift;
my $session = $self->session;
my $root = WebGUI::Asset->getRoot($session);
# keep track of how much time it's taking
my $start = time;
my $limit = 2_500;
my $timeLimit = 60;
my $list = $root->getLineage( ['descendants'], { returnObjects => 1,
includeOnlyClasses => ['WebGUI::Asset::EMSSubmissionForm'],
} );
for my $emsForm ( @$list ) {
my $whereClause = q{ submissionStatus='approved' };
my $res = $emsForm->getLineage(['children'],{ returnObjects => 1,
joinClass => 'WebGUI::Asset::EMSSubmission',
includeOnlyClasses => ['WebGUI::Asset::EMSSubmission'],
whereClause => $whereClause,
} );
for my $submission ( @$res ) {
my $properties = { className => 'WebGUI::Asset::Sku::EMSTicket' };
for my $name ( qw{title description seatsAvailable price vendorId
synopsis location duration startDate sku relatedRibbons
relatedBadgeGroups eventMetaData shipsSeparately} ) {
$properties->{$name} = $submission->get($name);
}
$properties->{eventNumber} = $self->session->db->quickScalar(
"select max(eventNumber)+1
from EMSTicket left join asset using (assetId)
where parentId=?",[$emsForm->ems->getId]) || 0;
my $newAsset = $emsForm->ems->addChild( $properties );
if( $newAsset ) {
# TODO this should be addRevision
$submission->update({ ticketId => $newAsset->getId, submissionStatus => 'created' });
WebGUI::VersionTag->autoCommitWorkingIfEnabled($session, { override => 1, allowComments => 0 });
} else {
$submission->addComment($@) if $@;
$submission->update({ submissionStatus => 'failed' });
}
$limit--;
last if ! $limit or time > $start + $timeLimit;
}
}
return $self->WAITING(1) if ! $limit or time > $start + $timeLimit;
return $self->COMPLETE;
}
1;

View file

@ -78,9 +78,10 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $session = $self->session;
my $sth = $session->db->read("select assetId,className from asset where state='trash' and stateChanged < ?", [time() - $self->get("purgeAfter")]);
my $start = time();
my $ttl = $self->getTTL;
my $sth = $session->db->read("select assetId,className from asset where state='trash' and stateChanged < ?",
[ time() - $self->get("purgeAfter") ]
);
my $expireTime = time() + $self->getTTL;
ASSET: while (my ($id, $class) = $sth->array) {
my $asset = eval { WebGUI::Asset->newById($session, $id); };
if (Exception::Class->caught()) {
@ -88,8 +89,8 @@ sub execute {
next ASSET;
}
$asset->purge;
if (time() - $start > $ttl) {
$session->log->info("Ran out of time processing");
if (time() > $expireTime) {
$session->log->info("Ran out of time processing");
$sth->finish;
return $self->WAITING(1);
}

View file

@ -0,0 +1,94 @@
package WebGUI::Workflow::Activity::RecheckVATNumber;
=head1 LEGAL
-------------------------------------------------------------------
WebGUI is Copyright 2001-2009 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::Shop::TaxDriver::EU;
use base 'WebGUI::Workflow::Activity';
=head1 NAME
Package WebGUI::Workflow::Activity::RecheckVATNumber
=head1 DESCRIPTION
Rechecks VAT number trhough the EU VIES service that could not be checked at the time they were submitted.
=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::defintion() for details.
=cut
sub definition {
my $class = shift;
my $session = shift;
my $definition = shift;
my $i18n = WebGUI::International->new($session, "Activity_RecheckVATNumber");
push ( @{ $definition }, {
name =>$i18n->get("topicName"),
} );
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 $params = $instance->get('parameters');
my $user = WebGUI::User->new( $self->session, $params->{ userId } );
my $taxDriver = WebGUI::Shop::TaxDriver::EU->new( $self->session );
my $result = $taxDriver->recheckVATNumber( $params->{ vatNumber }, $user );
$self->session->log->warn( "Checked $params->{ vatNumber } for user $params->{ userId }, result: $result");
# If the validity of the number is known we're finished.
if ( $result eq 'VALID' || $result eq 'INVALID' ) {
return $self->COMPLETE;
}
# Otherwise, try again in an hour.
return $self->WAITING( 3600 );
}
1;
#vim:ft=perl

View file

@ -174,7 +174,6 @@ sub execute {
my $versionTag = shift;
my $instance = shift;
my $i18n = WebGUI::International->new( $self->session, "VersionTag" );
my $inbox = WebGUI::Inbox->new( $self->session );
# First time through, send the message(s)
if ( $instance->getScratch("status") eq "" ) {
@ -267,7 +266,7 @@ sub sendMessage {
my $messageText
= join "\n\n",
$self->get("message"),
$approvalUrl,
sprintf('<a href="%s">%s</a>', $approvalUrl, $approvalUrl,),
$versionTag->get("comments"),
;

View file

@ -76,12 +76,14 @@ See WebGUI::Workflow::Activity::execute() for details.
sub execute {
my $self = shift;
my $sth = $self->session->db->read("select assetId from EventsCalendar_event where eventEndDate < ?", [time()-$self->get("trashAfter")]);
while (my ($id) = $sth->array) {
my $sth = $self->session->db->read( "select assetId from Event where endDate < ?", [ time() - $self->get("trashAfter") ]);
my $finishTime = time() + $self->getTTL;
EVENT: while ( my ($id) = $sth->array ) {
my $asset = eval { WebGUI::Asset::Event->newById($self->session, $id); };
if (! Exception::Class->caught() && $asset->get("eventEndDate") < time()-$self->get("trashAfter")) {
if (! Exception::Class->caught() && $asset->eventEndDate < time() - $self->trashAfter) {
$asset->trash;
}
}
last EVENT if time() > $finishTime;
}
$sth->finish;
return $self->COMPLETE;

View file

@ -84,7 +84,7 @@ sub execute {
my $urlOfSingleAsset = "";
#By default, we'll make it so that things happen now.
my $time = $session->datetime->time();
my $time = time();
#If the type is startTime, we'll wait until the version tag starttime to proceed
if($self->get("type") eq "startTime") {
@ -98,7 +98,7 @@ sub execute {
my $dt = WebGUI::DateTime->new($session,$time);
#Get the current UTC time
my $now = WebGUI::DateTime->new($session,$session->datetime->time());
my $now = WebGUI::DateTime->new($session,time());
#Workflow is complete if the time has passed.
if($now->epoch >= $dt->epoch) {