[system] / branches / rel-2-1-patches / webwork2 / bin / ww_db_v2_to_v3 Repository:
ViewVC logotype

Diff of /branches/rel-2-1-patches/webwork2/bin/ww_db_v2_to_v3

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

Revision 3021 Revision 3075
1#!/usr/bin/env perl 1#!/usr/bin/env perl
2################################################################################ 2################################################################################
3# WeBWorK Online Homework Delivery System 3# WeBWorK Online Homework Delivery System
4# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/ 4# Copyright © 2000-2003 The WeBWorK Project, http://openwebwork.sf.net/
5# $CVSHeader: webwork2/bin/ww_db_v2_to_v3,v 1.1 2004/11/25 05:50:51 sh002i Exp $ 5# $CVSHeader: webwork2/bin/ww_db_v2_to_v3,v 1.4 2004/12/09 16:30:12 sh002i Exp $
6# 6#
7# This program is free software; you can redistribute it and/or modify it under 7# This program is free software; you can redistribute it and/or modify it under
8# the terms of either: (a) the GNU General Public License as published by the 8# the terms of either: (a) the GNU General Public License as published by the
9# Free Software Foundation; either version 2, or (at your option) any later 9# Free Software Foundation; either version 2, or (at your option) any later
10# version, or (b) the "Artistic License" which comes with this package. 10# version, or (b) the "Artistic License" which comes with this package.
294 294
295 # look at existing roles to see if we can avoid adding some new ones 295 # look at existing roles to see if we can avoid adding some new ones
296 my $i = retrieve_all WeBWorK::DBv3::Role; 296 my $i = retrieve_all WeBWorK::DBv3::Role;
297 while (my $Role = $i->next) { 297 while (my $Role = $i->next) {
298 $role_names{$Role->name} = 1; 298 $role_names{$Role->name} = 1;
299 my @role_privs = sort $Role->priv_list; 299 my @role_privs = sort $Role->privs_list;
300 300
301 foreach my $level (keys %levels) { 301 foreach my $level (keys %levels) {
302 if (listeq($levels{$level}, \@role_privs)) { 302 if (listeq($levels{$level}, \@role_privs)) {
303 debug("Permission level '$level' is already represented as role '", 303 debug("Permission level '$level' is already represented as role '",
304 $Role->name, "' (ID $Role) -- skipping.\n"); 304 $Role->name, "' (ID $Role) -- skipping.\n");
323 } 323 }
324 } 324 }
325 325
326 my @privs = @{ $levels{$level} }; 326 my @privs = @{ $levels{$level} };
327 327
328 my $Role = create WeBWorK::DBv3::Role({name => $name }); 328 my $Role = create WeBWorK::DBv3::Role({name => $name});
329 $Role->priv_list(@privs); 329 $Role->privs_list(@privs);
330 $Role->update; 330 $Role->update;
331 debug("Added role '", $Role->name, "' (ID $Role) with privileges '@privs'.\n"); 331 debug("Added role '", $Role->name, "' (ID $Role) with privileges '@privs'.\n");
332 $level_to_role_id{$level} = $Role->id; 332 $level_to_role_id{$level} = $Role->id;
333 } 333 }
334 } else { 334 } else {
398 courseName => $courseID, 398 courseName => $courseID,
399 }); 399 });
400 400
401 my $course_db = WeBWorK::DB->new($course_ce->{dbLayout}); 401 my $course_db = WeBWorK::DB->new($course_ce->{dbLayout});
402 402
403 # First we see if this course already exists. If it does, there's a problem 403 debug("Adding course '$courseID' to v3 DB.\n");
404 # and we throw an exception.
405 if (search WeBWorK::DBv3::Course(name => $courseID)) {
406 die "Course '$courseID' exists in v3 DB";
407 }
408
409 debug("Course '$courseID' doesn't exist in v3 DB -- adding.\n");
410 my $v3Course = create WeBWorK::DBv3::Course({name => $courseID}); 404 my $v3Course = eval { create WeBWorK::DBv3::Course({name => $courseID}) };
405 $@ =~ /Duplicate entry/ and die "Course '$courseID' exists in v3 DB.\n";
406 $@ and die $@;
411 407
412 copy_users($course_db, $v3Course, $abbrev_to_status_id, $level_to_role_id); 408 copy_users($course_db, $v3Course, $abbrev_to_status_id, $level_to_role_id);
413 409
414 copy_abstract_data($course_db, $v3Course); 410 # { $globalSetID => [ $v3AbsSet->id, { $globalProblemID => $vAbsProb->id, ... }, ... }
411 my %global_set_id_to_abstract_set_data = copy_abstract_data($course_db, $v3Course);
415} 412}
416 413
417################################################################################ 414################################################################################
418 415
419sub copy_users { 416sub copy_users {
586################################################################################ 583################################################################################
587 584
588sub copy_abstract_data { 585sub copy_abstract_data {
589 my ($course_db, $v3Course) = @_; 586 my ($course_db, $v3Course) = @_;
590 587
588 my %global_set_id_to_abstract_set_data;
589
591 my @globalSetIDs = $course_db->listGlobalSets; 590 my @globalSetIDs = $course_db->listGlobalSets;
592 my %GlobalSets; @GlobalSets{@globalSetIDs} = $course_db->getGlobalSets(@globalSetIDs); 591 my %GlobalSets; @GlobalSets{@globalSetIDs} = $course_db->getGlobalSets(@globalSetIDs);
593 592
594 foreach my $globalSetID (keys %GlobalSets) { 593 foreach my $globalSetID (keys %GlobalSets) {
595 my $GlobalSet = $GlobalSets{$globalSetID}; 594 my $GlobalSet = $GlobalSets{$globalSetID};
624 due_date => $due_date, 623 due_date => $due_date,
625 answer_date => $answer_date, 624 answer_date => $answer_date,
626 published => $GlobalSet->published, 625 published => $GlobalSet->published,
627 }); 626 });
628 debug(" added abstract_set ID '$v3AbsSet'.\n"); 627 debug(" added abstract_set ID '$v3AbsSet'.\n");
628
629
630 my %problem_mapping;
629 631
630 my @globalProblemIDs = sort { $a <=> $b } $course_db->listGlobalProblems($globalSetID); 632 my @globalProblemIDs = sort { $a <=> $b } $course_db->listGlobalProblems($globalSetID);
631 warn "globalProblemIDs=@globalProblemIDs\n"; 633 warn "globalProblemIDs=@globalProblemIDs\n";
632 my %GlobalProblems; @GlobalProblems{@globalProblemIDs} 634 my %GlobalProblems; @GlobalProblems{@globalProblemIDs}
633 = $course_db->getGlobalProblems(map { [ $globalSetID, $_ ] } @globalProblemIDs); 635 = $course_db->getGlobalProblems(map { [ $globalSetID, $_ ] } @globalProblemIDs);
663 version_answer_date_offset => undef, 665 version_answer_date_offset => undef,
664 }); 666 });
665 debug(" added abstract_problem ID '$v3AbsProb'.\n"); 667 debug(" added abstract_problem ID '$v3AbsProb'.\n");
666 668
667 push @problem_order, $v3AbsProb->id; 669 push @problem_order, $v3AbsProb->id;
670
671 $problem_mapping{$globalProblemID} = $v3AbsProb->id;
668 } 672 }
669 673
670 # update problem order 674 # update problem order
671 debug("Setting problem order to: '@problem_order'..."); 675 debug("Setting problem order to: '@problem_order'...");
672 $v3AbsSet->problem_order_list(@problem_order); 676 $v3AbsSet->problem_order_list(@problem_order);
673 $v3AbsSet->update; 677 $v3AbsSet->update;
674 debug(" done.\n"); 678 debug(" done.\n");
679
680 $global_set_id_to_abstract_set_data{$globalSetID} = [ $v3AbsSet->id, \%problem_mapping ];
675 } 681 }
682
683 return %global_set_id_to_abstract_set_data;
676} 684}
677 685
686################################################################################
678 687
688sub copy_assignment_data {
689 my ($course_db, $v3Course, $global_set_id_to_abstract_set_data) = @_;
690
691 my $participant_iter = WeBWorK::DBv3::Participant->search(course => $v3Course);
692
693 while (my $Participant = $participant_iter->next) {
694 my @userSetIDs = $course_db->listUserSets($Participant->user->login_id);
695 $v3AbsSet->
696 }
697}
679 698
680 699sub copy_single_assignment {
681 700 my ($course_db, $v3Course, $v3Participant, $v3AbsSet, $global_set_id_to_abstract_set_data) = @_;
682 701
683 702
684 703}
685
686
687
688
689
690
691

Legend:
Removed from v.3021  
changed lines
  Added in v.3075

aubreyja at gmail dot com
ViewVC Help
Powered by ViewVC 1.0.9