Initial commit.
This commit is contained in:
commit
cfa018e04b
3 changed files with 315 additions and 0 deletions
93
lib/WebGUI/Asset/Wobject/NewsletterCollection.pm
Normal file
93
lib/WebGUI/Asset/Wobject/NewsletterCollection.pm
Normal file
|
|
@ -0,0 +1,93 @@
|
||||||
|
package WebGUI::Asset::Wobject::NewsletterCollection;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
|
||||||
|
use Class::C3;
|
||||||
|
|
||||||
|
use base qw{
|
||||||
|
WebGUI::AssetAspect::Mailable
|
||||||
|
WebGUI::Asset::Wobject
|
||||||
|
};
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub definition {
|
||||||
|
my $class = shift;
|
||||||
|
my $session = shift;
|
||||||
|
my $definition = shift;
|
||||||
|
my $i18n = WebGUI::International->new( $session, 'Asset_NewsletterCollection' );
|
||||||
|
|
||||||
|
tie my %properties, 'Tie::IxHash', (
|
||||||
|
);
|
||||||
|
|
||||||
|
push @{ $definition }, {
|
||||||
|
assetName => $i18n->echo('newsletter'),
|
||||||
|
icon => 'newWobject.gif',
|
||||||
|
autoGenerateForms => 1,
|
||||||
|
tableName => 'NewsletterCollection',
|
||||||
|
className => 'WebGUI::Asset::Wobject::NewsletterCollection',
|
||||||
|
properties => \%properties
|
||||||
|
};
|
||||||
|
|
||||||
|
return $class->SUPER::definition( $session, $definition );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub generateEmailContent {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $form = $session->form;
|
||||||
|
|
||||||
|
my $issueId = $form->get('issueId');
|
||||||
|
my $issue = WebGUI::Asset->newByDynamicClass( $session, $issueId );
|
||||||
|
|
||||||
|
return "Invalid issueId [$issueId]" unless $issue;
|
||||||
|
|
||||||
|
$issue->prepareView;
|
||||||
|
return $issue->view;
|
||||||
|
}
|
||||||
|
|
||||||
|
##-------------------------------------------------------------------
|
||||||
|
#sub prepareView {
|
||||||
|
# my $self = shift;
|
||||||
|
# $self->SUPER::prepareView();
|
||||||
|
# my $template = WebGUI::Asset::Template->new( $self->session, $self->get("templateIdView") );
|
||||||
|
# $template->prepare($self->getMetaDataAsTemplateVariables);
|
||||||
|
# $self->{_viewTemplate} = $template;
|
||||||
|
#}
|
||||||
|
|
||||||
|
#-------------------------------------------------------------------
|
||||||
|
sub view {
|
||||||
|
my $self = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
|
||||||
|
my $issues = $self->getLineage( [ 'children' ], {
|
||||||
|
returnObjects => 1,
|
||||||
|
orderByClause => 'revisionDate desc',
|
||||||
|
} );
|
||||||
|
|
||||||
|
my $output = $self->getToolbar if $session->var->isAdminOn;
|
||||||
|
|
||||||
|
return $output . "No issues yet" unless scalar @{ $issues };
|
||||||
|
|
||||||
|
$output .= '<p>Issues: <ul>';
|
||||||
|
$output .=
|
||||||
|
join '',
|
||||||
|
map {
|
||||||
|
'<li>'
|
||||||
|
.'<a href="' . $_->getUrl . '">' . $_->get('title') . '</a>'
|
||||||
|
.' :: '
|
||||||
|
.' <a href="' .$self->getUrl('func=previewEmail;issueId='.$_->getId.';userId=3').'">preview</a>'
|
||||||
|
.'</li>'
|
||||||
|
}
|
||||||
|
@{ $issues };
|
||||||
|
$output .= '</ul></p>';
|
||||||
|
|
||||||
|
$issues->[0]->prepareView;
|
||||||
|
$output .= $issues->[0]->view;
|
||||||
|
|
||||||
|
return $output;
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
87
lib/WebGUI/AssetAspect/Mailable.pm
Normal file
87
lib/WebGUI/AssetAspect/Mailable.pm
Normal file
|
|
@ -0,0 +1,87 @@
|
||||||
|
package WebGUI::AssetAspect::Mailable;
|
||||||
|
|
||||||
|
use strict;
|
||||||
|
use warnings;
|
||||||
|
use Class::C3;
|
||||||
|
|
||||||
|
use WebGUI::Macro;
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub definition {
|
||||||
|
my $class = shift;
|
||||||
|
my $session = shift;
|
||||||
|
my $definition = shift;
|
||||||
|
my $i18n = WebGUI::International->new( $session,'AssetAspect_Mailable' );
|
||||||
|
|
||||||
|
tie my %properties, 'Tie::IxHash', (
|
||||||
|
);
|
||||||
|
|
||||||
|
push( @{ $definition }, {
|
||||||
|
autoGenerateForms => 1,
|
||||||
|
tableName => 'assetAspectMailable',
|
||||||
|
className => 'WebGUI::AssetAspect::Mailable',
|
||||||
|
properties => \%properties
|
||||||
|
} );
|
||||||
|
|
||||||
|
return $class->next::method( $session, $definition );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getEditTabs {
|
||||||
|
my $self = shift;
|
||||||
|
|
||||||
|
return ( $self->next::method, [ 'mailable', 'Mailing list', 9 ] );
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub generateEmailContent {
|
||||||
|
WebGUI::Error::OverrideMe->throw;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getIssueList {
|
||||||
|
WebGUI::Error::OverrideMe->throw;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub getRecipients {
|
||||||
|
WebGUI::Error::OverrideMe->throw;
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub processContentAsUser {
|
||||||
|
my $self = shift;
|
||||||
|
my $userId = shift;
|
||||||
|
my $session = $self->session;
|
||||||
|
my $currentUser = $session->user;
|
||||||
|
|
||||||
|
# Become the desired user
|
||||||
|
$session->user( { userId => $userId } );
|
||||||
|
|
||||||
|
# Generate email body for this user
|
||||||
|
my $content = $self->generateEmailContent;
|
||||||
|
|
||||||
|
# Process macros
|
||||||
|
WebGUI::Macro::process( $session, \$content );
|
||||||
|
|
||||||
|
# Become ourselves again.
|
||||||
|
$session->user( { userId => $currentUser->getId } );
|
||||||
|
|
||||||
|
return $content;
|
||||||
|
}
|
||||||
|
|
||||||
|
#----------------------------------------------------------------------------
|
||||||
|
sub www_previewEmail {
|
||||||
|
my $self = shift;
|
||||||
|
my $form = $self->session->form;
|
||||||
|
|
||||||
|
my $userId = $form->get('userId');
|
||||||
|
|
||||||
|
return $self->processContentAsUser( $userId );
|
||||||
|
}
|
||||||
|
|
||||||
|
1;
|
||||||
|
|
||||||
135
sbin/install_newsletter.pl
Normal file
135
sbin/install_newsletter.pl
Normal file
|
|
@ -0,0 +1,135 @@
|
||||||
|
#!/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 );
|
||||||
|
|
||||||
|
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,
|
||||||
|
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,
|
||||||
|
primary key( assetId, revisionDate )
|
||||||
|
);
|
||||||
|
EOSQL
|
||||||
|
|
||||||
|
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
|
||||||
Loading…
Add table
Add a link
Reference in a new issue