You can subscribe to this list here.
2004 |
Jan
|
Feb
|
Mar
|
Apr
|
May
|
Jun
|
Jul
|
Aug
|
Sep
|
Oct
|
Nov
|
Dec
(58) |
---|---|---|---|---|---|---|---|---|---|---|---|---|
2005 |
Jan
(53) |
Feb
(56) |
Mar
|
Apr
|
May
(30) |
Jun
(78) |
Jul
(121) |
Aug
(155) |
Sep
(77) |
Oct
(61) |
Nov
(45) |
Dec
(94) |
2006 |
Jan
(116) |
Feb
(33) |
Mar
(11) |
Apr
(23) |
May
(60) |
Jun
(89) |
Jul
(130) |
Aug
(109) |
Sep
(124) |
Oct
(63) |
Nov
(82) |
Dec
(45) |
2007 |
Jan
(31) |
Feb
(35) |
Mar
(123) |
Apr
(36) |
May
(18) |
Jun
(134) |
Jul
(133) |
Aug
(241) |
Sep
(126) |
Oct
(31) |
Nov
(15) |
Dec
(5) |
2008 |
Jan
(11) |
Feb
(6) |
Mar
(16) |
Apr
(29) |
May
(43) |
Jun
(149) |
Jul
(27) |
Aug
(29) |
Sep
(37) |
Oct
(20) |
Nov
(4) |
Dec
(6) |
2009 |
Jan
(34) |
Feb
(30) |
Mar
(16) |
Apr
(6) |
May
(1) |
Jun
(32) |
Jul
(22) |
Aug
(7) |
Sep
(18) |
Oct
(50) |
Nov
(22) |
Dec
(8) |
2010 |
Jan
(17) |
Feb
(15) |
Mar
(10) |
Apr
(9) |
May
(67) |
Jun
(30) |
Jul
|
Aug
|
Sep
(2) |
Oct
|
Nov
(1) |
Dec
|
From: <act...@de...> - 2004-12-10 16:20:16
|
Log Message: ----------- mail from: "$RealName via activitymail <activitymail@devel...>" Modified Files: -------------- CVSROOT: loginfo Revision Data ------------- Index: loginfo =================================================================== RCS file: /webwork/cvs/system/CVSROOT/loginfo,v retrieving revision 1.10 retrieving revision 1.11 diff -Lloginfo -Lloginfo -u -r1.10 -r1.11 --- loginfo +++ loginfo @@ -24,4 +24,4 @@ #DEFAULT (echo ""; id; echo %s; date; cat) >> $CVSROOT/CVSROOT/commitlog # or #DEFAULT (echo ""; id; echo %{sVv}; date; cat) >> $CVSROOT/CVSROOT/commitlog -ALL /usr/local/bin/activitymail -cdpf %{sVv} -t "ope...@li..." -u "act...@de..." +ALL /usr/local/bin/activitymail -cdpf %{sVv} -t "ope...@li..." -u `perl -e '$_=(getpwuid $>)[6]; s/,.*//; print'`" via activitymail <act...@de...>" |
From: <act...@de...> - 2004-12-09 23:42:55
|
Log Message: ----------- fixes, uniqueness constraints, CSV list handling * internal subroutines now have `_' prefix. * added uniqneness constraints (has_unique_columns) * added has_cs_list() to declare that a column is a comma-sep. list Modified Files: -------------- webwork2/lib/WeBWorK: DBv3.pm Revision Data ------------- Index: DBv3.pm =================================================================== RCS file: /webwork/cvs/system/webwork2/lib/WeBWorK/DBv3.pm,v retrieving revision 1.3 retrieving revision 1.4 diff -Llib/WeBWorK/DBv3.pm -Llib/WeBWorK/DBv3.pm -u -r1.3 -r1.4 --- lib/WeBWorK/DBv3.pm +++ lib/WeBWorK/DBv3.pm @@ -17,6 +17,7 @@ package WeBWorK::DBv3; use base 'Class::DBI'; use WeBWorK::DBv3::NormalizerMixin; +use Class::DBI::Plugin::AbstractCount; =head1 NAME @@ -177,12 +178,12 @@ =cut -sub datetime_inflate { +sub _datetime_inflate { my $dt = $dt_format->parse_datetime($_[0]) or _croak("invalid date: '$_[0]'"); return $dt->set_time_zone("UTC"); } -sub datetime_deflate { +sub _datetime_deflate { my $dt = $_[0]->clone->set_time_zone("UTC"); # clone to avoid changing timezone of original object return $dt_format->format_datetime($dt); } @@ -195,8 +196,8 @@ $class->has_a( $field => "DateTime", - inflate => \&datetime_inflate, - deflate => \&datetime_deflate, + inflate => \&_datetime_inflate, + deflate => \&_datetime_deflate, ); } @@ -253,7 +254,7 @@ =cut -sub bool_normalizer { $_[0] ? 1 : 0 } +sub _bool_normalizer { $_[0] ? 1 : 0 } sub has_a_boolean { my ($class, $field) = @_; return unless $field; @@ -263,8 +264,94 @@ =back +=head2 MACROS FOR UNIQUENESS CONSTRAINTS + +has_unique_columns() allows you do define uniqueness constraints by listing the +fields that must be unique: + + __PACKAGE__->has_unique_columns($name => qw/field1 field2 field3/); + +$name gives a name to this constraint, which is included in the error message +given when the conditions of the constraint are not met. + =cut +sub has_unique_columns { + my ($class, $name, @columns) = @_; + + $class->_invalid_object_method('has_unique_columns()') if ref $class; + $name or $class->_croak("has_unique_columns needs a name"); + + foreach my $column (@columns) { + # normalize columns, and croak on any invalid columns + my $normalized_column = $class->find_column($column) + or $class->_croak("has_unique_columns: '$column' is not a valid column"); + $column = $normalized_column; + } + + # closure over @columns, $name + my $unique_columns = sub { + my ($self) = @_; + my %search_spec = map { $_ => $self->$_ } @columns; + $search_spec{id} = { '!=', $self->id }; + unless ($self->count_search_where(%search_spec) == 0) { + my $columns = join(",", @columns); + my $values = join(",", map "'$search_spec{$_}'", @columns); + my $fail = @columns == 1 ? "fails" : "fail"; + return $self->_croak("$class ($columns) $fail uniqueness constraint '$name' with ($values)"); + } + }; + + $class->add_trigger(before_create => $unique_columns); + $class->add_trigger(before_update => $unique_columns); +} + +=head2 COMMA-SEPARATED LIST HANDLING + +has_cs_list() allows you to define a column as containing a comma-separated list +of values. It will add an accessor/modifier to the invocant's class with the +suffix C<_list>. + +Note that this handling is pretty dumb, and cannot deal with embedded commas. +This is typically OK, since cs_list fields are usually used to store list of +record IDs or strings that are valid identifiers. (If you really need to store +strings with embedded commas, you may URL-encode them or whatever you like. Just +make sure you decode them on the way out.) + + __PACKAGE__->has_cs_list("problem_order"); + + # results in this method being added to __PACKAGE__ + sub problem_order_list { + my ($self, @list) = @_; + if (@list) { + return $self->problem_order(join(",", @list)); + } else { + return split(",", $self->problem_order); + } + } + +=cut + +sub has_cs_list { + my ($class, $field) = @_; + return unless $field; + + my $method_name = "${class}::${field}_list"; + + # closure over $field + my $cs_list = sub { + my ($self, @list) = @_; + if (@list) { + return $self->$field(join(",", @list)); + } else { + return split(",", $self->$field); + } + }; + + no strict 'refs'; + *$method_name = $cs_list; +} + ################################################################################ # Table classes: each table in the database is a subclass of WeBWorK::DBv3. # (http://devel.webwork.rochester.edu/twiki/bin/view/Webwork/DatabaseSchemaV3) @@ -325,14 +412,16 @@ # FIXME need trigger to set creation_date -sub problem_order_list { - my ($self, @problem_order) = @_; - if (@problem_order) { - return $self->problem_order(join(",", @problem_order)); - } else { - return split(",", $self->problem_order); - } -} +#sub problem_order_list { +# my ($self, @problem_order) = @_; +# if (@problem_order) { +# return $self->problem_order(join(",", @problem_order)); +# } else { +# return split(",", $self->problem_order); +# } +#} + +__PACKAGE__->has_cs_list("problem_order"); ################################################################################ @@ -353,6 +442,9 @@ # FIXME need to make version_due_date_offset/version_answer_date_offset # DateTime::Offset objects +__PACKAGE__->has_unique_columns('override_scope_unique_for_abstract_problem' + => qw/section recitation participant abstract_problem/); + ################################################################################ package WeBWorK::DBv3::SetOverride; @@ -377,14 +469,19 @@ # FIXME need to make version_due_date_offset/version_answer_date_offset # DateTime::Offset objects -sub problem_order_list { - my ($self, @problem_order) = @_; - if (@problem_order) { - return $self->problem_order(join(",", @problem_order)); - } else { - return split(",", $self->problem_order); - } -} +#sub problem_order_list { +# my ($self, @problem_order) = @_; +# if (@problem_order) { +# return $self->problem_order(join(",", @problem_order)); +# } else { +# return split(",", $self->problem_order); +# } +#} + +__PACKAGE__->has_cs_list("problem_order"); + +__PACKAGE__->has_unique_columns('override_scope_unique_for_abstract_set' + => qw/section recitation participant abstract_set/); ################################################################################ @@ -400,6 +497,9 @@ __PACKAGE__->has_many(problem_overrides => "WeBWorK::DBv3::ProblemOverride"); __PACKAGE__->has_many(problem_versions => "WeBWorK::DBv3::ProblemVersion"); +__PACKAGE__->has_unique_columns('set_assignment_unique_for_abstract_problem' + => qw/set_assignment abstract_problem/); + ################################################################################ package WeBWorK::DBv3::SetAssignment; @@ -415,14 +515,19 @@ __PACKAGE__->has_many(set_overrides => "WeBWorK::DBv3::SetOverride"); __PACKAGE__->has_many(set_versions => "WeBWorK::DBv3::SetVersion"); -sub problem_order_list { - my ($self, @problem_order) = @_; - if (@problem_order) { - return $self->problem_order(join(",", @problem_order)); - } else { - return split(",", $self->problem_order); - } -} +#sub problem_order_list { +# my ($self, @problem_order) = @_; +# if (@problem_order) { +# return $self->problem_order(join(",", @problem_order)); +# } else { +# return split(",", $self->problem_order); +# } +#} + +__PACKAGE__->has_cs_list("problem_order"); + +__PACKAGE__->has_unique_columns('abstract_set_unique_for_participant' + => qw/abstract_set participant/); ################################################################################ @@ -439,6 +544,9 @@ __PACKAGE__->has_many(problem_assignments => "WeBWorK::DBv3::ProblemAssignment"); +__PACKAGE__->has_unique_columns('name_unique_for_abstract_set' + => qw/name abstract_set/); + # FIXME need to make version_due_date_offset/version_answer_date_offset # DateTime::Offset objects @@ -448,7 +556,7 @@ use base 'WeBWorK::DBv3'; __PACKAGE__->table("abstract_set"); -__PACKAGE__->columns(All => qw/id course name set_header problem_header +__PACKAGE__->columns(All => qw/id course name set_header hardcopy_header open_date due_date answer_date published problem_order reorder_type reorder_subset_size reorder_time atomicity max_attempts_per_version version_creation_interval versions_per_interval version_due_date_offset @@ -466,14 +574,18 @@ # FIXME need to make version_due_date_offset/version_answer_date_offset # DateTime::Offset objects -sub problem_order_list { - my ($self, @problem_order) = @_; - if (@problem_order) { - return $self->problem_order(join(",", @problem_order)); - } else { - return split(",", $self->problem_order); - } -} +#sub problem_order_list { +# my ($self, @problem_order) = @_; +# if (@problem_order) { +# return $self->problem_order(join(",", @problem_order)); +# } else { +# return split(",", $self->problem_order); +# } +#} + +__PACKAGE__->has_cs_list("problem_order"); + +__PACKAGE__->has_unique_columns('name_unique_for_course' => qw/name course/); ################################################################################ @@ -495,6 +607,8 @@ __PACKAGE__->has_many(set_overrides => "WeBWorK::DBv3::SetOverride"); __PACKAGE__->has_many(problem_overrides => "WeBWorK::DBv3::ProblemOverride"); +__PACKAGE__->has_unique_columns('user_unique_for_course' => qw/user course/); + ################################################################################ package WeBWorK::DBv3::Recitation; @@ -509,6 +623,8 @@ __PACKAGE__->has_many(set_overrides => "WeBWorK::DBv3::SetOverride"); __PACKAGE__->has_many(problem_overrides => "WeBWorK::DBv3::ProblemOverride"); +__PACKAGE__->has_unique_columns('name_unique_for_course' => qw/name course/); + ################################################################################ package WeBWorK::DBv3::Section; @@ -523,6 +639,8 @@ __PACKAGE__->has_many(set_overrides => "WeBWorK::DBv3::SetOverride"); __PACKAGE__->has_many(problem_overrides => "WeBWorK::DBv3::ProblemOverride"); +__PACKAGE__->has_unique_columns('name_unique_for_course' => qw/name course/); + ################################################################################ package WeBWorK::DBv3::Role; @@ -535,14 +653,18 @@ __PACKAGE__->has_many(participants => "WeBWorK::DBv3::Participant"); -sub priv_list { - my ($self, @privs) = @_; - if (@privs) { - return $self->privs(join(",", @privs)); - } else { - return split(",", $self->privs); - } -} +#sub priv_list { +# my ($self, @privs) = @_; +# if (@privs) { +# return $self->privs(join(",", @privs)); +# } else { +# return split(",", $self->privs); +# } +#} + +__PACKAGE__->has_cs_list("privs"); + +__PACKAGE__->has_unique_columns('name_unique' => qw/name/); ################################################################################ @@ -561,6 +683,8 @@ __PACKAGE__->has_many(participants => "WeBWorK::DBv3::Participant"); +__PACKAGE__->has_unique_columns('name_unique' => qw/name/); + ################################################################################ package WeBWorK::DBv3::User; @@ -574,6 +698,13 @@ __PACKAGE__->has_many(participants => "WeBWorK::DBv3::Participant"); +__PACKAGE__->add_constraint("student_id_unique", student_id => sub { + return __PACKAGE__->search(student_id => $_[0])->count == 0; +}); + +__PACKAGE__->has_unique_columns('student_id_unique' => qw/student_id/); +__PACKAGE__->has_unique_columns('login_id_unique' => qw/login_id/); + ################################################################################ package WeBWorK::DBv3::Course; @@ -592,6 +723,8 @@ __PACKAGE__->has_many(recitations => "WeBWorK::DBv3::Recitation"); __PACKAGE__->has_many(participants => "WeBWorK::DBv3::Participant"); __PACKAGE__->has_many(abstract_sets => "WeBWorK::DBv3::AbstractSet"); + +__PACKAGE__->has_unique_columns('name_unique' => qw/name/); ################################################################################ |
From: <act...@de...> - 2004-12-09 16:44:42
|
Log Message: ----------- refactored status/role lookups, added abstract set/problem support Modified Files: -------------- webwork2/bin: ww_db_v2_to_v3 Revision Data ------------- Index: ww_db_v2_to_v3 =================================================================== RCS file: /webwork/cvs/system/webwork2/bin/ww_db_v2_to_v3,v retrieving revision 1.3 retrieving revision 1.4 diff -Lbin/ww_db_v2_to_v3 -Lbin/ww_db_v2_to_v3 -u -r1.3 -r1.4 --- bin/ww_db_v2_to_v3 +++ bin/ww_db_v2_to_v3 @@ -21,7 +21,7 @@ =head1 SYNOPSIS - ww_db_v2_to_v3 course ... + ww_db_v2_to_v3 -crsuv course ... =head1 DESCRIPTION @@ -136,15 +136,30 @@ =item * -WWDBv2 user IDs are converted to login IDs. WWDBv2 set IDs are converted to set -names. WWDBv2 problem IDs are used to determine the C<problem_order> in the -problem's abstract set. +WWDBv2 user IDs are converted to login IDs. =item * -Users with the same user ID in different courses are assumed to be the same +Users with the same v2 user ID in different courses are assumed to be the same user. +=item * + +A user's permission level is used to determine the role to assign to their v3 +participant record. (See L<ROLES>.) If the user has an empty permission level, +they are assigned the role associated with permission level "0". + +=item * + +A user's status abbreviation is used to determine the status to assign to their +v3 participant record. (See L<STATUSES>.) If the user has an empty status, they +are assigned the status "Enrolled". + +=item * + +If a user has a non-empty section or recitation, their v3 participant record +will be assigned to the section or recitation with a matching name. + =back =cut @@ -152,6 +167,7 @@ use strict; use warnings; use Data::Dumper; +use DateTime; use Getopt::Std; BEGIN { @@ -171,7 +187,7 @@ Drop => { allow_course_access => 0, include_in_assignment => 0, include_in_stats => 0, include_in_scoring => 0 }, }; -use constant DEFAULT_STATUS => "Enrolled"; +use constant DEFAULT_STATUS => "C"; use constant DEFAULT_PERMISSION_LEVEL => "0"; our ($opt_c, $opt_r, $opt_s, $opt_u, $opt_v); @@ -213,6 +229,39 @@ ################################################################################ +sub reverse_hash { + my (%hash) = @_; + + my %reverse_hash; + foreach my $key (keys %hash) { + my $value = $hash{$key}; + if (defined $value and not ref $value) { + push @{ $reverse_hash{$value} }, $key; + #} else { + # my $val_string = defined $value ? $value : "UNDEF"; + # warn "pair ( $key => $val_string ) skipped.\n"; + } + } + + return %reverse_hash; +} + +sub listeq { + my ($a, $b) = @_; + return "" unless @$a == @$b; + for (my $i = 0; $i < @$a; $i++) { + return "" unless $a->[$i] eq $b->[$i]; + } + return 1; +} + +sub is_empty { + my ($val) = @_; + return (not defined $val or $val eq ""); +} + +################################################################################ + sub set_up_roles { my ($permissionLevels) = @_; my %permissionLevels = %$permissionLevels; @@ -337,23 +386,6 @@ return %abbrev_to_status_id; } -sub reverse_hash { - my (%hash) = @_; - - my %reverse_hash; - foreach my $key (keys %hash) { - my $value = $hash{$key}; - if (defined $value and not ref $value) { - push @{ $reverse_hash{$value} }, $key; - #} else { - # my $val_string = defined $value ? $value : "UNDEF"; - # warn "pair ( $key => $val_string ) skipped.\n"; - } - } - - return %reverse_hash; -} - ################################################################################ sub copy_course_data { @@ -370,21 +402,31 @@ # First we see if this course already exists. If it does, there's a problem # and we throw an exception. - if (WeBWorK::DBv3::Course->search(name => $courseID)) { + if (search WeBWorK::DBv3::Course(name => $courseID)) { die "Course '$courseID' exists in v3 DB"; } debug("Course '$courseID' doesn't exist in v3 DB -- adding.\n"); - my $v3Course = WeBWorK::DBv3::Course->create({name => $courseID}); + my $v3Course = create WeBWorK::DBv3::Course({name => $courseID}); copy_users($course_db, $v3Course, $abbrev_to_status_id, $level_to_role_id); copy_abstract_data($course_db, $v3Course); } +################################################################################ + sub copy_users { my ($course_db, $v3Course, $abbrev_to_status_id, $level_to_role_id) = @_; + my $DefaultStatus = find_status(DEFAULT_STATUS, $abbrev_to_status_id); + die "Default status '", DEFAULT_STATUS, "' does not correspond to any v3 status.\n" + unless $DefaultStatus; + + my $DefaultRole = find_role(DEFAULT_PERMISSION_LEVEL, $level_to_role_id); + die "Default permission level '", DEFAULT_PERMISSION_LEVEL, "' does not correspond to any v3 role.\n" + unless $DefaultRole; + my @userIDs = $course_db->listUsers; my %Users; @Users{@userIDs} = $course_db->getUsers(@userIDs); my %Passwords; @Passwords{@userIDs} = $course_db->getPasswords(@userIDs); @@ -403,74 +445,65 @@ debug("Processing user '$userID'...\n"); # create/update user record - my ($v3User) = WeBWorK::DBv3::User->search(login_id => $userID); + my ($v3User) = search WeBWorK::DBv3::User(login_id => $userID); if ($v3User) { debug("A user with login_id '$userID' exists in v3 database -- "); if ($opt_u) { + # password record might not exist (annoying...) + my $password = defined $Password ? $Password->password : ""; + debug("updating (as per -u switch).\n"); - $v3User->first_name($User->first_name) if $User->first_name ne ""; - $v3User->last_name($User->first_name) if $User->last_name ne ""; - $v3User->email_address($User->email_address) if $User->email_address ne ""; - $v3User->student_id($User->student_id) if $User->student_id ne ""; - $v3User->password($Password->password) if $Password->password ne ""; + $v3User->first_name($User->first_name) unless is_empty($User->first_name); + $v3User->last_name($User->first_name) unless is_empty($User->last_name); + $v3User->email_address($User->email_address) unless is_empty($User->email_address); + $v3User->student_id($User->student_id) unless is_empty($User->student_id); + $v3User->password($password) unless is_empty($password); $v3User->update; } else { debug("not updating (as per lack of -u switch).\n"); } } else { + # password record might not exist (annoying...) + my $password = defined $Password ? $Password->password : ""; + debug("No user with login_id '$userID' exists in v3 database -- adding.\n"); - $v3User = WeBWorK::DBv3::User->create({ + $v3User = create WeBWorK::DBv3::User({ first_name => $User->first_name, last_name => $User->last_name, email_address => $User->email_address, student_id => $User->student_id, login_id => $User->user_id, - password => $Password->password, + password => $password, }); } # get status - my $status = $User->status; - if ($status eq "") { - $status = DEFAULT_STATUS; - debug("This user has no status -- using '$status'.\n"); - } - my $v3Status_id = $abbrev_to_status_id->{$status}; - my $v3Status; - if (defined $v3Status_id) { - debug("This user has status '", $User->status, "', which maps to v3 status ID '$v3Status_id'.\n"); - $v3Status = WeBWorK::DBv3::Status->retrieve($v3Status_id); - } else { - debug("This user has status '", $User->status, "', which doesn't map to any v3 status.\n"); + my $v3Status = find_status($User->status, $abbrev_to_status_id); + unless ($v3Status) { + debug("Using default status '", $DefaultStatus->name, "'.\n"); + $v3Status = $DefaultStatus; } # get role - my $level = $PermissionLevel->permission; - if ($level eq "") { - $level = DEFAULT_PERMISSION_LEVEL; - debug("This user has no permission level -- using '$level'.\n"); - } - my $v3Role_id = $level_to_role_id->{$level}; - my $v3Role; - if (defined $v3Role_id) { - debug("This user has permission level '", $PermissionLevel->permission, "', which maps to v3 role ID '$v3Role_id'.\n"); - $v3Role = WeBWorK::DBv3::Role->retrieve($v3Role_id); - } else { - debug("This user has permission level '", $PermissionLevel->permission, "', which doesn't map to any v3 role.\n"); + my $level = defined $PermissionLevel ? $PermissionLevel->permission : ""; + my $v3Role = find_role($level, $level_to_role_id); + unless ($v3Role) { + debug("Using default role '", $DefaultRole->name, "'.\n"); + $v3Role = $DefaultRole; } # find/create section record my $section = $User->section; my $v3Section; - if ($section ne "") { + if (is_empty($section)) { debug("This user has section '$section'.\n"); - ($v3Section) = WeBWorK::DBv3::Section->search(course => $v3Course->id, name => $section); + ($v3Section) = search WeBWorK::DBv3::Section(course => $v3Course, name => $section); if ($v3Section) { debug("This corresponds to existing section ID $v3Section in v3 database.\n"); } else { debug("No corresponding section exists in v3 DB -- adding.\n"); - $v3Section = WeBWorK::DBv3::Section->create({ - course => $v3Course->id, + $v3Section = create WeBWorK::DBv3::Section({ + course => $v3Course, name => $section, }); debug("Added section '", $v3Section->name, "' (ID $v3Section).\n"); @@ -479,19 +512,18 @@ debug("This user has no section.\n"); } - # find/create recitation record my $recitation = $User->recitation; my $v3Recitation; - if ($recitation ne "") { + if (is_empty($recitation)) { debug("This user has recitation '$recitation'.\n"); - ($v3Recitation) = WeBWorK::DBv3::Recitation->search(course => $v3Course->id, name => $User->recitation); + ($v3Recitation) = search WeBWorK::DBv3::Recitation(course => $v3Course, name => $User->recitation); if ($v3Recitation) { debug("This correponds to existing recitation ID $v3Recitation in v3 database.\n"); } else { debug("No corresponding recitation exists in v3 DB -- adding.\n"); - $v3Recitation = WeBWorK::DBv3::Recitation->create({ - course => $v3Course->id, + $v3Recitation = create WeBWorK::DBv3::Recitation({ + course => $v3Course, name => $User->recitation, }); debug("Added recitation '", $v3Recitation->name, "' (ID $v3Recitation).\n"); @@ -501,34 +533,159 @@ } # create participant record - debug("Adding participant record for user '", $v3User->login_id, "' (ID $v3User).\n"); - my $sectionID = $v3Section->id if defined $v3Section; - my $recitationID = $v3Recitation->id if defined $v3Recitation; - my $v3Participant = WeBWorK::DBv3::Participant->create({ - course => $v3Course->id, - user => $v3User->id, - status => $v3Status->id, - role => $v3Role->id, - section => $sectionID, - recitation => $recitationID, + debug("Adding participant record for user '$userID'..."); + #my $sectionID = $v3Section->id if defined $v3Section; + #my $recitationID = $v3Recitation->id if defined $v3Recitation; + my $v3Participant = create WeBWorK::DBv3::Participant({ + course => $v3Course, + user => $v3User, + status => $v3Status, + role => $v3Role, + section => $v3Section, + recitation => $v3Recitation, comment => $User->comment, }); + debug(" added participant ID $v3Participant.\n"); } } -sub copy_abstract_data { - my ($course_db, $v3Course) = @_; +sub find_status { + my ($status, $abbrev_to_status_id) = @_; + return if is_empty($status); + my $v3Status_id = $abbrev_to_status_id->{$status}; + my $v3Status; + if (defined $v3Status_id) { + #debug("Status '$status' maps to v3 status ID '$v3Status_id'.\n"); + $v3Status = retrieve WeBWorK::DBv3::Status($v3Status_id); + } else { + #debug("Status '$status' doesn't map to any v3 status.\n"); + } + + return $v3Status; +} + +sub find_role { + my ($level, $level_to_role_id) = @_; + + return if is_empty($level); + + my $v3Role_id = $level_to_role_id->{$level}; + my $v3Role; + if (defined $v3Role_id) { + #debug("Permission level '$level' maps to v3 role ID '$v3Role_id'.\n"); + $v3Role = retrieve WeBWorK::DBv3::Role($v3Role_id); + } else { + #debug("Permission level '$level' doesn't map to any v3 role.\n"); + } + + return $v3Role; } ################################################################################ -sub listeq { - my ($a, $b) = @_; - return "" unless @$a == @$b; - for (my $i = 0; $i < @$a; $i++) { - return "" unless $a->[$i] eq $b->[$i]; +sub copy_abstract_data { + my ($course_db, $v3Course) = @_; + + my @globalSetIDs = $course_db->listGlobalSets; + my %GlobalSets; @GlobalSets{@globalSetIDs} = $course_db->getGlobalSets(@globalSetIDs); + + foreach my $globalSetID (keys %GlobalSets) { + my $GlobalSet = $GlobalSets{$globalSetID}; + + unless (defined $GlobalSet) { + debug("Global set record for global set ID '$globalSetID' not found -- skipping.\n"); + next; + } + + debug("Processing global set '$globalSetID'...\n"); + + # set up some fields that need setting up + # (if the conditional is false, the variable is left undefined) + + # convert empty strings to undefined values + my $set_header = $GlobalSet->set_header unless is_empty($GlobalSet->set_header); + my $hardcopy_header = $GlobalSet->hardcopy_header unless is_empty($GlobalSet->hardcopy_header); + + # convert + my $open_date = DateTime->from_epoch(epoch => $GlobalSet->open_date); + my $due_date = DateTime->from_epoch(epoch => $GlobalSet->due_date); + my $answer_date = DateTime->from_epoch(epoch => $GlobalSet->answer_date); + + # create abstract_set record + debug("Adding abstract_set record for global set '$globalSetID'..."); + my $v3AbsSet = create WeBWorK::DBv3::AbstractSet({ + course => $v3Course, + name => $GlobalSet->set_id, + set_header => $set_header, + hardcopy_header => $hardcopy_header, + open_date => $open_date, + due_date => $due_date, + answer_date => $answer_date, + published => $GlobalSet->published, + }); + debug(" added abstract_set ID '$v3AbsSet'.\n"); + + my @globalProblemIDs = sort { $a <=> $b } $course_db->listGlobalProblems($globalSetID); + warn "globalProblemIDs=@globalProblemIDs\n"; + my %GlobalProblems; @GlobalProblems{@globalProblemIDs} + = $course_db->getGlobalProblems(map { [ $globalSetID, $_ ] } @globalProblemIDs); + + my @problem_order; + + foreach my $globalProblemID (@globalProblemIDs) { + my $GlobalProblem = $GlobalProblems{$globalProblemID}; + + unless (defined $GlobalProblem) { + warn "Global problem record for global problem ID '$globalProblemID' in set ID '$globalSetID' not found -- skipping.\n"; + next; + } + + debug("Processing global problem '$globalProblemID'...\n"); + + # convert max_attempts of -1 to undef + my $max_attempts_per_version = $GlobalProblem->max_attempts + if $GlobalProblem->max_attempts >= 0; + + # create abstract_problem record + debug("Adding abstract_set record for global problem '$globalProblemID'..."); + my $v3AbsProb = create WeBWorK::DBv3::AbstractProblem({ + abstract_set => $v3AbsSet, + name => "Legacy problem $globalProblemID", + source_type => "file", + source_file => $GlobalProblem->source_file, + weight => $GlobalProblem->value, + max_attempts_per_version => $max_attempts_per_version, + version_creation_interval => undef, + versions_per_interval => 1, + version_due_date_offset => undef, + version_answer_date_offset => undef, + }); + debug(" added abstract_problem ID '$v3AbsProb'.\n"); + + push @problem_order, $v3AbsProb->id; + } + + # update problem order + debug("Setting problem order to: '@problem_order'..."); + $v3AbsSet->problem_order_list(@problem_order); + $v3AbsSet->update; + debug(" done.\n"); } - return 1; } + + + + + + + + + + + + + + + |
From: <all...@mu...> - 2004-12-09 16:35:07
|
From: <act...@de...> - 2004-12-09 15:06:12
|
From: Sam H. <act...@de...> - 2004-12-09 14:40:47
|
From: Sam H. <act...@de...> - 2004-12-09 06:33:27
|
From: Sam H. <sh...@de...> - 2004-12-09 06:17:52
|
From: <all...@mu...> - 2004-12-09 03:21:49
|
From: Sam H. <som...@mu...> - 2004-12-09 02:47:40
|
From: Sam H. <sa...@uo...> - 2004-12-09 02:28:44
|
From: Sam H. <sa...@uo...> - 2004-12-09 02:13:37
|
From: Sam H. <sa...@uo...> - 2004-12-08 19:09:48
|
Testing... 1... 2... 3... -s...@uo... |