Installation

uninitialized WEBWORK_DIRECTORY

uninitialized WEBWORK_DIRECTORY

by Hal Sadofsky -
Number of replies: 4

We just upgraded from 2.4.7 to 2.5.1.1.

I have a perl script I wrote under 2.4.7 to add courses in batches (we're typically using WeBWorK in on the order of 100 courses per term, so it is nice not to be adding them through the admin interface).  I'm not especially proud of it, but it seemed to work, and is attached.

I ported the script to the new version of WeBWorK, and had to make some very small changes in the "use" lines to get it to work.  It works now, but it generates the following error message (which has no detectable effect so far):

Use of uninitialized value $WeBWorK::Constants::WEBWORK_DIRECTORY in concatenation (.) or string at /opt/webwork/webwork2/lib/WeBWorK/Constants.pm line 38.

I think it produces this error once at the beginning, and then every time it calls wwdb.  

If anyone has any insight on what is going on and how I should make it stop, I'd greatly appreciate it!

thanks,  Hal

Hal Sadofsky
Mathematics Department
University of Oregon
In reply to Hal Sadofsky

Re: uninitialized WEBWORK_DIRECTORY

by Michael Gage -
Hi Hal,

Look at http://webwork.maa.org/moodle/mod/forum/discuss.php?d=2767#p6393

$WeBWorK::Constants::WEBWORK_DIRECTORY is usually initiated 
in webwork.apache2-config.  You can initialize it from $ENV{WEBWORK_ROOT} either in your script or in you can modify WeBWorK/Constants.pm to initialize
that variable from the ENV hash if  $WeBWorK::Constants::WEBWORK_DIRECTORY hasn't been initialized already.

-- Mike

In reply to Michael Gage

Re: uninitialized WEBWORK_DIRECTORY

by Hal Sadofsky -

Thanks MIke,

So the thread you referred me to seems to suggest editing WeBWorK/Constants.pm so that it simply doesn't refer to WEBWORK_DIRECTORY.  Is that really safe?  I mean the value of WEBWORK_DIRECTORY wherever I can see it is the same as WEBWORK_ROOT, so I suppose I could substitute that, but I worry about unforeseen consequences.

Or did you mean to define WEBWORK_DIRECTORY in my script?  I've tried that in various ways, none of which make the error messages go away.  For example, I've tried:

$ENV{WEBWORK_DIRECTORY} = '/opt/webwork/webwork2';

and also 

$WeBWorK::Constants::WEBWORK_DIRECTORY = '/opt/webwork/webwork2'; 

neither of which seem to have an effect.

yours,  Hal
 
In reply to Hal Sadofsky

Re: uninitialized WEBWORK_DIRECTORY

by Michael Gage -
I suggest the following line, derived from the webwork.apache2-config. and 
placed near the top of Constants.pm.  I've included some of the surrounding lines.


use strict;
use warnings;

$WeBWorK::Constants::WEBWORK_DIRECTORY = $ENV{WEBWORK_ROOT} unless defined $WeBWorK::Constants::WEBWORK_DIRECTORY;

################################################################################
# WeBWorK::Debug
################################################################################

That way if you are accessing code without passing through webwork.apache2-config  the location of the webwork2 directory will get set from the ENV{WEBWORK_ROOT} variable which is set in your .bashrc or
.cshrc file.   That way scripts run from the command line will still know where the home directory for webwork2 is.

Your second definition should have silenced the warnings (if it is at the top of  the Constants.pm script) but it's not an easily portable solution and we're trying to keep all of the configurations in one place.  You should not 
have to edit Constants.pm to set up a new installation with a different directory structure.

As I mentioned in another thread we are dealing with a legacy problem. People over the years have used several different variables to store the home directory.   

$WeBWorK::Constants::WEBWORK_DIRECTORY  is now the "official" home of  the webwork2 root directory (where the conf file can be found).  

This is initialized in webwork.apache2-config.  

If that file is not used (e.g. when you call a script from the command line) then you have to initialize that constant in each command line script.  Either directly or by referencing the $ENV{WEBWORK_ROOT} variable.  

The line I added above is a reasonable safety feature which handles older scripts which fail to initialize this variable but do have the
$ENV{WEBWORK_ROOT} variable initialized.
In reply to Michael Gage

Re: uninitialized WEBWORK_DIRECTORY

by Hal Sadofsky -

Mike,

Thanks for the very explicit and helpful instructions.  That seems to have made the error message go away!

Hal

(Explain it to me like I'm a golden retriever.)