dbXapp 2.0
RAD, CMS, Module und Runtime-IDE fuer dbXapp
Loading...
Searching...
No Matches
dbxFileWalker.class.php
Go to the documentation of this file.
1<?php
2
3
4
5
6class dbxFileWalker extends dbxObj {
7
8
9
10 public function clear() {
11 $section=$this->_section;
12 //dbx_debug("#filewalker clear Section=($section)");
13 $count=$this->get_property('count',-1);
14 if ($section) {
15 $this->del_property('*');
16 } else {
17 $this->_properties=array();
18 }
19 $this->set_property('count',$count);
20 }
21
22
23public function init($section) {
24 $this->_section=$section;
25 $status=$this->get_property('status','init');
26 //dbx_debug("#filewalker init status=($status) Section=($section)") ;
27
28
29
30 if ($status=='init') {
31 $this->clear();
32 $this->set_property('status','init');
33 $this->set_property('done',0);
34 $this->set_property('percent',0);
35 $this->set_property('errors',0);
36 $this->set_property('count',0);
37
38 }
39 //dbx_debug("######init=($status) process=($process)");
40 return $status;
41}
42
43
44 public function delete() {
45 $ok=0;
46
47 $file = $this->get_property('file','');
48 $path = $this->get_property('path' ,'');
49 $path = dbx_os_path_file($path);
50 $path_file=$path.$file;
51 if (file_exists($path_file)) {
52 $ok=unlink($path_file);
53 }
54
55 return $ok;
56 }
57
58
59
60 public function archiv() {
61 $ok=0;
62
63 $file =$this->get_property('file','');
64 $path =$this->get_property('path' ,'');
65 $archiv=$this->get_property('archiv','');
66 $date =$this->get_property('date' ,0);
67
68 $path_file=$path.$file;
69 if (!$file) return 0;
70
71 //dbx_debug("#A-ARCHIV dir =($archiv) Path=($path) File=($file)");
72
73 if ($archiv) {
74 if (!is_dir($archiv)) return 'error'; // error wrong archiv dir
75
76 if ($date) {
77 $date_dir=date("Y-m-d").'/';
78 $archiv.=$date_dir;
79 if (!is_dir($archiv)) {
80 if (!mkdir($archiv, 0777, true)) {
81 return 0 ; // error wrong archiv.date dir
82 }
83 }
84 }
85
86 //dbx_debug("#B-ARCHIV dir =($archiv) ");
87
88
90 $newname=dbx_os_path_file($archiv.$file);
91 if (file_exists($oldname)) {
92 $ok= rename($oldname, $newname);
93 }
94
95 // dbx_debug("#ARCHIV ($oldname) -> ($newname) ok=($ok)");
96
97
98 }
99 return $ok;
100 }
101
102 public function create_que() {
103
104 $path=$this->get_property('path');
105 $ext =$this->get_property('ext');
106 $len =strlen($ext);
107
108 $path=dbx_os_path_file($path);
109 //dbx_debug("#filewalker create_que=($path) Ext=($ext) Len=($len)");
110
111
112 if (!is_dir($path)) {
113 $this->set_property('status','end');
114 return 0;
115 }
116
117 $files=$this->get_property('files',0);
118 if (!$files) {
119 $files=array();
120 $all_files=scandir($path);
121 foreach ($all_files as $file) {
122 $fext=substr($file, ($len * -1));
123 if ($ext === $fext) {
124 $file_path=$path.$file;
125 if (is_file($file_path)) $files[]=$file;
126 }
127 }
128 $this->set_property('files',$files);
129 //dbx_debug ("#filewalker create_que files=",$files);
130 }
131 $files=$this->get_property('files',0);
132 if (is_array($files)) {
133 $count=count($files);
134 } else {
135 $count=0;
136 }
137
138 //dbx_debug ("#filewalker create_que count=($count)");
139
140 if ( $count) $this->set_property('status','run');
141 if (!$count) $this->set_property('status','end');
142 $this->set_property('count',$count);
143 $this->set_property('pos',0);
144
145 return $count;
146 }
147
148
149 public function filewalker() {
150
151 $count=0; $percent=0; $file=''; $files=array();
152 $info='import';
153
154 $status =$this->get_property('status','init');
155 $count =$this->get_property('count',0);
156 $pos =$this->get_property('pos' ,0);
157 $percent=$this->get_property('percent',0);
158
159 //dbx_debug("STATUS-A=($status)");
160 if ($status=='run' && $pos > $count) $status='end';
161 if ($status=='end') $status='init';
162 if ($status=='init') {
163 $this->clear();
164 $this->set_property('status','init');
165 $this->set_property('pos',0);
166
167 //dbx_debug ("### Walker run Status=(init) ($status) count=($count) Pos=($pos) Percent=($percent)");
168
169 return 'init';
170 }
171
172
173 $path =$this->get_property('path');
174 $files =$this->get_property('files');
175 $count =$this->get_property('count' ,0);
176 $pos =$this->get_property('pos' ,0);
177 $percent=$this->get_property('percent',0);
178 $path =dbx_os_path_file($path);
179
180 if (!$count || $pos > $count) $status='end';
181
182
183
184 if ($status=='run') {
185 if ($pos >= $count ) {
186 $this->set_property('status','end');
187 return 'end';
188 }
189 }
190
191 //dbx_debug ("### Walker run Status=($status) count=($count) Pos=($pos) Percent=($percent)");
192
193 if ($status=='run' && is_Array($files)) {
194 if ($pos <= $count) {
195 if (isset($files[$pos])) {
196 $pos = ($pos + 1);
197 $file = $files[$pos-1];
198 $percent =(round($pos / $count,2)*100);
199 $this->set_property('file',$file);
200 $this->set_property('path_file',$path.$file);
201 $this->set_property('percent',$percent);
202 $this->set_property('status','run');
203 $this->set_property('pos',$pos);
204
205 } // isset
206 } // pos <= count
207 } // is_array
208
209 $this->set_property('status',$status);
210 //if ($status=='end') $this->clear();
211 return $status;
212 } // filewalker
213 // - - - - - - - - - -
214
215
216
217 public function run() {
218 $status=$this->filewalker();
219 return $status;
220 }
221}
222
Gemeinsame Basisklasse fuer dbXapp-System-, Modul- und Include-Objekte.
Definition dbxKernel.php:63
get_property($name, $default='', $section='', $modul='modul')
Liest eine Objekt- oder Session-Property.
set_property($name, $value, $section='', $modul='modul')
Speichert eine Objekt- oder Session-Property.
Public $_section
Definition dbxKernel.php:66
del_property($name, $section='', $modul='modul')
Loescht eine Objekt- oder Session-Property.
dbx_os_path_file($path_file)
Definition index.php:164
$path_file
Definition index.php:270