| 176 |
- |
1 |
#!/usr/bin/perl
|
|
|
2 |
|
|
|
3 |
use strict;
|
|
|
4 |
use cPanelUserConfig;
|
| 278 |
- |
5 |
use RollerCon;
|
| 176 |
- |
6 |
use DBI;
|
|
|
7 |
use WebDB;
|
|
|
8 |
use REST::Client;
|
|
|
9 |
use JSON;
|
| 278 |
- |
10 |
use Data::Dumper;
|
| 176 |
- |
11 |
|
|
|
12 |
my $dbh = WebDB::connect ();
|
| 236 |
- |
13 |
my $headers = { Authorization => getSetting ("WRSTBND_API_KEY") };
|
| 176 |
- |
14 |
|
|
|
15 |
print "Bulk adding class registrations...\n";
|
|
|
16 |
|
| 278 |
- |
17 |
my $sql = <<sqlstatement;
|
|
|
18 |
select class.id, v_class_signup_new.RCid, wrstbnd_id, wrstbnd_accountid
|
|
|
19 |
from v_class_signup_new
|
|
|
20 |
left join class on v_class_signup_new.id = class.id
|
|
|
21 |
left join RCid_ticket_link on v_class_signup_new.RCid = RCid_ticket_link.RCid and year = year(now())
|
|
|
22 |
left join ticket on MVPid = ticket.id
|
|
|
23 |
where year(class.date) = year(now()) and isnull(wb_ticket_act) = 1 and isnull(v_class_signup_new.RCid) = 0
|
|
|
24 |
sqlstatement
|
|
|
25 |
|
|
|
26 |
#my $sth = $dbh->prepare ("select class.id, v_class_signup_new.RCid, wrstbnd_id, wrstbnd_accountid from v_class_signup_new left join class on v_class_signup_new.id = class.id left join RCid_ticket_link on v_class_signup_new.RCid = RCid_ticket_link.RCid and year = year(now()) left join ticket on MVPid = ticket.id where year(v_class_signup_new.date) = year(now())");
|
|
|
27 |
my $sth = $dbh->prepare ($sql);
|
| 176 |
- |
28 |
my $assignment = $dbh->prepare ("update assignment set wb_ticket_act = ? where Gid = ? and RCid = ? and role like ?");
|
|
|
29 |
|
|
|
30 |
$sth->execute ();
|
|
|
31 |
|
|
|
32 |
while (my ($id, $rcid, $classid, $accountid) = $sth->fetchrow ()) {
|
|
|
33 |
print "Adding $classid to $accountid...";
|
|
|
34 |
my $client = REST::Client->new();
|
| 177 |
- |
35 |
$client->setHost('https://core.wrstbnd.io');
|
|
|
36 |
|
| 176 |
- |
37 |
my $body = {
|
| 273 |
- |
38 |
"eventId" => getSetting ("WRSTBND_EVENT_ID"),
|
| 176 |
- |
39 |
"activeStatus" => "active",
|
|
|
40 |
"ticketTypeId" => $classid
|
|
|
41 |
};
|
|
|
42 |
my $json_body = encode_json $body;
|
|
|
43 |
|
|
|
44 |
$client->POST(
|
|
|
45 |
'/rest/core/v1/ticket',
|
|
|
46 |
$json_body,
|
|
|
47 |
$headers
|
|
|
48 |
);
|
|
|
49 |
my $response = from_json($client->responseContent());
|
| 278 |
- |
50 |
|
| 176 |
- |
51 |
my $activationCode = $response->{activationCode};
|
|
|
52 |
print $activationCode."...";
|
| 236 |
- |
53 |
my $api_key = getSetting ("WRSTBND_API_KEY");
|
|
|
54 |
my $add_response = `/bin/curl --location 'https://core.wrstbnd.io/rest/core/v1/assign' --header 'Authorization: $api_key' --form accountid=$accountid --form ticketactcode=$activationCode --output /dev/null --silent --write-out '%{http_code}\n'`;
|
| 273 |
- |
55 |
print $add_response; chomp $add_response;
|
| 176 |
- |
56 |
$assignment->execute ($activationCode, $id, $rcid, 'CLA-%') unless $add_response ne "200";
|
| 279 |
- |
57 |
# print Dumper $add_response unless $add_response eq "200";
|
| 176 |
- |
58 |
}
|
|
|
59 |
|
|
|
60 |
|
|
|
61 |
print "\nDone.\n";
|