| 105 | | &get_database_settings unless ($opt->{timeoffset}); |
| | 98 | unless ($opt->{timeoffset}) { |
| | 99 | # Specify a non-standard location for mysql.txt |
| | 100 | Shepherd::MythTV::setup($opt->{mysql_file}) if ($opt->{mysql_file}); |
| | 101 | |
| | 102 | my $sql = "SELECT data FROM settings WHERE value LIKE 'TimeOffset'"; |
| | 103 | ($opt->{timeoffset}) = Shepherd::MythTV::query($sql); |
| | 104 | unless ($opt->{timeoffset}) { |
| | 105 | print " Won't augment any timezones!\n" . |
| | 106 | " Assuming MythTV's timezone is \"None\".\n". |
| | 107 | " *** If this is wrong, guide data may be in wrong timezone! ***\n\n"; |
| | 108 | } |
| | 109 | } |
| 219 | | ############################################################################## |
| 220 | | |
| 221 | | sub find_database_settings_file |
| 222 | | { |
| 223 | | foreach my $cfgfile (split(/:/,$opt->{mysql_file})) { |
| 224 | | return $cfgfile if ((-f $cfgfile) && (-r $cfgfile)); |
| 225 | | } |
| 226 | | |
| 227 | | printf "\nWARNING: Could not find MythTV mysql.txt config file\n". |
| 228 | | " (looked in ".$opt->{mysql_file}.")\n". |
| 229 | | " Assuming MythTV's timezone is \"None\".\n". |
| 230 | | " *** If this is wrong, guide data may be in wrong timezone! ***\n\n"; |
| 231 | | $stats{missing_mysql_database_file}++; |
| 232 | | return undef; |
| 233 | | } |
| 234 | | |
| 235 | | ############################################################################## |
| 236 | | |
| 237 | | sub get_database_settings |
| 238 | | { |
| 239 | | my $cfgfile = &find_database_settings_file; |
| 240 | | return if (!defined $cfgfile); |
| 241 | | |
| 242 | | # |
| 243 | | # find database settings |
| 244 | | # |
| 245 | | |
| 246 | | if (!(open(F,"<$cfgfile"))) { |
| 247 | | print "WARNING: could not read $cfgfile: $!\n". |
| 248 | | "Won't augment any timezones!\n"; |
| 249 | | $stats{mysql_database_file_unreadable}++; |
| 250 | | return; |
| 251 | | } |
| 252 | | |
| 253 | | while (<F>) { |
| 254 | | chop; |
| 255 | | |
| 256 | | if ($_ =~ /^DBHostName=(.*)$/) { |
| 257 | | $opt->{dbhost} = $1; |
| 258 | | } elsif ($_ =~ /^DBUserName=(.*)$/) { |
| 259 | | $opt->{dbuser} = $1; |
| 260 | | } elsif ($_ =~ /^DBPassword=(.*)$/) { |
| 261 | | $opt->{dbpass} = $1; |
| 262 | | } elsif ($_ =~ /^DBName=(.*)$/) { |
| 263 | | $opt->{dbname} = $1; |
| 264 | | } |
| 265 | | } |
| 266 | | close(F); |
| 267 | | |
| 268 | | # |
| 269 | | # look up the timeoffset setting |
| 270 | | # |
| 271 | | |
| 272 | | if (!($dbh = DBI->connect("dbi:mysql:database=".$opt->{dbname}.":host=".$opt->{dbhost},$opt->{dbuser}, $opt->{dbpass}))) { |
| 273 | | print "WARNING: Couldn't connect to database ".$opt->{dbname}.": $!\n". |
| 274 | | " Won't augment any timezones!\n"; |
| 275 | | $stats{mysql_database_connect_failed}++; |
| 276 | | return; |
| 277 | | } |
| 278 | | |
| 279 | | my $q = "SELECT data FROM settings WHERE value LIKE 'TimeOffset'"; |
| 280 | | if (!($opt->{timeoffset} = $dbh->selectrow_array($q))) { |
| 281 | | print "WARNING: Couldn't query database: $q: $!\n". |
| 282 | | " Won't augment any timezones!\n"; |
| 283 | | $stats{mysql_database_query_failed}++; |
| 284 | | return; |
| 285 | | } |
| 286 | | } |
| 287 | | |