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