Skip to content

Commit b575e55

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 e4cecdb commit b575e55

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

+728
-2442
lines changed

bin/addcourse

Lines changed: 9 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -18,11 +18,6 @@ be granted professor privileges.
1818
1919
=over
2020
21-
=item B<--db-layout>=I<LAYOUT>
22-
23-
The specified database layout will be used in place of the default specified in
24-
F<defaults.config>.
25-
2621
=item B<--users>=I<FILE>
2722
2823
The users listed in the comma-separated text file I<FILE> will be added to the
@@ -63,30 +58,26 @@ BEGIN {
6358
use lib "$ENV{WEBWORK_ROOT}/lib";
6459

6560
use WeBWorK::CourseEnvironment;
66-
67-
# Grab course environment (by reading webwork2/conf/defaults.config)
68-
my $ce = WeBWorK::CourseEnvironment->new;
69-
70-
use WeBWorK::DB;
7161
use WeBWorK::File::Classlist;
7262
use WeBWorK::Utils qw(runtime_use cryptPassword);
7363
use WeBWorK::Utils::CourseManagement qw(addCourse);
7464
use WeBWorK::File::Classlist qw(parse_classlist);
65+
use WeBWorK::DB::Record::User;
66+
use WeBWorK::DB::Record::Password;
67+
use WeBWorK::DB::Record::PermissionLevel;
7568

7669
sub usage_error {
7770
warn "@_\n";
7871
warn "usage: $0 [options] COURSEID\n";
7972
warn "Options:\n";
80-
warn " [--db-layout=LAYOUT]\n";
8173
warn " [--users=FILE [--professors=USERID[,USERID]...] ]\n";
8274
exit;
8375
}
8476

85-
my ($dbLayout, $users, $templates_from) = ('', '', '');
77+
my ($users, $templates_from) = ('', '');
8678
my @professors;
8779

8880
GetOptions(
89-
"db-layout=s" => \$dbLayout,
9081
"users=s" => \$users,
9182
"professors=s" => \@professors,
9283
"templates-from=s" => \$templates_from,
@@ -96,33 +87,16 @@ my $courseID = shift;
9687

9788
usage_error('The COURSEID must be provided.') unless $courseID;
9889

99-
$ce = WeBWorK::CourseEnvironment->new({ courseName => $courseID });
90+
my $ce = WeBWorK::CourseEnvironment->new({ courseName => $courseID });
10091

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

104-
if ($dbLayout) {
105-
die "Database layout $dbLayout does not exist in the course environment.",
106-
" (It must be defined in defaults.config.)\n"
107-
unless exists $ce->{dbLayouts}{$dbLayout};
108-
} else {
109-
$dbLayout = $ce->{dbLayoutName};
110-
}
111-
11295
usage_error("Can't specify --professors without also specifying --users.")
11396
if @professors && !$users;
11497

11598
my @users;
11699
if ($users) {
117-
# This is a hack to create records without bringing up a DB object
118-
my $userClass = $ce->{dbLayouts}{$dbLayout}{user}{record};
119-
my $passwordClass = $ce->{dbLayouts}{$dbLayout}{password}{record};
120-
my $permissionClass = $ce->{dbLayouts}{$dbLayout}{permission}{record};
121-
122-
runtime_use($userClass);
123-
runtime_use($passwordClass);
124-
runtime_use($permissionClass);
125-
126100
my @classlist = parse_classlist($users);
127101
for my $record (@classlist) {
128102
my %record = %$record;
@@ -154,9 +128,9 @@ if ($users) {
154128

155129
push @users,
156130
[
157-
$userClass->new(%record),
158-
$record{password} ? $passwordClass->new(user_id => $user_id, password => $record{password}) : undef,
159-
$permissionClass->new(
131+
WeBWorK::DB::Record::User->new(%record),
132+
WeBWorK::DB::Record::Password->new(user_id => $user_id, password => $record{password}),
133+
WeBWorK::DB::Record::PermissionLevel->new(
160134
user_id => $user_id,
161135
permission => defined $professors{$user_id}
162136
? $ce->{userRoles}{professor}
@@ -176,15 +150,7 @@ if ($templates_from) {
176150
$optional_arguments{copyTemplatesHtml} = 1;
177151
}
178152

179-
eval {
180-
addCourse(
181-
courseID => $courseID,
182-
ce => $ce,
183-
courseOptions => { dbLayoutName => $dbLayout },
184-
users => \@users,
185-
%optional_arguments,
186-
);
187-
};
153+
eval { addCourse(courseID => $courseID, ce => $ce, users => \@users, %optional_arguments,); };
188154

189155
die "$@\n" if $@;
190156

bin/change_user_id

Lines changed: 1 addition & 1 deletion
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

Lines changed: 0 additions & 10 deletions
This file was deleted.

bin/dump-past-answers.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ sub write_past_answers_csv {
123123
next if $courseID eq ($minimal_ce->{admin_course_id} // 'admin') || $courseID eq 'modelCourse';
124124

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

128128
my %permissionLabels = reverse %{ $ce->{userRoles} };
129129

bin/importClassList.pl

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ BEGIN
1515

1616
use WeBWorK::CourseEnvironment;
1717

18-
use WeBWorK::DB qw(check_user_id);
18+
use WeBWorK::DB;
1919
use WeBWorK::File::Classlist;
2020
use WeBWorK::Utils qw(cryptPassword);
2121
use WeBWorK::File::Classlist qw(parse_classlist);
@@ -35,7 +35,7 @@ BEGIN
3535
courseName => $courseID
3636
});
3737

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

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

bin/newpassword

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ my $ce = WeBWorK::CourseEnvironment->new({
8080
courseName => $courseID
8181
});
8282

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

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

bin/upgrade-database-to-utf8mb4.pl

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ BEGIN
198198
},
199199
);
200200

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

204204
sub checkAndUpdateTableColumnTypes {

bin/ww_purge_old_nonces

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ my $ce = WeBWorK::CourseEnvironment->new({
5858
courseName => $course,
5959
});
6060

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

6363
my @errors;
6464

bin/wwdb

Lines changed: 0 additions & 115 deletions
This file was deleted.

bin/wwsh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ $ce = WeBWorK::CourseEnvironment->new({
4040
});
4141

4242

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

4545
print <<'EOF';
4646
wwsh - The WeBWorK Shell

conf/README.md

Lines changed: 0 additions & 2 deletions
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

Lines changed: 1 addition & 3 deletions
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

Lines changed: 3 additions & 3 deletions
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

Lines changed: 1 addition & 1 deletion
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)