Annotation of wpscripts/ztransfer/fetch.pm, Revision 1.6
1.1 yason 1: #!/usr/bin/perl
1.6 ! yason 2: # $Id: fetch.pm,v 1.5 2011/07/22 07:43:56 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.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.4 yason 42: $dbpaths[$i] = '/mnt/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: #
1.6 ! yason 49: # increment $i ONLY if local file exists, otherwise replace element in next iteration
! 50: $i++;
! 51: # if localfile does not exists, write result of next iteration on its place
1.1 yason 52: }
53: else
54: {
55: next;
56: }
57: }
58:
59: # strip last row in arrays by decrementing $i counter
60: # SHOULD BE FIXED!
61: $i--;
62: $#dbids = $i;
63: $#dbpaths = $i;
64:
65: # reformat listing using file_priority database field
66: for($i = 0;$i < scalar(@dbids); $i++)
67: {
68: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 0);
69: }
70: for($i = 0;$i < scalar(@dbids); $i++)
71: {
72: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 1);
73: }
74: for($i = 0;$i < scalar(@dbids); $i++)
75: {
76: stack_push($dbids[$i], $dbpaths[$i]) if($dbpri[$i] == 2);
77: }
78: @dbids = @stack_ids;
79: @dbpaths = @stack_paths;
80:
81: # make current files list via log::filelist()
82: log::filelist(\@dbpaths);
83:
84: # we return the list of references to @dbids and @dbpaths
85: return( (\@dbids, \@dbpaths) );
86: }
87:
88:
89: sub probas_list()
90: {
91: my @dbids;
92: my @dbpaths;
93: my $i = 0;
94:
95: $sth = $db::dbh->prepare($QUERY_P);
96: $sth->execute( );
97: while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
98: {
1.5 yason 99: $dbpaths[$i] = substr($dbpaths[$i], 13);
1.1 yason 100: $dbpaths[$i] =~ tr/\\/\//;
1.5 yason 101: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
1.1 yason 102: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
103: $i++;
104: }
105:
106: $i--;
107: $#dbids = $i;
108: $#dbpaths = $i;
109:
110: log::filelist(\@dbpaths);
111:
112:
113: return( (\@dbids, \@dbpaths) );
114: }
1.6 ! yason 115:
! 116: sub tt_list()
! 117: {
! 118: my @dbids;
! 119: my @dbpaths;
! 120: my $i = 0;
! 121:
! 122: $sth = $db::dbh->prepare($QUERY_T);
! 123: $sth->execute( );
! 124: while(($dbids[$i], $dbpaths[$i]) = $sth->fetchrow_array( ) )
! 125: {
! 126: $dbpaths[$i] = substr($dbpaths[$i], 13);
! 127: $dbpaths[$i] =~ tr/\\/\//;
! 128: $dbpaths[$i] = '/mnt/maket/' . $dbpaths[$i];
! 129: $dbpaths[$i] = substr($dbpaths[$i], 0, ( index($dbpaths[$i], ' ', 0) ) );
! 130: $i++;
! 131: }
! 132:
! 133: $i--;
! 134: $#dbids = $i;
! 135: $#dbpaths = $i;
! 136:
! 137: log::filelist(\@dbpaths);
! 138:
! 139:
! 140: return( (\@dbids, \@dbpaths) );
! 141: }
! 142:
1.1 yason 143:
144:
145: return(1);
CVSweb