427 lines
13 KiB
Perl
427 lines
13 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;
|
|
use List::MoreUtils qw{ insert_after_string none };
|
|
|
|
# Get parameters here, including $help
|
|
GetOptions(
|
|
'configFile=s' => \$configFile,
|
|
);
|
|
|
|
my $session = start( $webguiRoot, $configFile );
|
|
|
|
installSubscriberAspectTable( $session );
|
|
installMailableAspectTable( $session );
|
|
installNewsletterCollection( $session );
|
|
installMailingTables( $session );
|
|
installNewsletterInAdminConsole( $session );
|
|
installNewsletterSettings( $session );
|
|
addPluginsToConfigFile( $session );
|
|
addTemplateColumnToNewsletterCollection( $session );
|
|
addRecentColumnToNewsletterCollection( $session );
|
|
renamespaceTemplates( $session );
|
|
addSpecialStateTable( $session );
|
|
addListNameColumn( $session );
|
|
addRegistrationSteps( $session );
|
|
addConfirmationTemplateColumn( $session );
|
|
addSentToIndex( $session );
|
|
|
|
finish($session);
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addConfirmationTemplateColumn {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
|
|
print "\tAdding column for mutation confirmation template...";
|
|
|
|
my $hasColumn = $db->quickScalar( 'show columns from assetAspectSubscriber where Field = ?', [
|
|
'confirmMutationTemplateId',
|
|
] );
|
|
|
|
unless ( $hasColumn ) {
|
|
$db->write(
|
|
'alter table assetAspectSubscriber add column confirmMutationTemplateId char(22) binary not null default ?',
|
|
[
|
|
'WUk-wEhGiF8dcEogrJfrfg',
|
|
]
|
|
);
|
|
|
|
$db->write(
|
|
'update assetAspectSubscriber set confirmMutationTemplateId=? where confirmMutationTemplateId is null',
|
|
[
|
|
'WUk-wEhGiF8dcEogrJfrfg',
|
|
]
|
|
);
|
|
|
|
sub addSentToIndex {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
|
|
print "\tAdding index to column Mailing_email.sentTo...";
|
|
|
|
my @indexes = $db->buildArray('show indexes from Mailing_email where Column_name=?',['sentTo']);
|
|
|
|
if ( @indexes == 0 ) {
|
|
$db->write('alter table Mailing_email add index(sentTo)');
|
|
}
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addListNameColumn {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
print "\tAdding list name column for subscribers...";
|
|
|
|
my @columns = $db->buildArray( 'desc assetAspectSubscriber' );
|
|
|
|
if ( none { $_ eq 'listName' } @columns ) {
|
|
$db->write( 'alter table assetAspectSubscriber add column listName varchar(255)' );
|
|
}
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
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 installSubscriberAspectTable {
|
|
my $session = shift;
|
|
print "\tCreating Subscriber aspect table...";
|
|
|
|
$session->db->write(<<EOSQL);
|
|
create table if not exists assetAspectSubscriber (
|
|
assetId char(22) binary not null,
|
|
revisionDate bigint(20) not null,
|
|
subscriptionGroupId char(22) binary,
|
|
subscriptionEnabled tinyint(1) not null default 0,
|
|
alwaysConfirmSubscription tinyint(1) not null default 0,
|
|
allowAnonymousSubscription tinyint(1) not null default 0,
|
|
confirmationRequiredTemplateId char(22) binary,
|
|
confirmationEmailTemplateId char(22) binary,
|
|
confirmationEmailSubject varchar(255),
|
|
noMutationEmailTemplateId char(22) binary,
|
|
noMutationEmailSubject varchar(255),
|
|
primary key( assetId, revisionDate )
|
|
);
|
|
EOSQL
|
|
|
|
$session->db->write(<<EOSQL2);
|
|
create table if not exists assetAspectSubscriber_log (
|
|
assetId char(22) binary not null,
|
|
requestIp char(15) not null,
|
|
requestDate bigint(20) not null,
|
|
confirmationIp char(15),
|
|
confirmationDate bigint(20),
|
|
userId char(22) binary not null,
|
|
email varchar(255) not null,
|
|
type char(30) not null,
|
|
anonymous tinyint(1) not null,
|
|
confirmed tinyint(1) default 0,
|
|
code char(22) default null
|
|
);
|
|
EOSQL2
|
|
|
|
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,
|
|
primary key( assetId, revisionDate )
|
|
);
|
|
EOSQL
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addTemplateColumnToNewsletterCollection {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
print "\tAdding view template column to NewletterCollection...";
|
|
|
|
my $hasColumn = $db->quickScalar( 'show columns from NewsletterCollection where Field=?', [ 'viewTemplateId' ] );
|
|
|
|
unless ( $hasColumn ) {
|
|
$db->write( 'alter table NewsletterCollection add column viewTemplateId char(22) binary not null default ?', [
|
|
'aYVYFpofaYvmRYoHwl3x4w'
|
|
] );
|
|
$db->write( 'update NewsletterCollection set viewTemplateId=?', [
|
|
'aYVYFpofaYvmRYoHwl3x4w',
|
|
] );
|
|
}
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addRecentColumnToNewsletterCollection {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
print "\tAdding recent issues column to NewletterCollection...";
|
|
|
|
my $hasColumn = $db->quickScalar( 'show columns from NewsletterCollection where Field=?', [ 'recentIssueCount' ] );
|
|
|
|
unless ( $hasColumn ) {
|
|
$db->write( 'alter table NewsletterCollection add column recentIssueCount int(3) not null default ?', [
|
|
1,
|
|
] );
|
|
$db->write( 'update NewsletterCollection set recentIssueCount=?', [
|
|
1
|
|
] );
|
|
}
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub installMailingTables {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
print "\tInstalling Mailing table...";
|
|
|
|
# Remname tables from a previous (bad) name to a new (good) one.
|
|
# Must be done before the crudCreateOrUpdate calls to prevent creation of stale tables.
|
|
my @tables = $db->buildArray( 'show tables' );
|
|
if ( scalar grep { $_ eq 'WGMailing' } @tables ) {
|
|
$db->write( 'rename table WGMailing to Mailing' );
|
|
}
|
|
if ( scalar grep { $_ eq 'WGMailing_queue' } @tables ) {
|
|
$db->write( 'rename table WGMailing_queue to Mailing_email' );
|
|
}
|
|
|
|
# Create or update Mailing tables.
|
|
use WebGUI::Mailing;
|
|
use WebGUI::Mailing::Email;
|
|
|
|
WebGUI::Mailing->crud_createOrUpdateTable( $session );
|
|
WebGUI::Mailing::Email->crud_createOrUpdateTable( $session );
|
|
|
|
print "Done\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub installNewsletterInAdminConsole {
|
|
my $session = shift;
|
|
|
|
print "\tAdding newsletter admin console section...";
|
|
$session->config->set( 'adminConsole/mailable', {
|
|
groupSetting => "mailingManagerGroupId",
|
|
icon => "newsletter.gif",
|
|
title => "Newsletter",
|
|
uiLevel => 7,
|
|
url => qq{^PageUrl("",newsletter=manage);},
|
|
} );
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub installNewsletterSettings {
|
|
my $session = shift;
|
|
my $setting = $session->setting;
|
|
|
|
print "\tInstalling newsletter setting slots...";
|
|
|
|
my %settings = (
|
|
newsletterReturnDomain => undef,
|
|
newsletterBounceScoreThreshold => 0,
|
|
mailingManagerTemplateId => 'FTfNhWI8KJOwLzFUl5rYeQ',
|
|
mailingAdminGroupId => 3,
|
|
mailingManagerGroupId => 3,
|
|
mailingManagersCanOverrideDefault => 0,
|
|
);
|
|
|
|
while ( my ($name, $value) = each %settings ) {
|
|
$setting->add( $name => $value ) unless $setting->has( $name );
|
|
}
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addPluginsToConfigFile {
|
|
my $session = shift;
|
|
my $config = $session->config;
|
|
|
|
print "\tAdding plugins to config file...";
|
|
|
|
$config->set( 'assets/WebGUI::Asset::Wobject::NewsletterCollection', {
|
|
category => 'basic',
|
|
} );
|
|
|
|
my @handlers = @{ $session->config->get('contentHandlers') };
|
|
if ( !scalar grep { $_ eq 'WebGUI::Content::NewsletterManager' } @handlers ) {
|
|
insert_after_string 'WebGUI::Content::Shop', 'WebGUI::Content::NewsletterManager', @handlers;
|
|
$session->config->set( 'contentHandlers', \@handlers );
|
|
}
|
|
|
|
my @workflows = @{ $session->config->get('workflowActivities/None') };
|
|
if ( !scalar grep { $_ eq 'WebGUI::Workflow::Activity::SendQueuedMailings' } @workflows ) {
|
|
push @workflows, 'WebGUI::Workflow::Activity::SendQueuedMailings';
|
|
$session->config->set( 'workflowActivities/None', \@workflows );
|
|
}
|
|
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub renamespaceTemplates {
|
|
my $session = shift;
|
|
my $db = $session->db;
|
|
|
|
print "\tRenamespacing templates...";
|
|
|
|
$db->write( 'update template set namespace=? where namespace=?', [
|
|
'Mailing/Manage',
|
|
'NLAdmin/Manage',
|
|
] );
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addSpecialStateTable {
|
|
my $session = shift;
|
|
|
|
print "\tAdding special state table...";
|
|
|
|
$session->db->write( <<EOSQL );
|
|
create table if not exists users_specialState (
|
|
userId char(22) binary not null,
|
|
specialState char(30) not null,
|
|
primary key ( userId, specialState )
|
|
)
|
|
EOSQL
|
|
|
|
print "Done.\n";
|
|
}
|
|
|
|
#----------------------------------------------------------------------------
|
|
sub addRegistrationSteps {
|
|
my $session = shift;
|
|
|
|
print "\tAdding MailingSubscribe Registration Step to config...";
|
|
|
|
my %steps = map { $_ => 1 } @{ $session->config->get( 'registrationSteps' ) || [] };
|
|
$steps{ 'WebGUI::Registration::Step::MailingSubscribe' } = 1;
|
|
|
|
$session->config->set( 'registrationSteps', [ keys %steps ] );
|
|
|
|
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
|