6 use POSIX qw
/strftime/;
8 $SIG{__WARN__
} = sub { cluck
$_[0] };
10 my $ctx = ASR
::Ladder
->new;
12 $ctx->header('Monthly reset');
14 if ($ctx->param('pwd') ne $ctx->{adminpw
}) {
15 print $ctx->p('Invalid password.');
20 if (not system('mysqldump -u asr -p'.$ctx->{password
}.' asr >/tmp/ASR-`date +%F`.dump')) {
21 print $ctx->p("Error: Database backup failed: $?, $!");
26 ($ctx->db_do('START TRANSACTION') and
27 $ctx->db_do('CREATE TEMPORARY TABLE inactive (id INT)') and
28 $ctx->db_do('INSERT INTO inactive SELECT id FROM raw_ladder ' .
29 'WHERE last_game IS NULL OR last_game < ' .
30 'DATE("'.$ctx->param('cutoffdate').'")') and
31 $ctx->db_do('DELETE FROM player WHERE id IN (SELECT id FROM inactive)') and
32 $ctx->db_do('DROP TABLE inactive') and
33 $ctx->db_do('COMMIT')) or
34 print $ctx->p('Removing inactive players failed.');
36 $ctx->db_do('UPDATE player SET score = 100 WHERE score < 100') or
37 print $ctx->p('Flooring score to 100 failed.');
38 $ctx->db_do('UPDATE player SET score = 200 WHERE score > 200') or
39 print $ctx->p('Ceiling score to 200 failed.');
40 $ctx->db_do('UPDATE player SET score = 100 + (score - 100) / 2 WHERE score > 100') or
41 print $ctx->p('Halving score failed.');