Rubber-stamped by Brady Eidson.
[webbrowser.git] / BugsSite / sanitycheck.pl
blob592069a9c47427c3560ff2f816ac326c536497e6
1 #!/usr/bin/env perl -w
2 # -*- Mode: perl; indent-tabs-mode: nil -*-
4 # The contents of this file are subject to the Mozilla Public
5 # License Version 1.1 (the "License"); you may not use this file
6 # except in compliance with the License. You may obtain a copy of
7 # the License at http://www.mozilla.org/MPL/
9 # Software distributed under the License is distributed on an "AS
10 # IS" basis, WITHOUT WARRANTY OF ANY KIND, either express or
11 # implied. See the License for the specific language governing
12 # rights and limitations under the License.
14 # The Original Code is the Bugzilla Bug Tracking System.
16 # The Initial Developer of the Original Code is Frédéric Buclin.
17 # Portions created by Frédéric Buclin are Copyright (C) 2007
18 # Frédéric Buclin. All Rights Reserved.
20 # Contributor(s): Frédéric Buclin <LpSolit@gmail.com>
22 use strict;
24 use lib qw(. lib);
26 use Bugzilla;
27 use Bugzilla::Constants;
28 use Bugzilla::Error;
29 use Bugzilla::User;
30 use Bugzilla::Mailer;
32 use Getopt::Long;
33 use Pod::Usage;
35 my $verbose = 0; # Return all comments if true, else errors only.
36 my $login = ''; # Login name of the user which is used to call sanitycheck.cgi.
37 my $help = 0; # Has user asked for help on this script?
39 my $result = GetOptions('verbose' => \$verbose,
40 'login=s' => \$login,
41 'help|h|?' => \$help);
43 pod2usage({-verbose => 1, -exitval => 1}) if $help;
45 Bugzilla->usage_mode(USAGE_MODE_CMDLINE);
47 # Be sure a login name if given.
48 $login || ThrowUserError('invalid_username');
50 my $user = new Bugzilla::User({ name => $login })
51 || ThrowUserError('invalid_username', { name => $login });
53 my $cgi = Bugzilla->cgi;
54 my $template = Bugzilla->template;
56 # Authenticate using this user account.
57 Bugzilla->set_user($user);
59 # Pass this param to sanitycheck.cgi.
60 $cgi->param('verbose', $verbose);
62 require 'sanitycheck.cgi';
64 # Now it's time to send an email to the user if there is something to notify.
65 if ($cgi->param('output')) {
66 my $message;
67 my $vars = {};
68 $vars->{'addressee'} = $user->email;
69 $vars->{'output'} = $cgi->param('output');
70 $vars->{'error_found'} = $cgi->param('error_found') ? 1 : 0;
72 $template->process('email/sanitycheck.txt.tmpl', $vars, \$message)
73 || ThrowTemplateError($template->error());
75 MessageToMTA($message);
79 __END__
81 =head1 NAME
83 sanitycheck.pl - Perl script to perform a sanity check at the command line
85 =head1 SYNOPSIS
87 ./sanitycheck.pl [--help]
88 ./sanitycheck.pl [--verbose] --login <user@domain.com>
90 =head1 OPTIONS
92 =over
94 =item B<--help>
96 Displays this help text
98 =item B<--verbose>
100 Causes this script to be more verbose in its output. Without this option,
101 the script will return only errors. With the option, the script will append
102 all output to the email.
104 =item B<--login>
106 This should be passed the email address of a user that is capable of
107 running the Sanity Check process, a user with the editcomponents priv. This
108 user will receive an email with the results of the script run.
110 =back
112 =head1 DESCRIPTION
114 This script provides a way of running a 'Sanity Check' on the database
115 via either a CLI or cron. It is equivalent to calling sanitycheck.cgi
116 via a web broswer.