From 3dda2775b73b29ca72f3996eb5788124950f9e70 Mon Sep 17 00:00:00 2001 From: Janik Kleinhoff Date: Fri, 28 Oct 2016 13:48:16 +0000 Subject: Use DBIx::Class For now this is a relatively quick-and-dirty transition, but this enables us to reuse ASM::DB from the website. Yay --- meta.pl | 40 +++++++++++++++++++++++++++++++++++++--- 1 file changed, 37 insertions(+), 3 deletions(-) (limited to 'meta.pl') diff --git a/meta.pl b/meta.pl index 7f03197..2e12008 100755 --- a/meta.pl +++ b/meta.pl @@ -123,10 +123,44 @@ sub init { if (-e "debugsock") { $irc->debugsock(1); } + + my $mysql_config_bad = 0; + + if (exists $::mysql->{table}) { + if ($::mysql->{table} ne 'alertlog') { + warn "The 'table' option in mysql.json is no longer supported. Please ensure your table is named 'alertlog'.\n"; + $mysql_config_bad++; + } + else { + warn "The 'table' option in mysql.json is no longer supported. Please remove it from the configuration.\n"; + } + } + if (exists $::mysql->{actiontable}) { + if ($::mysql->{actiontable} ne 'actionlog') { + warn "The 'actiontable' option in mysql.json is no longer supported. Please ensure your table is named 'actionlog'.\n"; + $mysql_config_bad++; + } + else { + warn "The 'actiontable' option in mysql.json is no longer supported. Please remove it from the configuration.\n"; + } + } + + if ($mysql_config_bad) { + die "The bot cannot operate with the current database configuration.\n"; + } + if (!$::mysql->{disable}) { - $::db = ASM::DB->new($::mysql->{db}, $::mysql->{host}, $::mysql->{port}, - $::mysql->{user}, $::mysql->{pass}, $::mysql->{table}, - $::mysql->{actiontable}, $::mysql->{dblog}); + my $dsn; + if (exists $::mysql->{dsn}) { + $dsn = $::mysql->{dsn}; + } + else { + # This isn't what we *should* do - notably, we'd have to wrap IPv6 addresses given + # as host in brackets. It's what the old code did, though, and all we need is + # compatibility with that. + $dsn = sprintf 'DBI:mysql:database=%s;host=%s;port=%s', @{ $::mysql }{'db', 'host', 'port'}; + } + $::db = ASM::DB->connect($dsn, $::mysql->{user}, $::mysql->{pass}); } $conn = $irc->newconn( Server => $host, Port => $::settings->{port} || '6667', -- cgit v1.2.3