/[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 197 by dpavlin, Thu Oct 13 18:33:00 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})}});                  my $selected = 0;
                 $cont = <<EOF;  
   
         $title  
         $subtitle  
42    
43  EOF                  foreach my $key(keys(%In)) {
44                                        if ($key =~ m/^fcb([0-9]+)_([0-9]+)_([0-9]+)$/gi) {
45                  # insert DVD first,                                  my ($host_id, $backup_num, $backup_id) = ($1,$2,$3);
46                  my $sql = q{ SELECT MAX(num)+1 AS maxNum FROM dvds; };                                  push @selected_backup_ids, $backup_id;
47                                    $total_size += BackupPC::SearchLib::getGzipSize($host_id, $backup_num);
48                                    $selected++;
49                            }
50                    }
51    
52                  my $sth = $dbh->prepare($sql);                  my $total_kb = int($total_size / 1024);
                 $sth->execute();  
53    
54                  my ($mediumNum) = $sth->fetchrow_array();                  # and now a little magic to check multi-volume increments
55                  $mediumNum ||= '0';                  my $parts = 1;
56                    if ($#selected_backup_ids == 0) {
57                            ($parts) = $dbh->selectrow_array("select parts from backups where id = ?", undef, $selected_backup_ids[0]);
58                    }
59    
60                  $mediumName = "DVD".$mediumNum;                  if ($total_kb > ($Conf{MaxArchiveSize} * $parts)) {
61                  $sth = $dbh->prepare (q{                          $cont .= eval( q{ ${h2(Error)}});
62                                  INSERT INTO dvds (num, name)                          $cont .= "Selected backups size $total_kb Kb exceed max archive size $Conf{MaxArchiveSize} Kb.";
63                                  VALUES                  } elsif ($total_size == 0) {
64                                  (?,?)                                                            $cont .= eval( q{ ${h2(Error)}});
65                  });                          $cont .= "No backups selected.";
66                    } else {
67    
68                            # create new archive
69                            my $sth = $dbh->prepare(q{
70                                                            INSERT INTO archive (
71                                                                    id,
72                                                                    dvd_nr,
73                                                                    note,
74                                                                    username,
75                                                                    date,
76                                                                    total_size
77                                                            ) VALUES (
78                                                                    nextVal('archive_id_seq'),
79                                                                    nextVal('dvd_nr'),
80                                                                    ?,
81                                                                    ?,
82                                                                    NOW(),
83                                                                    ?
84                                                            )
85                                                    });
86    
87                            $sth->execute($In{'note'}, $User, $total_size);
88    
89                            foreach my $backup_id (@selected_backup_ids) {
90    
91                                    # link backups with archive
92                                    my $sth = $dbh->prepare(q{
93                                            INSERT INTO archive_backup (
94                                                    archive_id, backup_id
95                                            ) VALUES (
96                                                    (SELECT last_value FROM archive_id_seq), ?
97                                            )
98                                    });
99    
100                  $sth->execute($mediumNum, $mediumName);                                  $sth->execute($backup_id);
101    
102                  my $dvdid = $dbh->last_insert_id(undef,undef,'dvds',undef);                                          $dbh->commit();
               
                 my $updateSQL = q{  
                         UPDATE files  
                         SET dvdid=?  
                         WHERE files.shareID IN (  
                                 SELECT ID FROM shares WHERE hostID=?  
                         ) AND  
                                 files.backupNum=?  
                 };  
103    
                 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);  
104                          }                          }
105    
106                            my ($dvd_nr) = $dbh->selectrow_array(qq{
107                                    select last_value from dvd_nr
108                            });
109    
110                            $dvd_nr ||= 'error';
111    
112                            $dbh->commit();
113    
114                            $cont .= q{
115                                    Archived following backups:
116                            } . join(", ", @selected_backup_ids) . q{
117                                    <br/>with total size of
118                            <b>} . sprintf("%1.2f Mb", $total_size / 1024 / 1024) . q{</b>
119                                    to media <b>} . $dvd_nr . q{</b>
120                                    with following message:
121                                    <div style="background-color: #e0e0e0; display: inline; padding: 2px;">
122                            } . $In{'note'} . q{
123                                    </div>
124                            };
125                  }                  }
                 $cont .= "Backups assigned to media ".$mediumName;  
126          }          }
127          
128          Header($Lang->{Burn_media}, "", 1, "", $cont);          Header($Lang->{Burn_media}, "", 1, "", $cont);
129    
130          Trailer();          Trailer();
131          $dbh->disconnect();          $dbh->disconnect();
132  }  }

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

  ViewVC Help
Powered by ViewVC 1.1.26