version 1.13, 2019/06/29 23:21:05
|
version 1.17, 2022/03/15 18:18:31
|
Line 30
|
Line 30
|
package Apache::lonclonecourse; |
package Apache::lonclonecourse; |
use LONCAPA; |
use LONCAPA; |
use Apache::lonnet; |
use Apache::lonnet; |
|
use Apache::lonlocal; |
use DateTime(); |
use DateTime(); |
use DateTime::TimeZone; |
use DateTime::TimeZone; |
|
|
Line 107 sub rewritefile {
|
Line 108 sub rewritefile {
|
|
|
sub copyfile { |
sub copyfile { |
my ($origcrsid,$newcrsid,$which)=@_; |
my ($origcrsid,$newcrsid,$which)=@_; |
unless ($which=~/\.sequence$/) { |
unless ($which=~/\.(page|sequence)$/) { |
return &writefile($newcrsid,$which, |
return &writefile($newcrsid,$which, |
&readfile($origcrsid,$which)); |
&readfile($origcrsid,$which)); |
} else { |
} else { |
Line 130 sub copyfile {
|
Line 131 sub copyfile {
|
# =============================================================== Copy a dbfile |
# =============================================================== Copy a dbfile |
|
|
sub copydb { |
sub copydb { |
my ($origcrsid,$newcrsid,$which)=@_; |
my ($origcrsid,$newcrsid,$which,$newinstcode,$newowner,$tinyurls)=@_; |
$which=~s/\.db$//; |
$which=~s/\.db$//; |
my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid); |
my %origcrsdata=&Apache::lonnet::coursedescription($origcrsid); |
my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid); |
my %newcrsdata= &Apache::lonnet::coursedescription($newcrsid); |
|
if (($which eq 'tiny') && ($tinyurls eq 'delete')) { |
|
return (); |
|
} |
|
my @info; |
my %data=&Apache::lonnet::dump |
my %data=&Apache::lonnet::dump |
($which,$origcrsdata{'domain'},$origcrsdata{'num'}); |
($which,$origcrsdata{'domain'},$origcrsdata{'num'}); |
foreach my $key (keys(%data)) { |
foreach my $key (keys(%data)) { |
if ($key=~/^internal./) { delete($data{$key}); } |
if ($key=~/^internal./) { delete($data{$key}); } |
} |
} |
return &Apache::lonnet::put |
if ($which =~ /^exttool_\d+$/) { |
($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'}); |
if ($origcrsdata{'description'} ne $newcrsdata{'description'}) { |
|
$data{'crstitle'} =~s/\Q$origcrsdata{'description'}\E/$newcrsdata{'description'}/; |
|
} |
|
if ($origcrsdata{'internal.coursecode'} ne $newinstcode) { |
|
$data{'crslabel'} =~ s/\Q$origcrsdata{'internal.coursecode'}\E/$newinstcode/; |
|
} |
|
} elsif ($which eq 'tiny') { |
|
my $oldprefix = 'uploaded/'.$origcrsdata{'domain'}.'/'.$origcrsdata{'num'}.'/'; |
|
my $newprefix = 'uploaded/'.$newcrsdata{'domain'}.'/'. $newcrsdata{'num'}.'/'; |
|
my (%domtiny,%tocreate,@todelete,$numnew,$errors); |
|
if (($tinyurls eq 'transfer') && (keys(%data))) { |
|
unless (($origcrsdata{'internal.courseowner'} eq $newowner) && |
|
($origcrsdata{'domain'} eq $newcrsdata{'domain'})) { |
|
$tinyurls = 'create'; |
|
push(@info,{ |
|
mt => "Action for URL shortcut(s) changed from 'transfer' to 'create' ". |
|
"because requirements of same owner and some course domain ". |
|
"for new course and original course not met.", |
|
args => [], |
|
}); |
|
} |
|
} |
|
foreach my $key (keys(%data)) { |
|
my $code = $data{$key}; |
|
my $newkey = $key; |
|
$newkey =~ s{\Q$oldprefix\E}{$newprefix}g; |
|
if ($tinyurls eq 'transfer') { |
|
$data{$newkey} = $code; |
|
$domtiny{$code} = $newcrsdata{'num'}.'&'.$newkey; |
|
push(@todelete,$key); |
|
} else { |
|
$tocreate{$newcrsdata{'num'}.'&'.$newkey} = 1; |
|
} |
|
delete($data{$key}); |
|
} |
|
if (keys(%tocreate)) { |
|
($numnew,$errors) = &Apache::loncommon::make_short_symbs($newcrsdata{'domain'}, |
|
$newcrsdata{'num'}, |
|
\%tocreate,$newowner); |
|
if ((ref($errors) eq 'ARRAY') && (@{$errors} > 0)) { |
|
push(@info,{ |
|
mt => 'Error(s) when creating URL shortcut(s) in new course for equivalent '. |
|
'resource(s)/folder(s) in original course: [_1]', |
|
args => [join(', ',@{$errors})], |
|
}); |
|
} |
|
if ($numnew) { |
|
push(@info,{ |
|
mt => 'New URL shortcut(s) in new course for [quant,_1,item] to replicate '. |
|
'shortcut(s) for equivalent(s) in original course.', |
|
args => [$numnew], |
|
}); |
|
} |
|
return @info; |
|
} elsif (keys(%domtiny)) { |
|
my $configuname = &Apache::lonnet::get_domainconfiguser($newcrsdata{'domain'}); |
|
my $putdomres = &Apache::lonnet::put('tiny',\%domtiny,$newcrsdata{'domain'},$configuname); |
|
if ($putdomres eq 'ok') { |
|
my $delres = &Apache::lonnet::del('tiny',\@todelete, |
|
$origcrsdata{'domain'}, |
|
$origcrsdata{'num'}); |
|
|
|
if ($delres eq 'ok') { |
|
push(@info,{ |
|
mt => 'URL shortcut(s) for [quant,_1,item] transferred, and '. |
|
'now point to resource(s)/folder(s) in new course instead of '. |
|
'equivalent(s) in original course.', |
|
args => [scalar(keys(%domtiny))], |
|
}); |
|
} else { |
|
push(@info,{ |
|
mt => 'Failed to delete URL shortcut(s) in original course '. |
|
'when attempting to transfer to new course.', |
|
args => [], |
|
}); |
|
} |
|
} else { |
|
push(@info,{ |
|
mt => 'Failed to store update of target course for URL shortcut(s) in '. |
|
'domain records.', |
|
args => [], |
|
}); |
|
return @info; |
|
} |
|
} |
|
} elsif ($which eq 'lti') { |
|
foreach my $key (keys($data)) { |
|
if (ref($data{$key}) eq 'HASH') { |
|
if (exists($data{$key}{'usable'})) { |
|
delete($data{$key}{'usable'}); |
|
} |
|
} |
|
} |
|
} |
|
my $putres = &Apache::lonnet::put |
|
($which,\%data,$newcrsdata{'domain'},$newcrsdata{'num'}); |
|
return @info; |
} |
} |
|
|
# ========================================================== Copy resourcesdata |
# ========================================================== Copy resourcesdata |
Line 251 sub copyuserfiles {
|
Line 352 sub copyuserfiles {
|
©file($origcrsid,$newcrsid,$_); |
©file($origcrsid,$newcrsid,$_); |
} |
} |
} |
} |
|
return; |
} |
} |
# ========================================================== Copy all userfiles |
# ========================================================== Copy all userfiles |
|
|
sub copydbfiles { |
sub copydbfiles { |
my ($origcrsid,$newcrsid)=@_; |
my ($origcrsid,$newcrsid,$newinstcode,$newowner,$tinyurls)=@_; |
|
my @copyinfo; |
|
|
my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|); |
my ($origcrs_discussion) = ($origcrsid=~m|^/(.*)|); |
$origcrs_discussion=~s|/|_|g; |
$origcrs_discussion=~s|/|_|g; |
foreach (&crsdirlist($origcrsid)) { |
foreach (&crsdirlist($origcrsid)) { |
if ($_=~/\.db$/) { |
if ($_=~/\.db$/) { |
unless ($_=~/^(nohist\_|disclikes|discussiontimes|classlist|versionupdate |
unless ($_=~/^(nohist\_|disclikes|discussiontimes|classlist|versionupdate |
|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations |
|resourcedata|\Q$origcrs_discussion\E|slots|slot_reservations |
|gradingqueue|reviewqueue|CODEs|groupmembership|comm_block)/) { |
|gradingqueue|reviewqueue|CODEs|groupmembership|comm_block)/) { |
©db($origcrsid,$newcrsid,$_); |
my @info = ©db($origcrsid,$newcrsid,$_,$newinstcode,$newowner, |
|
$tinyurls); |
|
if (@info) { |
|
push(@copyinfo,@info); |
|
} |
|
} |
} |
} |
} |
|
} |
} |
|
return @copyinfo; |
} |
} |
|
|
# ======================================================= Copy all course files |
# ======================================================= Copy all course files |
|
|
sub copycoursefiles { |
sub copycoursefiles { |
my ($origcrsid,$newcrsid,$date_mode,$date_shift)=@_; |
my ($origcrsid,$newcrsid,$date_mode,$date_shift,$newinstcode,$newowner, |
|
$tinyurls)=@_; |
©userfiles($origcrsid,$newcrsid); |
©userfiles($origcrsid,$newcrsid); |
©dbfiles($origcrsid,$newcrsid); |
my @info = ©dbfiles($origcrsid,$newcrsid,$newinstcode,$newowner,$tinyurls); |
©resourcedb($origcrsid,$newcrsid,$date_mode,$date_shift); |
©resourcedb($origcrsid,$newcrsid,$date_mode,$date_shift); |
|
return @info; |
} |
} |
|
|
1; |
1; |