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