-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathconfig_manager.pm
159 lines (104 loc) · 3.67 KB
/
config_manager.pm
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
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
package config_manager;
use strict;
use warnings;
use File::Find qw( finddepth );
sub new {
my ( $class, $globals ) = @_;
my $self;
$self->{globals} = $globals;
bless $self, $class;
$self->{globals}->{db}->do(
"create table if not exists simple_config (\n"
. " key text not null primary key\n"
. " , value text\n"
. ")"
);
$self->{globals}->{db}->do(
"create table if not exists connections (\n"
. " ID integer primary key autoincrement\n"
. " , ConnectionName text\n"
. " , DatabaseType text\n"
. " , EnvironmentName text\n"
. " , Username text\n"
. " , Password text\n"
. " , Host text\n"
. " , Port text\n"
. ")"
);
$self->{exists_simple_config} = $self->{globals}->{db}->prepare(
"select value from simple_config where key = ?"
);
$self->{update_simple_config} = $self->{globals}->{db}->prepare(
"update simple_config set value = ? where key = ?"
);
$self->{insert_simple_config} = $self->{globals}->{db}->prepare(
"insert into simple_config ( key, value ) values ( ?, ? )"
);
return $self;
}
sub simpleSet {
my ( $self, $key, $value ) = @_;
$self->{exists_simple_config}->execute( $key );
my $exists = $self->{exists_simple_config}->fetchrow_hashref;
if ( $exists ) {
$self->{update_simple_config}->execute( $value, $key );
} else {
$self->{insert_simple_config}->execute( $key, $value );
}
}
sub simpleGet {
my ( $self, $key ) = @_;
$self->{exists_simple_config}->execute( $key );
my $exists = $self->{exists_simple_config}->fetchrow_hashref;
if ( $exists ) {
return $exists->{value};
} else {
return undef;
}
}
sub get_auth_values {
my ( $self, $connection_name ) = @_;
my $auth_hash = $self->{globals}->{db}->select(
"select * from connections where ConnectionName = ?"
, [ $connection_name ]
);
if ( ! $auth_hash ) {
powercom::dialog::new(
{
title => "Couldn't find connection in config database!"
, type => "error"
, markup => "The config manager was requested to build auth values for:\n\n"
. "Connection Name: [<span color='blue'><b>$connection_name</b></span>]\n"
. " ... but there is no such entry in the Connections table.\n"
. "Please open the configuration screen and add such a connection.\n\n"
. "<i>Expect a bunch of errors after this message ...</i>"
}
);
return undef;
}
return $auth_hash->[0];
}
sub all_database_drivers {
my $self = shift;
my $db_class_path = $self->{globals}->{current_dir} . "/Database/Connection/";
my ( @files , @all_database_drivers );
finddepth(
sub {
return if($_ eq '.' || $_ eq '..');
push @files, $File::Find::name;
}
, $db_class_path
);
foreach my $file ( @files ) {
my $db_class_name;
if ( $file =~ /.*Database\/Connection\/(.*)\.pm$/ ) {
$db_class_name = $1;
$db_class_name =~ s/\//::/g; # substitute slashes with ::
push @all_database_drivers, $db_class_name;
}
}
my @sorted_dbs = sort( @all_database_drivers );
return \@sorted_dbs;
}
1;
1;