--- trunk/lib/BackupPC/CGI/BurnMedia.pm 2005/08/20 17:19:48 53 +++ trunk/lib/BackupPC/CGI/BurnMedia.pm 2005/10/07 12:03:05 146 @@ -15,10 +15,10 @@ my $subtitle; my @files; - my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } ); + my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } ); BackupPC::CGI::Lib::NewRequest(); - $cont = Dumper(%In); +# $cont = Dumper(%In); if (!defined($In{submitBurner})) { $title = eval(q{ ${h1($Lang->{Burn_media})}}); $cont = Dumper(%In); @@ -30,65 +30,82 @@ EOF - $cont .= "Backups that have files not archived:
"; + $cont .= "Backups that have not been archived:
"; $cont .= BackupPC::SearchLib::displayBackupsGrid(); } else { - my $mediumName = "DVD"; + my @selected_backup_ids; - $title = eval(q{ ${h1($Lang->{Burn_media})}}); - $subtitle = eval(q{ ${h2($Lang->{Burn_media_assign})}}); - $cont = <prepare($sql); - $sth->execute(); - - my ($mediumNum) = $sth->fetchrow_array(); - $mediumNum ||= '0'; + my $total_size = 0; + + foreach my $key(keys(%In)) + { + if ($key =~ m/fcb([0-9]+)_([0-9]+)/gi) + { + my $hostID = $1; + my $backupnum = $2; + push(@selectedBackups, ($hostID, $backupnum)); + $total_size += BackupPC::SearchLib::getGzipSize($hostID, $backupnum); + } + } - $mediumName = "DVD".$mediumNum; - $sth = $dbh->prepare (q{ - INSERT INTO dvds (num, name) - VALUES - (?,?) + # create new archive + my $sth = $dbh->prepare(q{ + INSERT INTO archive ( + id, + dvd_nr, + note, + username, + date + ) VALUES ( + nextVal('archive_id_seq'), + nextVal('dvd_nr'), + ?, + ?, + NOW() + ) }); - $sth->execute($mediumNum, $mediumName); - - my $dvdid = $dbh->last_insert_id(undef,undef,'dvds',undef); - - my $updateSQL = q{ - UPDATE files - SET dvdid=? - WHERE files.shareID IN ( - SELECT ID FROM shares WHERE hostID=? - ) AND - files.backupNum=? - }; + # FIXME insert user here + $sth->execute($In{'note'}, 'dummy_user'); - my $update_sth = $dbh->prepare($updateSQL); - my $orQuery = ""; - - # then, assign dvdid to files - foreach my $key (keys(%In)) { - if ($key =~ /fcb/) { - my ($hID, $bNo) = split(/_/, $In{$key}); - $update_sth->execute($dvdid, $hID, $bNo); + if ($total_size > $Conf{MaxArchiveSize}) { + $cont .= eval( q{ ${h2(Error)}}); + $cont .= "Selected backups exceed max archive size."; + } else { + + + foreach my $backup_id (@selected_backup_ids) { + + # link backups with archive + my $sth = $dbh->prepare(q{ + INSERT INTO archive_backup ( + archive_id, backup_id, status + ) VALUES ( + (SELECT last_value FROM archive_id_seq), ?, ? + ) + }); + + $sth->execute($backup_id, 'ok'); + + $dbh->commit(); + + $cont .= qq{ + Archived following backups: + } . join(",", @selected_backup_ids) . qq{ +
with following message: +
+ } . $In{'note'} . qq{ +
+ }; } + $dbh->commit(); } - $cont .= "Backups assigned to media ".$mediumName; } - + Header($Lang->{Burn_media}, "", 1, "", $cont); + Trailer(); $dbh->disconnect(); }