[LON-CAPA-cvs] cvs: loncom /interface groupboards.pm
raeburn
lon-capa-cvs@mail.lon-capa.org
Thu, 20 Jul 2006 15:51:12 -0000
raeburn Thu Jul 20 11:51:12 2006 EDT
Modified files:
/loncom/interface groupboards.pm
Log:
Creating group bulletin boards now uses lonnet::newput() to lock a record in groupboards.db file to ensure a unique numeric id used for the url. New group id is stored in db file in combination with groupname as a new key.
Index: loncom/interface/groupboards.pm
diff -u loncom/interface/groupboards.pm:1.7 loncom/interface/groupboards.pm:1.8
--- loncom/interface/groupboards.pm:1.7 Mon Jul 17 10:52:00 2006
+++ loncom/interface/groupboards.pm Thu Jul 20 11:51:10 2006
@@ -77,7 +77,7 @@
}
my %curr_groups = &Apache::longroup::coursegroups($cdom,$cnum,$group);
if (!defined($curr_groups{$group})) {
- $earlyout = &mt('Invalid [_1]',$gpterm);
+ $earlyout = &mt('Invalid group');
$r->print(&display_error($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$earlyout,$refarg));
return OK;
@@ -103,7 +103,7 @@
if (($can_create) || (&Apache::lonnet::allowed('mdg',$env{'request.course.id'}))) {
$r->print(&boards_header($cdom,$cnum,$group,$description,$gpterm,
$ucgpterm,$bodytitle,$refarg));
- my ($outcome,$newurl,$bbtitle) =
+ my ($outcome,$newurl,$bbtitle,$dellockoutcome) =
&create_board($cdom,$cnum,$group,$env{'form.newbul'});
if ($outcome eq 'ok') {
my ($furl,$ferr)= &Apache::lonuserstate::readmap($cdom.'/'.$cnum);
@@ -115,6 +115,9 @@
'<a href="/adm/groupboards?group='.$group.'&'.
$refarg.'">'.&mt('View all group discussion boards').
'</a></td></tr></table>');
+ if ($dellockoutcome ne 'ok') {
+ $r->print(&mt('There was a problem removing a lockfile for the group ([_1]). This may prevent creation of additional bulletin boards in this group. Please contact the system administrator for your LON-CAPA domain.'));
+ }
} else {
$r->print(&mt('There was a problem creating the new discussion board - [_1]','<span class="LC_error">'.$outcome.'</span>').'<br /><a href="/adm/groupboards?group='.$group.'">'.
&mt('Return to discussion boards').'</a>');
@@ -130,8 +133,7 @@
function makebulboard() {
var title=prompt('Discussion Board Title');
if (title) {
- this.document.forms.newbb.newbul.value=
- title+'=/adm/$cdom/$cnum/$now/bulletinboard';
+ this.document.forms.newbb.newbul.value=title;
this.document.forms.newbb.submit();
}
}
@@ -173,16 +175,59 @@
}
sub create_board {
- my ($cdom,$cnum,$group,$newboard) = @_;
- my ($bbtitle,$newurl)=split(/\=/,$newboard);
- my $outcome;
- my ($boardid) = ($newurl =~ m-/adm/\Q$cdom\E/\Q$cnum\E/(\d+)/bulletinboard-);
- if (!$boardid) {
- $outcome = ('error: the URL for new board was invalid');
- return ($outcome,$newurl,$bbtitle);
- }
+ my ($cdom,$cnum,$group,$bbtitle) = @_;
+ my ($outcome,$boardid,$newurl);
$bbtitle=&unescape($bbtitle);
+ # get lock on nohist_groupboards file
+ my $lockhash = {
+ $group."\0".'locked_boardids' => $env{'user.name'}.
+ ':'.$env{'user.domain'},
+ };
+ my $tries = 0;
+ my $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum);
+ my $dellockoutcome;
+ while (($gotlock ne 'ok') && $tries <3) {
+ $tries ++;
+ sleep 1;
+ $gotlock = &Apache::lonnet::newput('nohist_groupboards',$lockhash,$cdom,$cnum);
+ }
+ if ($gotlock eq 'ok') {
+ my %curr_boards = &Apache::lonnet::dump('nohist_groupboards',$cdom,$cnum,$group);
+ $boardid = time;
+ my $idtries = 0;
+ while(exists($curr_boards{$group."\0".$boardid}) && $idtries < 20) {
+ $boardid ++;
+ $idtries ++;
+ }
+ if (!exists($curr_boards{$group."\0".$boardid})) {
+ my %new_board = (
+ $group."\0".$boardid => $env{'user.name'}.':'.
+ $env{'user.domain'},
+ );
+ my $putresult = &Apache::lonnet::put('nohist_groupboards',\%new_board,
+ $cdom,$cnum);
+ if ($putresult ne 'ok') {
+ $outcome = 'error storing new board: '.$putresult;
+ } else {
+ $newurl = '/adm/'.$cdom.'/'.$cnum.'/'.$boardid.
+ '/bulletinboard';
+ }
+ } else {
+ $outcome = ('error: no unique ID for the new board available.');
+ }
+ # remove lock
+ my @del_lock = ($group."\0".'locked_boardids');
+ $dellockoutcome = &Apache::lonnet::del('nohist_groupboards',\@del_lock,$cdom,$cnum);
+ } else {
+ $outcome = "error: could not obtain lockfile\n";
+ $dellockoutcome = 'ok';
+ }
+ if (!$newurl) {
+ return ($outcome,$newurl,$bbtitle,$dellockoutcome);
+ }
$newurl=&unescape($newurl);
+ # need to check here if group_boards_$group.sequence is in the course
+ # if not - add it as an item in group_folder_$group.sequence
my $allbbsmap = &Apache::longroup::get_bbfolder_url($cdom,$cnum,$group);
if ($allbbsmap =~ m|^/uploaded|) {
my ($errtext,$fatal)=&Apache::lonratedt::mapread($allbbsmap);
@@ -208,7 +253,7 @@
$outcome = 'error: discussion boards folder absent, '.
'or in unexpected location - '.$allbbsmap."\n";
}
- return ($outcome,$newurl,$bbtitle);
+ return ($outcome,$newurl,$bbtitle,$dellockoutcome);
}
sub display_error {