webgui_newsletter/sbin/install_newsletter.pl
2010-05-12 13:30:35 +02:00

165 lines
3.9 KiB
Perl

#!/usr/bin/env perl
$|++; # disable output buffering
our ( $webguiRoot, $configFile );
BEGIN {
$webguiRoot = "..";
unshift (@INC, $webguiRoot."/lib");
}
use strict;
use Pod::Usage;
use Getopt::Long;
use WebGUI::Session;
# Get parameters here, including $help
GetOptions(
'configFile=s' => \$configFile,
);
my $session = start( $webguiRoot, $configFile );
installMailableAspectTable( $session );
installNewsletterCollection( $session );
installMailingTables( $session );
finish($session);
#----------------------------------------------------------------------------
sub installMailableAspectTable {
my $session = shift;
print "\tCreating Mailable aspect table...";
$session->db->write(<<EOSQL);
create table if not exists assetAspectMailable (
assetId char(22) binary not null,
revisionDate bigint(20) not null,
mailStyleTemplateId char(22) binary not null,
primary key( assetId, revisionDate )
);
EOSQL
print "Done.\n";
}
#----------------------------------------------------------------------------
sub installNewsletterCollection {
my $session = shift;
print "\tCreating NewsletterCollection table...";
$session->db->write(<<EOSQL);
create table if not exists NewsletterCollection (
assetId char(22) binary not null,
revisionDate bigint(20) not null,
alwaysConfirmSubscription tinyint(1) not null default 0,
primary key( assetId, revisionDate )
);
EOSQL
$session->db->write(<<EOSQL2);
create table if not exists NewsletterCollection_subscriptions (
assetId char(22) binary not null,
userId char(22) binary not null,
confirmed tinyint(1) default 0,
code char(22) default null,
creationDate timestamp default CURRENT_TIMESTAMP,
primary key( assetId, userId )
);
EOSQL2
print "Done.\n";
}
#----------------------------------------------------------------------------
sub installMailingTables {
my $session = shift;
print "\tInstalling Mailing table...";
use WebGUI::Mailing;
use WebGUI::Mailing::Email;
WebGUI::Mailing->crud_createOrUpdateTable( $session );
WebGUI::Mailing::Email->crud_createOrUpdateTable( $session );
print "Done\n";
}
#----------------------------------------------------------------------------
sub start {
my $webguiRoot = shift;
my $configFile = shift;
my $session = WebGUI::Session->open($webguiRoot,$configFile);
$session->user({userId=>3});
## If your script is adding or changing content you need these lines, otherwise leave them commented
#
# my $versionTag = WebGUI::VersionTag->getWorking($session);
# $versionTag->set({name => 'Name Your Tag'});
#
##
return $session;
}
#----------------------------------------------------------------------------
sub finish {
my $session = shift;
## If your script is adding or changing content you need these lines, otherwise leave them commented
#
# my $versionTag = WebGUI::VersionTag->getWorking($session);
# $versionTag->commit;
##
$session->var->end;
$session->close;
}
__END__
=head1 NAME
utility - A template for WebGUI utility scripts
=head1 SYNOPSIS
utility --configFile config.conf ...
utility --help
=head1 DESCRIPTION
This WebGUI utility script helps you...
=head1 ARGUMENTS
=head1 OPTIONS
=over
=item B<--configFile config.conf>
The WebGUI config file to use. Only the file name needs to be specified,
since it will be looked up inside WebGUI's configuration directory.
This parameter is required.
=item B<--help>
Shows a short summary and usage
=item B<--man>
Shows this document
=back
=head1 AUTHOR
Copyright 2001-2009 Plain Black Corporation.
=cut
#vim:ft=perl