/[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 145 by dpavlin, Fri Oct 7 11:15:28 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 += 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';  
49    
50                  $mediumName = "DVD".$mediumNum;                  # create new archive
51                  $sth = $dbh->prepare (q{                  my $sth = $dbh->prepare(q{
52                                  INSERT INTO dvds (num, name)                                  INSERT INTO archive (
53                                  VALUES                                          id,
54                                  (?,?)                                                                            dvd_nr,
55                                            note,
56                                            username,
57                                            date
58                                    ) VALUES (
59                                            nextVal('archive_id_seq'),
60                                            nextVal('dvd_nr'),
61                                            ?,
62                                            ?,
63                                            NOW()
64                                    )
65                  });                  });
66    
67                  $sth->execute($mediumNum, $mediumName);                  # FIXME insert user here
68                    $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=?  
                 };  
69    
70                  my $update_sth = $dbh->prepare($updateSQL);                  if ($total_size > $Conf{MaxArchiveSize}) {
71                  my $orQuery = "";                          $cont .= eval( q{ ${h2(Error)}});
72                                        $cont .= "Selected backups exceed max archive size.";
73                  # then, assign dvdid to files                  } else {
74                  foreach my $key (keys(%In)) {  
75                          if ($key =~ /fcb/) {                                              foreach my $backup_id (@selected_backup_ids) {
76                                  my ($hID, $bNo) = split(/_/, $In{$key});  
77                                  $update_sth->execute($dvdid, $hID, $bNo);                                  # link backups with archive
78                                    my $sth = $dbh->prepare(q{
79                                            INSERT INTO archive_backup (
80                                                    archive_id, backup_id, status
81                                            ) VALUES (
82                                                    (SELECT last_value FROM archive_id_seq), ?, ?
83                                            )
84                                    });
85    
86                                    $sth->execute($backup_id, 'ok');
87    
88                                    $dbh->commit();
89    
90                                    $cont .= qq{
91                                            Archived following backups:
92                                    } . join(",", @selected_backup_ids) . qq{
93                                            <br/>with following message:
94                                            <div style="border: 1px solid #e0e0e0">
95                                    } . $In{'note'} . qq{
96                                            </div>
97                                    };
98                          }                          }
99                  }                  }
                 $cont .= "Backups assigned to media ".$mediumName;  
100          }          }
101          
102          Header($Lang->{Burn_media}, "", 1, "", $cont);          Header($Lang->{Burn_media}, "", 1, "", $cont);
103    
104          Trailer();          Trailer();
105          $dbh->disconnect();          $dbh->disconnect();
106  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26