Skip to content

Commit 22d95eb

Browse files
committed
Convert the conf/database.conf.dist file to a Perl module.
The database layout is now defined in the Perl `WeBWorK::DB::Layout` package. An instance of the `WeBWorK::DB` package is no longer instantiated by passing the layout. Instead it is passed a course environment object. An instance of the `WeBWorK::DB::Layout` package is constructed from that. In addition, the `WeBWorK::DB::Driver`, `WeBWorK::DB::Driver::Null`, and `WeBWorK::DB::Driver::SQL.pm` modules have been deleted. Instead there is the `WeBWorK::DB::Database` module that does everything those modules used to do. It is now the only "driver" for all tables. Although, that never should have been called a driver. The driver is still optional and is `DBD::MariaDB` or `DBD::mysql`. That is what is usually referred to as the driver, not the DBI connection handle which is what the `WeBWorK::DB::Database` module deals with, and what the previous "driver" modules did as well. Furthermore, only one instance of this module is constructed when a `WeBWorK::DB` object is constructed, and that is passed to each table. That is essentially the same as before in terms of DBI connection handles except that before there were multiple `WeBWorK::DB::Driver::SQL` instances that all shared the same DBI conneciton handle via the `connect_cached` call. So the layout is simplified considerably. The "driver", "source", "engine", and "character_set" are no longer options for a table, and there are no "%sqlParams" passed to each table. The only thing that is variable in the layout is the "$courseName" used for the tableOverride. The "source", "engine", and "character_set" are parameters of the `WeBWorK::DB::Database` object and retrieved from there as needed. Since there is no choice of database layout there is no point in having that be part of the authentication module selection in the configuration files. So the `$authen{user_module}` in the configuration files should be either a string naming a single authentication module or an array of strings. For example, ```perl $authen{user_module} = [ 'WeBWorK::Authen::LTIAdvantage', 'WeBWorK::Authen::LTIAdvanced', 'WeBWorK::Authen::Basic_TheLastOption' ]; ``` The old format of `{ '*' => 'WeBWorK::Authen::LTIAdvantage' }` (where `*` meant use this authentication for all database layouts) is still allowed for now, but eventually support for that will be dropped. Several related unused files were deleted. Those are * `bin/check_database_charsets.pl` (This should have never been in the repository.) * `bin/wwdb` (This has been broken for a long time.) * `lib/WeBWorK/DB/Driver/Null.pm` (This was mentioned above, but I don't think this ever was used or even made sense to be used.) * `lib/WeBWorK/Utils/CourseManagement/sql_moodle.pm` (This is not used, I doubt this has worked for a long time, and is no longer supported in any case.) * `lib/WeBWorK/Utils/CourseManagement/sql_single.pm` (Also not used and hasn't been working for a while now.) * `lib/WeBWorK/Utils/DBImportExport.pm` (This hasn't worked for a while now and code that called this in `lib/WeBWorK/DB.pm` was removed.) * `lib/WeBWorK/DB/Schema/NewSQL/VersionedMerge.pm` (This is unused. At some point the `lib/WeBWorK/DB/Schema/NewSQL/Merge.pm` module was updated to handle its functionality directly.)
1 parent 1de70d2 commit 22d95eb

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

53 files changed

+730
-2575
lines changed

bin/addcourse

+9-43
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,6 @@ be granted professor privileges.
3232
3333
=over
3434
35-
=item B<--db-layout>=I<LAYOUT>
36-
37-
The specified database layout will be used in place of the default specified in
38-
F<defaults.config>.
39-
4035
=item B<--users>=I<FILE>
4136
4237
The users listed in the comma-separated text file I<FILE> will be added to the
@@ -77,30 +72,26 @@ BEGIN {
7772
use lib "$ENV{WEBWORK_ROOT}/lib";
7873

7974
use WeBWorK::CourseEnvironment;
80-
81-
# Grab course environment (by reading webwork2/conf/defaults.config)
82-
my $ce = WeBWorK::CourseEnvironment->new;
83-
84-
use WeBWorK::DB;
8575
use WeBWorK::File::Classlist;
8676
use WeBWorK::Utils qw(runtime_use cryptPassword);
8777
use WeBWorK::Utils::CourseManagement qw(addCourse);
8878
use WeBWorK::File::Classlist qw(parse_classlist);
79+
use WeBWorK::DB::Record::User;
80+
use WeBWorK::DB::Record::Password;
81+
use WeBWorK::DB::Record::PermissionLevel;
8982

9083
sub usage_error {
9184
warn "@_\n";
9285
warn "usage: $0 [options] COURSEID\n";
9386
warn "Options:\n";
94-
warn " [--db-layout=LAYOUT]\n";
9587
warn " [--users=FILE [--professors=USERID[,USERID]...] ]\n";
9688
exit;
9789
}
9890

99-
my ($dbLayout, $users, $templates_from) = ('', '', '');
91+
my ($users, $templates_from) = ('', '');
10092
my @professors;
10193

10294
GetOptions(
103-
"db-layout=s" => \$dbLayout,
10495
"users=s" => \$users,
10596
"professors=s" => \@professors,
10697
"templates-from=s" => \$templates_from,
@@ -110,33 +101,16 @@ my $courseID = shift;
110101

111102
usage_error('The COURSEID must be provided.') unless $courseID;
112103

113-
$ce = WeBWorK::CourseEnvironment->new({ courseName => $courseID });
104+
my $ce = WeBWorK::CourseEnvironment->new({ courseName => $courseID });
114105

115106
die "Aborting addcourse: Course ID cannot exceed $ce->{maxCourseIdLength} characters."
116107
if length($courseID) > $ce->{maxCourseIdLength};
117108

118-
if ($dbLayout) {
119-
die "Database layout $dbLayout does not exist in the course environment.",
120-
" (It must be defined in defaults.config.)\n"
121-
unless exists $ce->{dbLayouts}{$dbLayout};
122-
} else {
123-
$dbLayout = $ce->{dbLayoutName};
124-
}
125-
126109
usage_error("Can't specify --professors without also specifying --users.")
127110
if @professors && !$users;
128111

129112
my @users;
130113
if ($users) {
131-
# This is a hack to create records without bringing up a DB object
132-
my $userClass = $ce->{dbLayouts}{$dbLayout}{user}{record};
133-
my $passwordClass = $ce->{dbLayouts}{$dbLayout}{password}{record};
134-
my $permissionClass = $ce->{dbLayouts}{$dbLayout}{permission}{record};
135-
136-
runtime_use($userClass);
137-
runtime_use($passwordClass);
138-
runtime_use($permissionClass);
139-
140114
my @classlist = parse_classlist($users);
141115
for my $record (@classlist) {
142116
my %record = %$record;
@@ -168,9 +142,9 @@ if ($users) {
168142

169143
push @users,
170144
[
171-
$userClass->new(%record),
172-
$record{password} ? $passwordClass->new(user_id => $user_id, password => $record{password}) : undef,
173-
$permissionClass->new(
145+
WeBWorK::DB::Record::User->new(%record),
146+
WeBWorK::DB::Record::Password->new(user_id => $user_id, password => $record{password}),
147+
WeBWorK::DB::Record::PermissionLevel->new(
174148
user_id => $user_id,
175149
permission => defined $professors{$user_id}
176150
? $ce->{userRoles}{professor}
@@ -190,15 +164,7 @@ if ($templates_from) {
190164
$optional_arguments{copyTemplatesHtml} = 1;
191165
}
192166

193-
eval {
194-
addCourse(
195-
courseID => $courseID,
196-
ce => $ce,
197-
courseOptions => { dbLayoutName => $dbLayout },
198-
users => \@users,
199-
%optional_arguments,
200-
);
201-
};
167+
eval { addCourse(courseID => $courseID, ce => $ce, users => \@users, %optional_arguments,); };
202168

203169
die "$@\n" if $@;
204170

bin/change_user_id

+1-1
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ my $ce = WeBWorK::CourseEnvironment->new({
4747
courseName => $courseID
4848
});
4949

50-
my $db = new WeBWorK::DB($ce->{dbLayout});
50+
my $db = WeBWorK::DB->new($ce);
5151
die "Error: $old_user_id does not exist!" unless $db->existsUser($old_user_id);
5252

5353
unless($db->existsUser($new_user_id)) {

bin/check_database_charsets.pl

-10
This file was deleted.

bin/dump-past-answers.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -137,7 +137,7 @@ sub write_past_answers_csv {
137137
next if $courseID eq ($minimal_ce->{admin_course_id} // 'admin') || $courseID eq 'modelCourse';
138138

139139
my $ce = WeBWorK::CourseEnvironment->new({ webwork_dir => $ENV{WEBWORK_ROOT}, courseName => $courseID });
140-
my $db = WeBWorK::DB->new($ce->{dbLayout});
140+
my $db = WeBWorK::DB->new($ce);
141141

142142
my %permissionLabels = reverse %{ $ce->{userRoles} };
143143

bin/importClassList.pl

+2-2
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@ BEGIN
2929

3030
use WeBWorK::CourseEnvironment;
3131

32-
use WeBWorK::DB qw(check_user_id);
32+
use WeBWorK::DB;
3333
use WeBWorK::File::Classlist;
3434
use WeBWorK::Utils qw(cryptPassword);
3535
use WeBWorK::File::Classlist qw(parse_classlist);
@@ -49,7 +49,7 @@ BEGIN
4949
courseName => $courseID
5050
});
5151

52-
my $db = WeBWorK::DB->new($ce->{dbLayout});
52+
my $db = WeBWorK::DB->new($ce);
5353

5454
my $createNew = 1; # Always set to true, so add new users
5555
my $replaceExisting = "none"; # Always set to "none" so no existing accounts are changed

bin/newpassword

+1-1
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,7 @@ my $ce = WeBWorK::CourseEnvironment->new({
9494
courseName => $courseID
9595
});
9696

97-
my $db = new WeBWorK::DB($ce->{dbLayout});
97+
my $db = WeBWorK::DB->new($ce);
9898

9999
dopasswd($db, $user, $newP);
100100
print "Changed password for $user in $courseID\n";

bin/upgrade-database-to-utf8mb4.pl

+1-1
Original file line numberDiff line numberDiff line change
@@ -212,7 +212,7 @@ BEGIN
212212
},
213213
);
214214

215-
my $db = WeBWorK::DB->new($ce->{dbLayouts}{ $ce->{dbLayoutName} });
215+
my $db = WeBWorK::DB->new($ce);
216216
my @table_types = sort(grep { !$db->{$_}{params}{non_native} } keys %$db);
217217

218218
sub checkAndUpdateTableColumnTypes {

bin/ww_purge_old_nonces

+1-1
Original file line numberDiff line numberDiff line change
@@ -72,7 +72,7 @@ my $ce = WeBWorK::CourseEnvironment->new({
7272
courseName => $course,
7373
});
7474

75-
my $db = WeBWorK::DB->new($ce->{dbLayout});
75+
my $db = WeBWorK::DB->new($ce);
7676

7777
my @errors;
7878

bin/wwdb

-129
This file was deleted.

bin/wwsh

+1-1
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ $ce = WeBWorK::CourseEnvironment->new({
5454
});
5555

5656

57-
$db = WeBWorK::DB->new($ce->{dbLayout});
57+
$db = WeBWorK::DB->new($ce);
5858

5959
print <<'EOF';
6060
wwsh - The WeBWorK Shell

conf/README.md

-2
Original file line numberDiff line numberDiff line change
@@ -16,8 +16,6 @@ Basic webwork2 configuration files.
1616
- `localOverrides.conf.dist` should be copied to `localOverrides.conf`. `localOverrides.conf` will be read after the
1717
`defaults.config` file is processed and will overwrite configurations in `defaults.config`. Use this file to make
1818
changes to the settings in `defaults.config`.
19-
- `database.conf.dist` contains database configuration parameters. It is included by `defaults.config`. This file
20-
should not be copied or modified unless you really know what you are doing.
2119

2220
Configuration extension files.
2321

conf/authen_CAS.conf.dist

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,9 +8,7 @@
88
########################################################################################
99

1010
# Set CAS as the authentication module to use.
11-
$authen{user_module} = {
12-
"*" => "WeBWorK::Authen::CAS",
13-
};
11+
$authen{user_module} = 'WeBWorK::Authen::CAS';
1412

1513
# List of authentication modules that may be used to enter the admin course.
1614
# This is used instead of $authen{user_module} when logging into the admin course.

conf/authen_LTI.conf.dist

+3-3
Original file line numberDiff line numberDiff line change
@@ -40,9 +40,9 @@ $debug_lti_grade_passback = 0;
4040
# the LTIAdvantage will be used. If you know a site will not use one or the other, it can be
4141
# commented out. Failover to Basic_TheLastOption is necessary to authenticate with cookie keys.
4242
$authen{user_module} = [
43-
{ '*' => 'WeBWorK::Authen::LTIAdvantage' }, # first try LTI 1.3
44-
{ '*' => 'WeBWorK::Authen::LTIAdvanced' }, # next try LTI 1.1
45-
{ '*' => 'WeBWorK::Authen::Basic_TheLastOption' } # fallback authorization method
43+
'WeBWorK::Authen::LTIAdvantage', # first try LTI 1.3
44+
'WeBWorK::Authen::LTIAdvanced', # next try LTI 1.1
45+
'WeBWorK::Authen::Basic_TheLastOption' # fallback authorization method
4646
];
4747

4848
# List of authentication modules that may be used to enter the admin course.

conf/authen_ldap.conf.dist

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
########################################################################################
99

1010
# Set LDAP as the authentication module to use.
11-
$authen{user_module} = { "*" => "WeBWorK::Authen::LDAP" };
11+
$authen{user_module} = 'WeBWorK::Authen::LDAP';
1212

1313
# List of authentication modules that may be used to enter the admin course.
1414
# This is used instead of $authen{user_module} when logging into the admin course.

0 commit comments

Comments
 (0)