[LON-CAPA-cvs] cvs: loncom /interface lonmysql.pm lonstatistics.pm
matthew
lon-capa-cvs@mail.lon-capa.org
Fri, 18 Apr 2003 15:50:55 -0000
matthew Fri Apr 18 11:50:55 2003 EDT
Modified files:
/loncom/interface lonmysql.pm lonstatistics.pm
Log:
Added &Apache::lonmysql::verify_sql_connection() to test the daemons ability
to talk to the database.
Modified &Apache::lonstatistics::handler to call verify_sql_connection and
give an error message to the user.
Index: loncom/interface/lonmysql.pm
diff -u loncom/interface/lonmysql.pm:1.12 loncom/interface/lonmysql.pm:1.13
--- loncom/interface/lonmysql.pm:1.12 Fri Mar 21 11:04:42 2003
+++ loncom/interface/lonmysql.pm Fri Apr 18 11:50:55 2003
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# MySQL utility functions
#
-# $Id: lonmysql.pm,v 1.12 2003/03/21 16:04:42 matthew Exp $
+# $Id: lonmysql.pm,v 1.13 2003/04/18 15:50:55 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -341,6 +341,33 @@
return undef;
}
$debugstring = "Successfully connected to loncapa database.";
+ return 1;
+}
+
+###############################
+
+=pod
+
+=item &verify_sql_connection()
+
+Inputs: none.
+
+Returns: 0 (failure) or 1 (success)
+
+Checks to make sure the database can be connected to. It does not
+initialize anything in the lonmysql package.
+
+=cut
+
+###############################
+sub verify_sql_connection {
+ my $connection;
+ if (! ($connection = DBI->connect("DBI:mysql:loncapa","www",
+ $Apache::lonnet::perlvar{'lonSqlAccess'},
+ { RaiseError=>0,PrintError=>0}))) {
+ return 0;
+ }
+ undef($connection);
return 1;
}
Index: loncom/interface/lonstatistics.pm
diff -u loncom/interface/lonstatistics.pm:1.65 loncom/interface/lonstatistics.pm:1.66
--- loncom/interface/lonstatistics.pm:1.65 Tue Mar 25 17:20:25 2003
+++ loncom/interface/lonstatistics.pm Fri Apr 18 11:50:55 2003
@@ -1,6 +1,6 @@
# The LearningOnline Network with CAPA
#
-# $Id: lonstatistics.pm,v 1.65 2003/03/25 22:20:25 matthew Exp $
+# $Id: lonstatistics.pm,v 1.66 2003/04/18 15:50:55 matthew Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -51,7 +51,7 @@
use Apache::lonproblemstatistics;
use Apache::lonstudentassessment;
use Apache::lonpercentage;
-
+ use Apache::lonmysql;
=over 4
=cut
@@ -82,6 +82,7 @@
use Apache::lonproblemstatistics();
use Apache::lonstudentassessment();
use Apache::lonpercentage;
+use Apache::lonmysql;
use Time::HiRes;
#######################################################
@@ -908,6 +909,22 @@
$r->print(&Apache::lonhtmlcommon::Title('Course Statistics and Charts'));
$r->rflush();
#
+ if (! &Apache::lonmysql::verify_sql_connection()) {
+ my $serveradmin = $r->dir_config('lonAdmEMail');
+ $r->print(<<END);
+<h2><font color="Red">Unable to connect to database!</font></h2>
+<p>
+Please notify the server administrator <b>$serveradmin</b>.
+</p><p>
+Course Statistics and Charts cannot be retrieved until the database is
+restarted. Your data is intact but cannot be displayed at this time.
+</p>
+</body>
+</html>
+END
+ return;
+ }
+ #
# Set up the statistics and chart environment
&PrepareClasslist($r);
&PrepareCourseData($r);
@@ -919,7 +936,7 @@
# Print main menu
my %reports = ('classlist' => 'Class list',
'problem_statistics' => 'Problem Statistics',
- 'student_assessment' => 'Student Assessment',
+ 'student_assessment' => 'Problem Status Chart',
'percentage' => 'Correct-problems Plot',
'option_response' => 'Option Response Analysis',
# 'activitylog' => 'Activity Log',