Annotation of wpscripts/ztransfer/fetch.pm, Revision 1.7
1.1 yason 1: #!/usr/bin/perl
1.7 ! yason 2: # $Id: fetch.pm,v 1.6 2011/08/30 08:30:41 yason Exp $
1.1 yason 3: package fetch;
4: use db;
5: use log; # bad! only for log::filelist()
6: use warnings;
7: my $QUERY_Z = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=0";
1.2 yason 8: my $QUERY_P = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=1";
1.6 yason 9: my $QUERY_T = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=2";
1.7 ! yason 10: my $QUERY_J = "SELECT ID,Path,file_priority FROM upload_files WHERE Status=0 AND type_file=3";
1.1 yason 11:
12: my $sth;
13:
14: my @stack_ids; # stack for ID's
15: my @stack_paths;# stack for Path's
16: my $tos = 0; # top of stack
17:
18:
19: sub stack_push($$)
20: {
21: $stack_ids[$tos] = shift;
22: $stack_paths[$tos] = shift;
23: $tos++;
24: }
25:
26:
27: sub zayavki_list()
28: {
29: my @dbids;
30: my @dbpaths;
31: my @dbpri;
32: my $i = 0;
33:
34: $sth = $db::dbh->prepare($QUERY_Z);
35: $sth->execute( );
36: while( ($dbids[$i], $dbpaths[$i], $dbpri[$i]) = $sth->fetchrow_array( ) )
37: {
38: if($dbids[$i]) # element exists (THIS CODE SHOULD BE FIXED)
39: {
40: #convert samba-paths to local unix paths
1.2 yason 41: $dbpaths[$i] = substr($dbpaths[$i], 13); # remove \\fileserver\
1.1 yason 42: $dbpaths[$i] =~ tr/\\/\//; # convert each \ to /
1.4 yason 43: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
1.1 yason 44: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
45: #
46: # We must not save non-existent local file in array!
47: # Returning of array with bad element is deprecated,
48: # So this code too weak to work correctly.
49: #
1.6 yason 50: # increment $i ONLY if local file exists, otherwise replace element in next iteration
51: $i++;
52: # if localfile does not exists, write result of next iteration on its place
1.1 yason 53: }
54: else
55: {
56: next;
57: }
58: }
59:
60: # strip last row in arrays by decrementing $i counter
61: # SHOULD BE FIXED!
62: $i--;
63: $#dbids = $i;
64: $#dbpaths = $i;
65:
66: # reformat listing using file_priority database field
67: for($i = 0;$i < scalar(@dbids); $i++)
68: {
69: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0);
70: }
71: for($i = 0;$i < scalar(@dbids); $i++)
72: {
73: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1);
74: }
75: for($i = 0;$i < scalar(@dbids); $i++)
76: {
77: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2);
78: }
79: @dbids = @stack_ids;
80: @dbpaths = @stack_paths;
81:
82: # make current files list via log::filelist()
83: log::filelist(\@dbpaths);
84:
85: # we return the list of references to @dbids and @dbpaths
86: return( (\@dbids, \@dbpaths) );
87: }
88:
89:
90: sub probas_list()
91: {
92: my @dbids;
93: my @dbpaths;
94: my $i = 0;
95:
96: $sth = $db::dbh->prepare($QUERY_P);
97: $sth->execute( );
98: while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
99: {
1.5 yason 100: $dbpaths[$i] = substr($dbpaths[$i], 13);
1.1 yason 101: $dbpaths[$i] =~ tr/\\/\//;
1.5 yason 102: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
1.1 yason 103: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
104: $i++;
105: }
106:
107: $i--;
108: $#dbids = $i;
109: $#dbpaths = $i;
110:
111: log::filelist(\@dbpaths);
112:
113:
114: return( (\@dbids, \@dbpaths) );
115: }
1.6 yason 116:
117: sub tt_list()
118: {
119: my @dbids;
120: my @dbpaths;
121: my $i = 0;
122:
123: $sth = $db::dbh->prepare($QUERY_T);
124: $sth->execute( );
125: while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
126: {
127: $dbpaths[$i] = substr($dbpaths[$i], 13);
128: $dbpaths[$i] =~ tr/\\/\//;
129: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
130: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
131: $i++;
132: }
133:
134: $i--;
135: $#dbids = $i;
136: $#dbpaths = $i;
137:
138: log::filelist(\@dbpaths);
139:
140:
141: return( (\@dbids, \@dbpaths) );
142: }
143:
1.7 ! yason 144: sub jpeg_list()
! 145: {
! 146: my @dbids;
! 147: my @dbpaths;
! 148: my $i = 0;
1.1 yason 149:
1.7 ! yason 150: $sth = $db::dbh->prepare($QUERY_J);
! 151: $sth->execute( );
! 152: while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
! 153: {
! 154: $dbpaths[$i] = substr($dbpaths[$i], 13);
! 155: $dbpaths[$i] =~ tr/\\/\//;
! 156: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
! 157: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
! 158: $i++;
! 159: }
! 160:
! 161: $i--;
! 162: $#dbids = $i;
! 163: $#dbpaths = $i;
! 164:
! 165: log::filelist(\@dbpaths);
! 166:
! 167:
! 168: return( (\@dbids, \@dbpaths) );
! 169: }
1.1 yason 170:
171: return(1);
CVSweb