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();
}