bin/database/data/insert-newsletter-demo-data
#!/usr/bin/env perl
# ===================================================================
# File: bin/database/insert-newsletter-demo-data
# Project: ShinyCMS
# Purpose: Insert newsletter demo data via DBIC
#
# Author: Denny de la Haye <2019@denny.me>
# Copyright (c) 2009-2019 Denny de la Haye
#
# ShinyCMS is free software; you can redistribute it and/or modify it
# under the terms of either the GPL 2.0 or the Artistic License 2.0
# ===================================================================
use strict;
use warnings;
# Load local helper lib and get connected schema object
use FindBin qw( $Bin );
use lib "$Bin/../../lib";
require 'helpers.pl'; ## no critic
my $schema = get_schema();
# MAILING LISTS
# Create private mailing lists
my $private_list1 = $schema->resultset( 'MailingList' )->find_or_create({
name => 'Donators and teachers',
});
my $private_list2 = $schema->resultset( 'MailingList' )->find_or_create({
name => 'Only one subscriber!',
});
# Create some mail recipients
my $recipient1 = $schema->resultset( 'MailRecipient' )->find_or_create({
name => 'Nice Person',
email => 'nice.person@example.com',
token => 'abcd1234abcd1234abcd1234abcd1111',
});
my $recipient2 = $schema->resultset( 'MailRecipient' )->find_or_create({
name => 'Another Person',
email => 'another.person@example.com',
token => 'abcd1234abcd1234abcd1234abcd2222',
});
my $recipient3 = $schema->resultset( 'MailRecipient' )->find_or_create({
name => 'A. Teacher',
email => 'a.teacher@example.com',
token => 'abcd1234abcd1234abcd1234abcd3333',
});
my $recipient4 = $schema->resultset( 'MailRecipient' )->find_or_create({
name => 'Site Admin',
email => 'changeme@example.com',
token => 'abcd1234abcd1234abcd1234abcd4444',
});
# Add the recipients to the list
$private_list1->subscriptions->find_or_create({
recipient => $recipient1->id
});
$private_list1->subscriptions->find_or_create({
recipient => $recipient2->id
});
$private_list1->subscriptions->find_or_create({
recipient => $recipient3->id
});
$private_list2->subscriptions->find_or_create({
recipient => $recipient4->id
});
# Create public mailing lists
my $public_list1 = $schema->resultset( 'MailingList' )->find_or_create({
name => 'A Public List',
user_can_sub => 1
});
my $public_list2 = $schema->resultset( 'MailingList' )->find_or_create({
name => 'Another Public List',
user_can_sub => 1
});
my $public_list3 = $schema->resultset( 'MailingList' )->find_or_create({
name => 'Third Public List',
user_can_sub => 1
});
# Add a recipient to a public list
$public_list1->subscriptions->find_or_create({
recipient => $recipient4->id
});
# NEWSLETTERS
# Create a newsletter template
my $template = $schema->resultset( 'NewsletterTemplate' )->find_or_create({
name => 'Example newsletter template',
filename => 'example.tt',
});
# Create template elements
$template->newsletter_template_elements->find_or_create({
name => 'body',
type => 'HTML',
});
# Create a newsletter
my $newsletter = $template->newsletters->find_or_create({
title => 'Donations and a word to teachers and librarians',
url_title => 'donations',
status => 'Not sent',
list => $private_list1->id,
plaintext => <<'EOT'
If you enjoyed the electronic edition of Little Brother and you want to donate
something to say thanks, go to http://craphound.com/littlebrother/donate/ and
find a teacher or librarian you want to support. Then go to Amazon, BN.com,
or your favorite electronic bookseller and order a copy to the classroom,
then email a copy of the receipt (feel free to delete your address and other
personal info first!) to freelittlebrother@gmail.com so that Olga can mark
that copy as sent. If you don't want to be publicly acknowledged for your
generosity, let us know and we'll keep you anonymous, otherwise we'll thank
you on the donate page.
EOT
});
# Populate the newsletter elements
$newsletter->newsletter_elements->find_or_create({
name => 'body',
type => 'HTML',
content => <<'EOT'
<p> A message from Cory Doctorow:
</p>
<p> Every time I put a book online for free, I get emails from readers who
want to send me donations for the book. I appreciate their generous
spirit, but I'm not interested in cash donations, because my
publishers are really important to me. They contribute immeasurably
to the book, improving it, introducing it to an audience I could never
reach, helping me do more with my work. I have no desire to cut them
out of the loop.
</p>
<p> But there has to be some good way to turn that generosity to good use,
and I think I've found it.
</p>
<p> Here's the deal: there are lots of teachers and librarians who'd love to
get hard-copies of Little Brother into their kids' hands, but don't have the
budget for it (teachers in the US spend around $1,200 out of pocket
each on classroom supplies that their budgets won't stretch to cover,
which is why I sponsor a classroom at Ivanhoe Elementary in my old
neighborhood in Los Angeles; you can adopt a class yourself
<a href="http://www.adoptaclassroom.org/">here</a>).
</p>
<p> There are generous people who want to send some cash my way to thank me
for the free ebooks.
</p>
<p> I'm proposing that we put them together.
</p>
<p> If you're a teacher or librarian and you want a free copy of Little
Brother, email
<a href="mailto:freelittlebrother@gmail.com">freelittlebrother@gmail.com</a>
with your name and the name and address of your school. It'll be
<a href="http://craphound.com/littlebrother/donate/">posted to my site</a>
by my fantastic helper, Olga Nunes, so that potential donors can see it.
</p>
<p> If you enjoyed the electronic edition of Little Brother and you want to
donate something to say thanks,
<a href="http://craphound.com/littlebrother/donate/">go here</a>
and find a teacher or librarian you want to support. Then go to Amazon,
BN.com, or your favorite electronic bookseller and order a copy to the
classroom, then email a copy of the receipt (feel free to delete your
address and other personal info first!) to
<a href="mailto:freelittlebrother@gmail.com">freelittlebrother@gmail.com</a>
so that Olga can mark that copy as sent. If you don't want to be publicly
acknowledged for your generosity, let us know and we'll keep you
anonymous, otherwise we'll thank you on the donate page.
</p>
<p> I have no idea if this will end up with hundreds, dozens or just a few
copies going out -- but I have high hopes!
</p>
EOT
});
# AUTORESPONDERS
# Create an autoresponder
my $autoresponder = $schema->resultset( 'Autoresponder' )->find_or_create({
name => 'Example autoresponder',
url_name => 'example',
has_captcha => 1,
});
# Create an autoresponder email
my $autoresponder_email = $autoresponder->autoresponder_emails->find_or_create({
subject => 'This is an autoresponse email',
template => $template->id,
delay => 0,
plaintext => <<'EOT'
This is the plain text body of the autoresponse email.
EOT
});
# Populate the autoresponder email elements
$autoresponder_email->autoresponder_email_elements->find_or_create({
name => 'body',
type => 'HTML',
content => <<'EOT'
<p>
This is the HTML body of the autoresponse email.
</p>
EOT
});
# PAID LISTS
# Create a paid list
my $paid_list = $schema->resultset( 'PaidList' )->find_or_create({
name => 'Example paid list',
url_name => 'example',
});
# Create a paid list email
my $paid_list_email = $paid_list->paid_list_emails->find_or_create({
subject => 'This is an paid list email',
template => $template->id,
delay => 0,
plaintext => <<'EOT'
This is the plain text body of the paid list email.
EOT
});
# Populate the paid list email elements
$paid_list_email->paid_list_email_elements->find_or_create({
name => 'body',
type => 'HTML',
content => <<'EOT'
<p>
This is the HTML body of the paid list email.
</p>
EOT
});