/[BackupPC]/trunk/lib/BackupPC/CGI/BurnMedia.pm
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Diff of /trunk/lib/BackupPC/CGI/BurnMedia.pm

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 53 by dpavlin, Sat Aug 20 17:19:48 2005 UTC revision 146 by iklaric, Fri Oct 7 12:03:05 2005 UTC
# Line 15  sub action() { Line 15  sub action() {
15          my $subtitle;          my $subtitle;
16          my @files;          my @files;
17    
18          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 1 } );          my $dbh = DBI->connect($dsn, $db_user, "", { RaiseError => 1, AutoCommit => 0 } );
19    
20          BackupPC::CGI::Lib::NewRequest();          BackupPC::CGI::Lib::NewRequest();
21          $cont = Dumper(%In);  #       $cont = Dumper(%In);
22          if (!defined($In{submitBurner})) {          if (!defined($In{submitBurner})) {
23                  $title = eval(q{ ${h1($Lang->{Burn_media})}});                  $title = eval(q{ ${h1($Lang->{Burn_media})}});
24                  $cont = Dumper(%In);                  $cont = Dumper(%In);
# Line 30  sub action() { Line 30  sub action() {
30                    
31  EOF  EOF
32                                
33                  $cont .= "Backups that have files not archived:<br>";                  $cont .= "Backups that have not been archived:<br>";
34                  $cont .= BackupPC::SearchLib::displayBackupsGrid();                  $cont .= BackupPC::SearchLib::displayBackupsGrid();
35                            
36          } else {          } else {
37    
38                  my $mediumName = "DVD";                  my @selected_backup_ids;
39    
40                  $title = eval(q{ ${h1($Lang->{Burn_media})}});                  my $total_size = 0;
41                  $subtitle = eval(q{ ${h2($Lang->{Burn_media_assign})}});                  
42                  $cont = <<EOF;                  foreach my $key(keys(%In))
43                    {
44          $title                          if ($key =~ m/fcb([0-9]+)_([0-9]+)/gi)
45          $subtitle                          {
46                                    my $hostID = $1;
47  EOF                                  my $backupnum = $2;
48                                                push(@selectedBackups, ($hostID, $backupnum));
49                  # insert DVD first,                                  $total_size += BackupPC::SearchLib::getGzipSize($hostID, $backupnum);
50                  my $sql = q{ SELECT MAX(num)+1 AS maxNum FROM dvds; };                          }
51                    }
                 my $sth = $dbh->prepare($sql);  
                 $sth->execute();  
   
                 my ($mediumNum) = $sth->fetchrow_array();  
                 $mediumNum ||= '0';  
52    
53                  $mediumName = "DVD".$mediumNum;                  # create new archive
54                  $sth = $dbh->prepare (q{                  my $sth = $dbh->prepare(q{
55                                  INSERT INTO dvds (num, name)                                  INSERT INTO archive (
56                                  VALUES                                          id,
57                                  (?,?)                                                                            dvd_nr,
58                                            note,
59                                            username,
60                                            date
61                                    ) VALUES (
62                                            nextVal('archive_id_seq'),
63                                            nextVal('dvd_nr'),
64                                            ?,
65                                            ?,
66                                            NOW()
67                                    )
68                  });                  });
69    
70                  $sth->execute($mediumNum, $mediumName);                  # FIXME insert user here
71                    $sth->execute($In{'note'}, 'dummy_user');
                 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=?  
                 };  
72    
73                  my $update_sth = $dbh->prepare($updateSQL);                  if ($total_size > $Conf{MaxArchiveSize}) {
74                  my $orQuery = "";                          $cont .= eval( q{ ${h2(Error)}});
75                                        $cont .= "Selected backups exceed max archive size.";
76                  # then, assign dvdid to files                  } else {
77                  foreach my $key (keys(%In)) {  
78                          if ($key =~ /fcb/) {                      
79                                  my ($hID, $bNo) = split(/_/, $In{$key});                          foreach my $backup_id (@selected_backup_ids) {
80                                  $update_sth->execute($dvdid, $hID, $bNo);  
81                                    # link backups with archive
82                                    my $sth = $dbh->prepare(q{
83                                            INSERT INTO archive_backup (
84                                                    archive_id, backup_id, status
85                                            ) VALUES (
86                                                    (SELECT last_value FROM archive_id_seq), ?, ?
87                                            )
88                                    });
89    
90                                    $sth->execute($backup_id, 'ok');
91    
92                                    $dbh->commit();
93    
94                                    $cont .= qq{
95                                            Archived following backups:
96                                    } . join(",", @selected_backup_ids) . qq{
97                                            <br/>with following message:
98                                            <div style="border: 1px solid #e0e0e0">
99                                    } . $In{'note'} . qq{
100                                            </div>
101                                    };
102                          }                          }
103                            $dbh->commit();
104                  }                  }
                 $cont .= "Backups assigned to media ".$mediumName;  
105          }          }
106          
107          Header($Lang->{Burn_media}, "", 1, "", $cont);          Header($Lang->{Burn_media}, "", 1, "", $cont);
108    
109          Trailer();          Trailer();
110          $dbh->disconnect();          $dbh->disconnect();
111  }  }

Legend:
Removed from v.53  
changed lines
  Added in v.146

  ViewVC Help
Powered by ViewVC 1.1.26