Installation

How to automate init of depths, locations, location_addresses?

Re: How to automate init of depths, locations, location_addresses?

by Michael Gage -
Number of replies: 3

This initialization is done in the subroutine:  InitNonNativeTables()

(searching for that term in the webwork2 directory I get:

~/webwork-docker2/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm:37:                                         listArchivedCourses unarchiveCourse initNonNativeTables);
~/webwork-docker2/webwork2/lib/WeBWorK/ContentGenerator/CourseAdmin.pm:70:     my $table_update_result = initNonNativeTables($ce, $ce->{dbLayoutName});
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:52:     initNonNativeTables
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:1143: =item initNonNativeTables($ce, $db, $dbLayoutName, %options)
~/webwork-docker2/webwork2/lib/WeBWorK/Utils/CourseManagement.pm:1152: sub initNonNativeTables {

so the function is define on line 1152 of .../Utils/CourseManagement.pm and called on line 70 of CourseAdmin.pm (which is the admin course front page)

You should be able to write a short script fragment which you can use with wwsh.  one example of such a fragment is addadmin which is called from the bin directory via    wwsh admin ./addadmin 

You comments in wwsh may be enough to tell you how you could access the initNonNativeTables() function and run it from the command line.

I've not tried it, but it seems like it might work. Let us know how it goes.

-- Mike

In reply to Michael Gage

Re: How to automate init of depths, locations, location_addresses?

by Allan Metts -
Thanks, Mike. I gave it a whirl, but punted in the end and added these tables with a manual login to the Admin course. Looking at intNonNativeTables, it appears that it's doing quite a bit more than addAdmin. If I'm interpreting things correctly, it's consulting a reference DB layout and deciding for itself what represents a "non-native table". I was hoping to find three simple "create table" statements somewhere.

Unfortunately, I'm not fluent at all in PERL -- and even less familiar with WebWork's design and implementation. I pasted the entire subroutine into a fresh file, added a command at the bottom of the file to run that subroutine, and executed the file with wwsh. I got complaints of uninitialized variables and decided I'd reached the end of my competency. :)

I'll post this into GitHub issues in case someone else considers this a worthwhile improvement to the application. Thanks for helping me out!
In reply to Allan Metts

Re: How to automate init of depths, locations, location_addresses?

by Andrew Parker -

instead of copying the subroutine verbatim, import the function itself. It's defined in CourseManagement, so our wwsh script only actually needs two lines.

# tell WeBWorK to import 'initNonNativeTables' from WeBWorK/Utils/CourseManagement.pm
use WeBWorK::Utils::CourseManagement 'initNonNativeTables';

# execute the subroutine as called in CourseAdmin.pm
my $table_update_result = initNonNativeTables($ce, $ce->{dbLayoutName});

# see what's in the return value
warn Dumper($table_update_result);
exit;


In reply to Andrew Parker

Re: How to automate init of depths, locations, location_addresses?

by Allan Metts -

Thanks for posting this, Andrew.  I haven't had a chance to try it on an un-initialized system yet, but it looks like it's exactly what I need.  I'll update the GitHub issue I created previously with your suggestion.