-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathkayako_import.pl
106 lines (78 loc) · 2.39 KB
/
kayako_import.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
#!/usr/bin/perl
####################################################################################
# A quick perl script that will import the production Kayako DB export into our test
# environment and provide housekeeping post import.
# 12/23/2013
# Version 1.2
####################################################################################
use strict;
use warnings;
use autodie;
use DBI;
use LWP::Simple;
# CONFIG VARIABLES
my $platform = "mysql";
my $database = "kayako";
my $host = "localhost";
my $username = "username";
my $password = "password";
my $hdurl = "http://helpdesk.domain.com";
# FUNCTION TO TRIM WHITESPACE
sub trim($)
{
my $string = shift;
$string =~ s/^\s+//;
$string =~ s/\s+$//;
return $string;
}
# DATABASE UPDATE VARIABLES
my $url = "update swsettings set data = '$hdurl/' where vkey='general_producturl'";
my $emailclose = "update swautocloserules set isenabled = '0'";
my $queue = "update swemailqueues set isenabled = '0'";
# DATA SOURCE NAME
my $dsn = "dbi:$platform:$database:$host";
# GET FILE TO IMPORT FROM
print 'Database export filename to import from: ';
chomp(my $import = <STDIN>);
$import = trim($import);
if (-e $import)
{
my $dbimport = "mysql -u $username -p$password kayako < $import";
print "Importing $import\. Please be patient this may take several minutes.\n";
# IMPORT THE SQL FILE
system ($dbimport);
# PERL DBI CONNECT
my $connect = DBI->connect($dsn, $username, $password) or die $DBI::errstr;
print "Connected to the Database\n";
print "\n";
# SET THE HELPDESK URL FOR THE DEV ENVIRONMENT
print "Updating Helpdesk URL\n";
$connect->do ($url) or die "SQL Error: $DBI::errstr";
print "Done!\n";
print "\n";
sleep 1;
# DISABLE EMAIL QUEUES TO PREVENT DEV FROM PICKING UP SUPPORT EMAILS
print "Disabling Email Queue\(s\)\n";
$connect->do ($queue) or die "SQL Error: $DBI::errstr";
print "Done!\n";
print "\n";
sleep 1;
# DISABLE AUTO CLOSURE RULES
print "Disabling Auto Closure Rule\(s\)\n";
$connect->do ($emailclose) or die "SQL Error: $DBI::errstr";
print "Done!\n";
print "\n";
# CLOSE MYSQL CONNECTION GRACEFULLY
$connect->disconnect;
# FORCE A CACHE UPDATE.
print "Updating helpdesk cache\n";
system ("curl $hdurl/staff/index.php?/Core/Default/RebuildCache");
print "Done!\n";
print "\n";
print "All finished, quitting!\n";
exit;
}
else { print "File not found. Aborting!\n";
exit;
}