[LON-CAPA-cvs] cvs: loncom /publisher lonpublisher.pm
albertel
lon-capa-cvs@mail.lon-capa.org
Mon, 21 Oct 2002 16:58:21 -0000
albertel Mon Oct 21 12:58:21 2002 EDT
Modified files:
/loncom/publisher lonpublisher.pm
Log:
- Checks for duplicated IDs, dosent allow publishing if this condition exists
- BUG#804
Index: loncom/publisher/lonpublisher.pm
diff -u loncom/publisher/lonpublisher.pm:1.105 loncom/publisher/lonpublisher.pm:1.106
--- loncom/publisher/lonpublisher.pm:1.105 Sun Oct 20 14:39:36 2002
+++ loncom/publisher/lonpublisher.pm Mon Oct 21 12:58:21 2002
@@ -1,7 +1,7 @@
# The LearningOnline Network with CAPA
# Publication Handler
#
-# $Id: lonpublisher.pm,v 1.105 2002/10/20 18:39:36 www Exp $
+# $Id: lonpublisher.pm,v 1.106 2002/10/21 16:58:21 albertel Exp $
#
# Copyright Michigan State University Board of Trustees
#
@@ -488,6 +488,10 @@
my $maxindex=10;
my $maxid=10;
my $needsfixup=0;
+ my $duplicateids=0;
+
+ my %allids;
+ my %duplicatedids;
my $parser=HTML::LCParser->new($content);
my $token;
@@ -498,6 +502,12 @@
if ($counter eq 'id') {
if (defined($token->[2]->{'id'})) {
$maxid=($token->[2]->{'id'}>$maxid)?$token->[2]->{'id'}:$maxid;
+ if (exists($allids{$token->[2]->{'id'}})) {
+ $duplicateids=1;
+ $duplicatedids{$token->[2]->{'id'}}=1;
+ } else {
+ $allids{$token->[2]->{'id'}}=1;
+ }
} else {
$needsfixup=1;
}
@@ -511,7 +521,8 @@
}
}
}
- return ($needsfixup,$maxid,$maxindex);
+ return ($needsfixup,$maxid,$maxindex,$duplicateids,
+ (keys(%duplicatedids)));
}
#########################################
@@ -580,8 +591,16 @@
$content=join('',<$org>);
}
- my ($needsfixup,$maxid,$maxindex)=&get_max_ids_indices(\$content);
+ my ($needsfixup,$maxid,$maxindex,$duplicateids,@duplicatedids)=
+ &get_max_ids_indices(\$content);
+ print $logfile ("Got $needsfixup,$maxid,$maxindex,$duplicateids--".
+ join(', ',@duplicatedids));
+ if ($duplicateids) {
+ print $logfile "Duplicate ID(s) exist, ".join(', ',@duplicatedids)."\n";
+ my $outstring='<font color="red">Unable to publish file, it contains duplicated ID(s), ID(s) need to be unique. The duplicated ID(s) are: '.join(', ',@duplicatedids).'</font>';
+ return ($outstring,1);
+ }
if ($needsfixup) {
print $logfile "Needs ID and/or index fixup\n".
"Max ID : $maxid (min 10)\n".
@@ -705,7 +724,7 @@
print $logfile "Does not need ID and/or index fixup\n";
}
- return ($outstring,%allow);
+ return ($outstring,0,%allow);
}
#########################################
@@ -810,8 +829,10 @@
}
# ------------------------------------------------------------- IDs and indices
- my $outstring;
- ($outstring,%allow)=&fix_ids_and_indices($logfile,$source,$target);
+ my ($outstring,$error);
+ ($outstring,$error,%allow)=&fix_ids_and_indices($logfile,$source,
+ $target);
+ if ($error) { return $outstring; }
# ------------------------------------------------------------ Construct Allows
$scrout.='<h3>Dependencies</h3>';