/[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 148 by iklaric, Fri Oct 7 12:06:35 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                            if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
44          $title                                  my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
45          $subtitle                                  push @selected_backup_ids, $backup_id;
46                                    $total_size += BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
47  EOF                          }
48                                }
                 # insert DVD first,  
                 my $sql = q{ SELECT MAX(num)+1 AS maxNum FROM dvds; };  
   
                 my $sth = $dbh->prepare($sql);  
                 $sth->execute();  
   
                 my ($mediumNum) = $sth->fetchrow_array();  
                 $mediumNum ||= '0';  
   
                 $mediumName = "DVD".$mediumNum;  
                 $sth = $dbh->prepare (q{  
                                 INSERT INTO dvds (num, name)  
                                 VALUES  
                                 (?,?)                                    
                 });  
49    
                 $sth->execute($mediumNum, $mediumName);  
50    
51                  my $dvdid = $dbh->last_insert_id(undef,undef,'dvds',undef);                          if ($total_size > $Conf{MaxArchiveSize}) {
52                                        $cont .= eval( q{ ${h2(Error)}});
53                  my $updateSQL = q{                          $cont .= "Selected backups exceed max archive size.";
54                          UPDATE files                  } else {
55                          SET dvdid=?  
56                          WHERE files.shareID IN (                          # create new archive
57                                  SELECT ID FROM shares WHERE hostID=?                          my $sth = $dbh->prepare(q{
58                          ) AND                                                          INSERT INTO archive (
59                                  files.backupNum=?                                                                  id,
60                  };                                                                  dvd_nr,
61                                                                    note,
62                  my $update_sth = $dbh->prepare($updateSQL);                                                                  username,
63                  my $orQuery = "";                                                                  date
64                                                                        ) VALUES (
65                  # then, assign dvdid to files                                                                  nextVal('archive_id_seq'),
66                  foreach my $key (keys(%In)) {                                                                  nextVal('dvd_nr'),
67                          if ($key =~ /fcb/) {                                                                                      ?,
68                                  my ($hID, $bNo) = split(/_/, $In{$key});                                                                  ?,
69                                  $update_sth->execute($dvdid, $hID, $bNo);                                                                  NOW()
70                                                            )
71                                                    });
72    
73                            # FIXME insert user here
74                            $sth->execute($In{'note'}, 'dummy_user');
75    
76                            foreach my $backup_id (@selected_backup_ids) {
77    
78                                    # link backups with archive
79                                    my $sth = $dbh->prepare(q{
80                                            INSERT INTO archive_backup (
81                                                    archive_id, backup_id, status
82                                            ) VALUES (
83                                                    (SELECT last_value FROM archive_id_seq), ?, ?
84                                            )
85                                    });
86    
87                                    $sth->execute($backup_id, 'ok');
88    
89                                    $dbh->commit();
90    
91                                    $cont .= qq{
92                                            Archived following backups:
93                                    } . join(",", @selected_backup_ids) . qq{
94                                            <br/>with following message:
95                                            <div style="border: 1px solid #e0e0e0">
96                                    } . $In{'note'} . qq{
97                                            </div>
98                                    };
99                          }                          }
100                            $dbh->commit();
101                  }                  }
                 $cont .= "Backups assigned to media ".$mediumName;  
102          }          }
103          
104          Header($Lang->{Burn_media}, "", 1, "", $cont);          Header($Lang->{Burn_media}, "", 1, "", $cont);
105    
106          Trailer();          Trailer();
107          $dbh->disconnect();          $dbh->disconnect();
108  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26