+sub _upgrade_data {
+ my ($class, %opts) = @_;
+
+ return if FS::upgrade_journal->is_done('log__remap_levels');
+
+ tie my %levelmap, 'Tie::IxHash',
+ 2 => 1, #notice -> info
+ 6 => 5, #alert -> critical
+ 7 => 5, #emergency -> critical
+ ;
+
+ # this method should never autocommit
+ # should have been set in upgrade, but just in case...
+ local $FS::UID::AutoCommit = 0;
+
+ # in practice, only debug/info/warning/error appear to have been used,
+ # so this probably won't do anything, but just in case
+ foreach my $old (keys %levelmap) {
+ # FS::log has no replace method
+ my $sql = 'UPDATE log SET level=' . dbh->quote($levelmap{$old}) . ' WHERE level=' . dbh->quote($old);
+ warn $sql unless $opts{'quiet'};
+ my $sth = dbh->prepare($sql) or die dbh->errstr;
+ $sth->execute() or die $sth->errstr;
+ $sth->finish();
+ }
+
+ foreach my $log_email (
+ qsearch('log_email',{ 'min_level' => 2 }),
+ qsearch('log_email',{ 'min_level' => 6 }),
+ qsearch('log_email',{ 'min_level' => 7 }),
+ ) {
+ $log_email->min_level($levelmap{$log_email->min_level});
+ my $error = $log_email->replace;
+ if ($error) {
+ dbh->rollback;
+ die $error;
+ }
+ }
+
+ FS::upgrade_journal->set_done('log__remap_levels');
+
+}
+