Permalink
Browse files

Re-connect the WhatCounts model

  • Loading branch information...
phillipadsmith committed Mar 28, 2012
1 parent 4a3f6ac commit 9fc3c0d863f89924f83bfbafa2e5fd11ae55359e
@@ -49,11 +49,6 @@ __PACKAGE__->table("subscriber");
datetime_undef_if_invalid: 1
is_nullable: 0
-=head2 trnordernumber
-
- data_type: 'integer'
- is_nullable: 1
-
=head2 trnamount
data_type: 'float'
@@ -247,8 +242,6 @@ __PACKAGE__->add_columns(
datetime_undef_if_invalid => 1,
is_nullable => 0,
},
- "trnordernumber",
- { data_type => "integer", is_nullable => 1 },
"trnamount",
{ data_type => "float", is_nullable => 0 },
"trnemailaddress",
@@ -27,7 +27,7 @@ has_field 'newspref_education' =>
( type => 'Checkbox', widget => 'checkbox', label => 'Education' );
has_field 'newspref_energy' =>
( type => 'Checkbox', widget => 'checkbox', label => 'Energy' );
-has_field 'newspref_environ' =>
+has_field 'newspref_enviro' =>
( type => 'Checkbox', widget => 'checkbox', label => 'Environment' );
has_field 'newspref_health' =>
( type => 'Checkbox', widget => 'checkbox', label => 'Health' );
@@ -33,14 +33,16 @@ Catalyst Controller.
sub index : Chained('/') PathPart('builders') CaptureArgs(0) {
my ( $self, $c ) = @_;
- my $dt = DateTime->from_epoch( epoch => str2time( $c->req->params->{'trnDate'} ) );
- my ( $fname, $lname ) = split( ' ', $c->req->params->{'trnCustomerName'} );
+ my $dt = DateTime->from_epoch(
+ epoch => str2time( $c->req->params->{'trnDate'} ) );
+ my ( $fname, $lname )
+ = split( ' ', $c->req->params->{'trnCustomerName'} );
$c->stash(
params => {
trnid => $c->req->params->{'trnId'},
trnamount => $c->req->params->{'trnAmount'},
- trndate => $c->req->params->{'trnDate'},
- name => $c->req->params->{'trnCustomerName'},
+ trndate => $c->req->params->{'trnDate'},
+ name => $c->req->params->{'trnCustomerName'},
trnemailaddress => $c->req->params->{'trnEmailAddress'},
trnphonenumber => $c->req->params->{'trnPhoneNumber'},
authcode => $c->req->params->{'authCode'},
@@ -55,9 +57,8 @@ sub index : Chained('/') PathPart('builders') CaptureArgs(0) {
sub add_to_db : Chained('index') PathPart('') CaptureArgs(0) {
my ( $self, $c ) = @_;
- my $subscriber = $c->model( 'SubscriberDB::Subscriber' )->find_or_create(
- $c->stash->{'params'}
- );
+ my $subscriber = $c->model( 'SubscriberDB::Subscriber' )
+ ->find_or_create( $c->stash->{'params'} );
$c->stash( subscriber => $subscriber );
}
@@ -66,10 +67,10 @@ sub add_to_wc : Chained('add_to_db') PathPart('') CaptureArgs(0) {
my $subscriber = $c->stash->{'subscriber'};
my ( $sub_info, $whatcounts )
= $c->model( 'WhatCounts' )->create_or_update(
- { builder_amt => $c->stash->{'trnamount'},
- builder_id => $c->stash->{'trnid'},
- builder_date => $c->stash->{'trndate'},
- email => $c->stash->{'trnemailaddress'},
+ { builder_amt => $c->stash->{'params'}->{'trnamount'},
+ builder_id => $c->stash->{'params'}->{'trnid'},
+ builder_date => $c->stash->{'params'}->{'trndate'},
+ email => $c->stash->{'params'}->{'trnemailaddress'},
list_id => $c->config->{'whatcounts_list_id'},
realm_name => $c->config->{'whatcounts_realm_name'},
pw => $c->config->{'whatcounts_pw'},
@@ -99,28 +100,22 @@ sub approved : Chained('add_to_wc') : PathPart('approved') : Args(0) {
);
return unless $form->validated;
if ( $c->req->method eq 'POST' ) {
+
# Form validated, return to the books list
- $c->stash->{status_msg}
- = 'Your preferences have been saved.';
+ $c->stash->{status_msg} = 'Your preferences have been saved.';
}
}
-
sub declined : Local : Args(0) {
my ( $self, $c ) = @_;
- my $id = $c->req->params->{'trnId'};
- my $amt = $c->req->params->{'trnAmount'};
- my $name = $c->req->params->{'trnCustomerName'};
- my $email = $c->req->params->{'trnEmailAddress'};
- my $phone = $c->req->params->{'trnPhoneNumber'};
- my $msg = $c->req->params->{'messageText'};
$c->stash(
- trn_id => $id,
- message => $msg,
- cust_name => $name,
- trn_amt => $amt,
- cust_email => $email,
- cust_phone => $phone,
+ trn_id => $c->req->params->{'trnId'},
+ message => $c->req->params->{'messageText'},
+ cust_name =>
+ $c->req->params->{'trnCustomerName'},
+ trn_amt => $c->req->params->{'trnAmount'},
+ cust_email => $c->req->params->{'trnEmailAddress'},
+ cust_phone => $c->req->params->{'trnPhoneNumber'},
title => 'Your transaction was not successful',
);
}
@@ -136,30 +131,6 @@ it under the same terms as Perl itself.
=cut
-# trnApproved=1
-# trnId=10000002
-# messageId=1
-# messageText=Approved
-# authCode=TEST
-# responseType=T
-# trnAmount=10.00
-# trnDate=2%2F27%2F2012+11%3A43%3A01+AM
-# trnOrderNumber=10000002
-# trnLanguage=eng
-# trnCustomerName=Phillip+Smith
-# trnEmailAddress=ps%40phillipadsmith.com
-# trnPhoneNumber=647+361+8248
-# avsProcessed=1
-# avsId=N
-# avsResult=0
-# avsAddrMatch=0
-# avsPostalMatch=0
-# avsMessage=Street+address+and+Postal%2FZIP+do+not+match.
-# cvdId=1&cardType=MC
-# trnType=P
-# paymentMethod=CC
-# ref1=&ref2=&ref3=&ref4=&ref5=
-
__PACKAGE__->meta->make_immutable;
1;
@@ -44,21 +44,6 @@ sub create_or_update {
return ( $subscribed, $response );
}
-
-# http://premiere.whatcounts.com/bin/api_web?r=media_thetyee&p=XXXXX&cmd=sub&list_id=36871&data=email,first,last^jane@domain.com,Jane,Doe
-# http://premiere.whatcounts.com/bin/list_edit2?cmd=edit&id=36871&CSRFChallengeToken=%2590%25E0%25D6%25CCOo%251BX%252Bx%25E5%25DBi%258E%25AD%25D7%250A%25DD%253A%259F%25DE%259F%25F9J%258A%25CDLR%25EF%25080Z%2508%2580%253A%25AEBn%25F1%25F4%2504%2580F%25C1%255D%25E5%25A8%25E7%255E%25EA%2590%25D3%2596%25C0%25B0%25C1%25E9%250Aj%2511%25AE%2503%2597m
-#my $response = HTTP::Tiny->new->get( 'http://example.com/' );
-
-#die "Failed!\n" unless $response->{success};
-
-#print "$response->{status} $response->{reason}\n";
-
-#while ( my ( $k, $v ) = each %{ $response->{headers} } ) {
-#for ( ref $v eq 'ARRAY' ? @$v : $v ) {
-#print "$k: $_\n";
-#}
-#}
-
=head1 NAME
Tyee::Forms::Model::WhatCounts - Catalyst Model
View
@@ -0,0 +1,55 @@
+#!/usr/bin/env perl
+#===============================================================================
+#
+# FILE: install_db.pl
+#
+# USAGE: ./install_db.pl
+#
+# DESCRIPTION:
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: YOUR NAME (),
+# COMPANY:
+# VERSION: 1.0
+# CREATED: 14/03/2012 14:52:10
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
+use Getopt::Long;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Config::JFDI;
+use Data::Dumper;
+use Subscriber::Schema;
+
+my $force_overwrite = 1;
+
+unless ( GetOptions( 'force_overwrite!' => \$force_overwrite ) ) {
+ die "Invalid options";
+}
+
+
+my $config = Config::JFDI->new(name => "Tyee::Forms", path => "$FindBin::Bin/../");
+my $config_hash = $config->get;
+my $args = $config_hash->{'Model::SubscriberDB'}->{'connect_info'};
+
+my $schema = Subscriber::Schema->connect( $args->[0], $args->[1], $args->[2] );
+
+my $dh = DH->new(
+ {
+ schema => $schema,
+ script_directory => "$FindBin::Bin/../dbicdh",
+ databases => 'MySQL',
+ sql_translator_args => { add_drop_table => 0 },
+ force_overwrite => $force_overwrite,
+ }
+);
+
+$dh->prepare_install;
+
@@ -0,0 +1,45 @@
+#!/usr/bin/perl
+#===============================================================================
+#
+# FILE: set_up_versioned_db.pl
+#
+# USAGE: ./set_up_versioned_db.pl
+#
+# DESCRIPTION:
+#
+# OPTIONS: ---
+# REQUIREMENTS: ---
+# BUGS: ---
+# NOTES: ---
+# AUTHOR: YOUR NAME (),
+# COMPANY:
+# VERSION: 1.0
+# CREATED: 14/03/2012 12:55:42
+# REVISION: ---
+#===============================================================================
+
+use strict;
+use warnings;
+
+use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
+use Getopt::Long;
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Config::JFDI;
+use Data::Dumper;
+use Subscriber::Schema;
+
+my $config = Config::JFDI->new(name => "Tyee::Forms", path => "$FindBin::Bin/../");
+my $config_hash = $config->get;
+my $args = $config_hash->{'Model::SubscriberDB'}->{'connect_info'};
+
+my $schema = Subscriber::Schema->connect( $args->[0], $args->[1], $args->[2] );
+my $dh = DBIx::Class::DeploymentHandler->new({
+ schema => $schema,
+ force_overwrite => 1,
+});
+
+$dh->prepare_version_storage_install;
+$dh->install_version_storage;
+
+$dh->add_database_version({ version => $schema->schema_version });
View
@@ -0,0 +1,28 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+use aliased 'DBIx::Class::DeploymentHandler' => 'DH';
+use FindBin;
+use lib "$FindBin::Bin/../lib";
+use Config::JFDI;
+use Data::Dumper;
+use Subscriber::Schema;
+
+my $config = Config::JFDI->new(name => "Tyee::Forms", path => "$FindBin::Bin/../");
+my $config_hash = $config->get;
+my $args = $config_hash->{'Model::SubscriberDB'}->{'connect_info'};
+
+my $schema = Subscriber::Schema->connect( $args->[0], $args->[1], $args->[2] );
+
+my $dh = DH->new({
+ schema => $schema,
+ script_directory => "$FindBin::Bin/../dbicdh",
+ databases => 'MySQL',
+ sql_translator_args => { add_drop_table => 0 },
+ force_overwrite => 1,
+
+});
+
+$dh->prepare_deploy;
+$dh->prepare_upgrade({ from_version => 1, to_version => 2});
+$dh->upgrade;
View
@@ -11,7 +11,7 @@
Target Server Version : 50521
File Encoding : utf-8
- Date: 03/23/2012 13:59:42 PM
+ Date: 03/28/2012 13:39:28 PM
*/
SET NAMES utf8;
@@ -24,7 +24,6 @@ DROP TABLE IF EXISTS `subscriber`;
CREATE TABLE `subscriber` (
`trnId` int(11) NOT NULL,
`trnDate` datetime NOT NULL,
- `trnOrderNumber` int(11) DEFAULT NULL,
`trnAmount` float NOT NULL,
`trnEmailAddress` varchar(255) NOT NULL,
`trnPhoneNumber` varchar(255) NOT NULL,

0 comments on commit 9fc3c0d

Please sign in to comment.