@@ -501,7 +501,7 @@ |
||
501 | 501 | */ |
502 | 502 | public static function list_backups($backup_dir=''):array { |
503 | 503 | $result = array( |
504 | - 'result' => 'Success' |
|
504 | + 'result' => 'Success' |
|
505 | 505 | ); |
506 | 506 | |
507 | 507 | $result['data'] = []; |
@@ -22,31 +22,31 @@ discard block |
||
22 | 22 | private $config_file; |
23 | 23 | private $options; |
24 | 24 | private $options_recover_file; |
25 | - private $progress=0; |
|
26 | - private $type='img'; // img | zip |
|
25 | + private $progress = 0; |
|
26 | + private $type = 'img'; // img | zip |
|
27 | 27 | |
28 | - public function __construct($id, $options=null){ |
|
28 | + public function __construct($id, $options = null) { |
|
29 | 29 | $this->dirs = PBX::get_asterisk_dirs(); |
30 | 30 | $this->dirs_mem = PBX::get_asterisk_dirs_mem(); |
31 | 31 | // Проверим особенность бекапа на сетевой диск. |
32 | 32 | Util::mwexec("du /storage/*/{$id}/flist.txt -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
33 | - if(($out[0] ?? false) && file_exists($out[0])){ |
|
33 | + if (($out[0] ?? false) && file_exists($out[0])) { |
|
34 | 34 | $this->dirs['backup'] = dirname($out[0], 2); |
35 | - }elseif (is_array($options) && isset($options['backup'])){ |
|
35 | + }elseif (is_array($options) && isset($options['backup'])) { |
|
36 | 36 | // Переопределяем каталог с бекапом. |
37 | 37 | $this->dirs['backup'] = $options['backup']; |
38 | 38 | } |
39 | - $this->id = $id; |
|
40 | - $b_dir="{$this->dirs['backup']}/{$this->id}"; |
|
39 | + $this->id = $id; |
|
40 | + $b_dir = "{$this->dirs['backup']}/{$this->id}"; |
|
41 | 41 | |
42 | - if(!is_dir($b_dir) && mkdir($b_dir, 0755, true) && !is_dir($b_dir)){ |
|
42 | + if (!is_dir($b_dir) && mkdir($b_dir, 0755, true) && !is_dir($b_dir)) { |
|
43 | 43 | Util::sys_log_msg('Backup', 'Can not create dir '.$b_dir); |
44 | 44 | } |
45 | 45 | |
46 | - if(isset($options['type'])){ |
|
46 | + if (isset($options['type'])) { |
|
47 | 47 | $this->type = $options['type']; |
48 | 48 | } |
49 | - if(file_exists("{$this->dirs['backup']}/{$this->id}/resultfile.zip")){ |
|
49 | + if (file_exists("{$this->dirs['backup']}/{$this->id}/resultfile.zip")) { |
|
50 | 50 | $this->type = 'zip'; |
51 | 51 | } |
52 | 52 | |
@@ -55,16 +55,16 @@ discard block |
||
55 | 55 | $this->result_dir = "{$this->dirs['backup']}/{$this->id}/mnt_point"; |
56 | 56 | $this->progress_file = "{$this->dirs['backup']}/{$this->id}/progress.txt"; |
57 | 57 | $this->config_file = "{$this->dirs['backup']}/{$this->id}/config.json"; |
58 | - $this->options_recover_file= "{$this->dirs['backup']}/{$this->id}/options_recover.json"; |
|
58 | + $this->options_recover_file = "{$this->dirs['backup']}/{$this->id}/options_recover.json"; |
|
59 | 59 | $this->progress_file_recover = "{$this->dirs['backup']}/{$this->id}/progress_recover.txt"; |
60 | 60 | |
61 | - if((!is_array($options) || $options === null) && file_exists($this->config_file)){ |
|
61 | + if ((!is_array($options) || $options === null) && file_exists($this->config_file)) { |
|
62 | 62 | $this->options = json_decode(file_get_contents($this->config_file), true); |
63 | - }else{ |
|
63 | + } else { |
|
64 | 64 | $this->options = $options; |
65 | 65 | } |
66 | 66 | |
67 | - if(!is_array($this->options) || $this->options === null){ |
|
67 | + if (!is_array($this->options) || $this->options === null) { |
|
68 | 68 | $this->options = [ |
69 | 69 | 'backup-config' => '1', |
70 | 70 | 'backup-records' => '1', |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'backup-sound-files'=> '1' |
73 | 73 | ]; |
74 | 74 | } |
75 | - if(!file_exists($this->config_file) && FALSE === @file_put_contents($this->config_file, json_encode($this->options), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)){ |
|
75 | + if (!file_exists($this->config_file) && FALSE === @file_put_contents($this->config_file, json_encode($this->options), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)) { |
|
76 | 76 | Util::sys_log_msg('Backup', 'Failed create file '.$this->config_file); |
77 | 77 | } |
78 | 78 | } |
@@ -83,42 +83,42 @@ discard block |
||
83 | 83 | private function create_file_list():bool { |
84 | 84 | global $g; |
85 | 85 | |
86 | - try{ |
|
86 | + try { |
|
87 | 87 | $result = @file_put_contents($this->file_list, ''); |
88 | - }catch (Exception $e){ |
|
88 | + } catch (Exception $e) { |
|
89 | 89 | Util::sys_log_msg('Backup', $e->getMessage()); |
90 | 90 | $result = false; |
91 | 91 | } |
92 | - if($result === false || !file_exists($this->file_list)){ |
|
92 | + if ($result === false || !file_exists($this->file_list)) { |
|
93 | 93 | Util::sys_log_msg('Backup', 'Failed to create file '.$this->file_list); |
94 | 94 | return $result; |
95 | 95 | } |
96 | 96 | |
97 | 97 | $flist = ''; |
98 | - if(($this->options['backup-config']??'') === '1'){ |
|
98 | + if (($this->options['backup-config'] ?? '') === '1') { |
|
99 | 99 | file_put_contents($this->file_list, 'backup-config:'.$g['pt1c_db_path']."\n", FILE_APPEND); |
100 | 100 | Util::mwexec("find {$this->dirs['custom_modules']}", $out); |
101 | - foreach ($out as $filename){ |
|
102 | - $flist.= 'backup-config:'.$filename."\n"; |
|
101 | + foreach ($out as $filename) { |
|
102 | + $flist .= 'backup-config:'.$filename."\n"; |
|
103 | 103 | } |
104 | 104 | } |
105 | - if(($this->options['backup-cdr']??'') === '1'){ |
|
105 | + if (($this->options['backup-cdr'] ?? '') === '1') { |
|
106 | 106 | file_put_contents($this->file_list, 'backup-cdr:'.Cdr::getPathToDB()."\n", FILE_APPEND); |
107 | 107 | } |
108 | 108 | |
109 | - file_put_contents($this->file_list, $this->file_list."\n", FILE_APPEND); |
|
110 | - file_put_contents($this->file_list, $this->config_file."\n", FILE_APPEND); |
|
109 | + file_put_contents($this->file_list, $this->file_list."\n", FILE_APPEND); |
|
110 | + file_put_contents($this->file_list, $this->config_file."\n", FILE_APPEND); |
|
111 | 111 | |
112 | - if(($this->options['backup-sound-files']??'') === '1'){ |
|
113 | - Util::mwexec("find {$this->dirs['media']} -type f",$out); |
|
114 | - foreach ($out as $filename){ |
|
115 | - $flist.= 'backup-sound-files:'.$filename."\n"; |
|
112 | + if (($this->options['backup-sound-files'] ?? '') === '1') { |
|
113 | + Util::mwexec("find {$this->dirs['media']} -type f", $out); |
|
114 | + foreach ($out as $filename) { |
|
115 | + $flist .= 'backup-sound-files:'.$filename."\n"; |
|
116 | 116 | } |
117 | 117 | } |
118 | - if(($this->options['backup-records']??'') === '1'){ |
|
118 | + if (($this->options['backup-records'] ?? '') === '1') { |
|
119 | 119 | Util::mwexec("find {$this->dirs['astspoolpath']} -type f -name *.mp3", $out); |
120 | - foreach ($out as $filename){ |
|
121 | - $flist.= 'backup-records:'.$filename."\n"; |
|
120 | + foreach ($out as $filename) { |
|
121 | + $flist .= 'backup-records:'.$filename."\n"; |
|
122 | 122 | } |
123 | 123 | } |
124 | 124 | file_put_contents($this->file_list, $flist, FILE_APPEND); |
@@ -139,13 +139,13 @@ discard block |
||
139 | 139 | $arr_size['backup-cdr'] = Util::get_size_file(Cdr::getPathToDB()); |
140 | 140 | |
141 | 141 | $backup_config = Util::get_size_file($g['pt1c_db_path']); |
142 | - $backup_config+= Util::get_size_file($dirs['custom_modules']); |
|
143 | - $arr_size['backup-config'] = $backup_config; |
|
142 | + $backup_config += Util::get_size_file($dirs['custom_modules']); |
|
143 | + $arr_size['backup-config'] = $backup_config; |
|
144 | 144 | |
145 | - foreach ($arr_size as $key => $value){ |
|
145 | + foreach ($arr_size as $key => $value) { |
|
146 | 146 | // Есть какие то аномалии с преобразование значение в json |
147 | 147 | // Без этого костыля есть проблемы с округлением. |
148 | - $arr_size[$key] = trim(1*$value); |
|
148 | + $arr_size[$key] = trim(1 * $value); |
|
149 | 149 | } |
150 | 150 | return $arr_size; |
151 | 151 | } |
@@ -155,10 +155,10 @@ discard block |
||
155 | 155 | */ |
156 | 156 | private function create_img_file():void { |
157 | 157 | // Создаем директорию монтирования. |
158 | - if(!is_dir($this->result_dir) && mkdir($this->result_dir) && !is_dir($this->result_dir)){ |
|
159 | - Util::sys_log_msg('Backup', 'Can not create dir '. $this->result_dir); |
|
158 | + if (!is_dir($this->result_dir) && mkdir($this->result_dir) && !is_dir($this->result_dir)) { |
|
159 | + Util::sys_log_msg('Backup', 'Can not create dir '.$this->result_dir); |
|
160 | 160 | } |
161 | - if( !file_exists($this->result_file) ) { |
|
161 | + if (!file_exists($this->result_file)) { |
|
162 | 162 | // Оценим размер бекапа. |
163 | 163 | $result_size = 0; |
164 | 164 | $arr_size = self::get_estimated_size(); |
@@ -168,7 +168,7 @@ discard block |
||
168 | 168 | } |
169 | 169 | } |
170 | 170 | // Округляем в большую сторону. |
171 | - $result_size = $result_size < 1?1:round($result_size); |
|
171 | + $result_size = $result_size < 1 ? 1 : round($result_size); |
|
172 | 172 | $tmp_name = $this->dirs['tmp'].'/'.Util::generateRandomString(); |
173 | 173 | // Создаем образ файловой системы. |
174 | 174 | $res = Util::mwexec("/bin/dd if=/dev/zero of={$tmp_name} bs=1 count=0 seek={$result_size}M"); |
@@ -188,7 +188,7 @@ discard block |
||
188 | 188 | Util::mwexec("rm -rf '{$tmp_name}'"); |
189 | 189 | } |
190 | 190 | // Монтируем. |
191 | - if(! Storage::disk_is_mounted($this->result_file, '')) { |
|
191 | + if (!Storage::disk_is_mounted($this->result_file, '')) { |
|
192 | 192 | $res = Util::mwexec("/bin/mount -o loop {$this->result_file} {$this->result_dir}"); |
193 | 193 | if ($res > 1) { |
194 | 194 | Util::sys_log_msg('Backup', 'File system mount error...'); |
@@ -202,22 +202,22 @@ discard block |
||
202 | 202 | * @param $filename |
203 | 203 | */ |
204 | 204 | private function add_file_to_arhive($filename):void { |
205 | - if(!file_exists($filename)) { |
|
205 | + if (!file_exists($filename)) { |
|
206 | 206 | return; |
207 | 207 | } |
208 | - if($this->type==='img'){ |
|
208 | + if ($this->type === 'img') { |
|
209 | 209 | $this->create_img_file(); |
210 | 210 | $res_dir = dirname($this->result_dir.$filename); |
211 | 211 | Util::mwexec("mkdir -p $res_dir"); |
212 | - if(in_array(basename($filename), ['mikopbx.db', 'cdr.db']) ){ |
|
212 | + if (in_array(basename($filename), ['mikopbx.db', 'cdr.db'])) { |
|
213 | 213 | // Выполняем копирование через dump. |
214 | 214 | // Наиболее безопасный вариант. |
215 | 215 | Util::mwexec("/usr/bin/sqlite3 '{$filename}' .dump | /usr/bin/sqlite3 '{$this->result_dir}{$filename}' ", $out); |
216 | - }else{ |
|
216 | + } else { |
|
217 | 217 | // Просто копируем файл. |
218 | 218 | Util::mwexec("/bin/cp '{$filename}' '{$this->result_dir}{$filename}' ", $out); |
219 | 219 | } |
220 | - }else{ |
|
220 | + } else { |
|
221 | 221 | Util::mwexec("7za a -tzip -spf '{$this->result_file}' '{$filename}'", $out); |
222 | 222 | } |
223 | 223 | } |
@@ -228,21 +228,21 @@ discard block |
||
228 | 228 | * @param null | string $out |
229 | 229 | * @return bool |
230 | 230 | */ |
231 | - public function extract_file($filename='', &$out=null) :bool { |
|
231 | + public function extract_file($filename = '', &$out = null) :bool { |
|
232 | 232 | $arr_out = []; |
233 | 233 | |
234 | 234 | $result_file = $filename; |
235 | 235 | $tmp_path = '/var/asterisk/'; |
236 | 236 | $mem_monitor_dir = $this->dirs_mem['astspoolpath'].'/mikopbx/voicemailarchive/monitor'; |
237 | 237 | $monitor_dir = substr(Storage::get_monitor_dir(), 0, -1); |
238 | - if(strpos($filename, $tmp_path) === 0){ |
|
238 | + if (strpos($filename, $tmp_path) === 0) { |
|
239 | 239 | $var_search = [ |
240 | 240 | $mem_monitor_dir, |
241 | 241 | $this->dirs_mem['media'], |
242 | 242 | $this->dirs_mem['astlogpath'], |
243 | 243 | $this->dirs_mem['backup'] |
244 | 244 | ]; |
245 | - $var_replace= [ |
|
245 | + $var_replace = [ |
|
246 | 246 | $monitor_dir, |
247 | 247 | $this->dirs['media'], |
248 | 248 | $this->dirs['astlogpath'], |
@@ -252,21 +252,21 @@ discard block |
||
252 | 252 | } |
253 | 253 | |
254 | 254 | $file_dir = dirname($filename); |
255 | - if(!file_exists($file_dir)){ |
|
256 | - Util::mwexec('mkdir -p '.escapeshellcmd($file_dir) ); |
|
255 | + if (!file_exists($file_dir)) { |
|
256 | + Util::mwexec('mkdir -p '.escapeshellcmd($file_dir)); |
|
257 | 257 | } |
258 | 258 | $file_dir = dirname($result_file); |
259 | - if(!file_exists($file_dir)){ |
|
260 | - Util::mwexec('mkdir -p '.escapeshellcmd($file_dir) ); |
|
259 | + if (!file_exists($file_dir)) { |
|
260 | + Util::mwexec('mkdir -p '.escapeshellcmd($file_dir)); |
|
261 | 261 | } |
262 | 262 | |
263 | - if($this->type==='img') { |
|
264 | - if(! Storage::disk_is_mounted($this->result_file, '')) { |
|
263 | + if ($this->type === 'img') { |
|
264 | + if (!Storage::disk_is_mounted($this->result_file, '')) { |
|
265 | 265 | Util::mwexec("/bin/mount -o loop {$this->result_file} {$this->result_dir}"); |
266 | 266 | } |
267 | - if(in_array(basename($filename), ['mikopbx.db', 'cdr.db']) ){ |
|
267 | + if (in_array(basename($filename), ['mikopbx.db', 'cdr.db'])) { |
|
268 | 268 | $sed_command = ''; |
269 | - if($result_file !== $filename){ |
|
269 | + if ($result_file !== $filename) { |
|
270 | 270 | $sed_command = ' | sed \'s/'.str_replace('/', '\/', $mem_monitor_dir).'/'.str_replace('/', '\/', $monitor_dir).'/g\''; |
271 | 271 | $sed_command .= ' | sed \'s/'.str_replace('/', '\/', $this->dirs_mem['media']).'/'.str_replace('/', '\/', $this->dirs['media']).'/g\''; |
272 | 272 | } |
@@ -276,16 +276,16 @@ discard block |
||
276 | 276 | Util::mwexec("/usr/bin/sqlite3 '{$this->result_dir}{$filename}' .dump $sed_command | /usr/bin/sqlite3 '{$result_file}' ", $arr_out); |
277 | 277 | Util::mwexec("chown -R www:www {$result_file}* > /dev/null 2> /dev/null"); |
278 | 278 | |
279 | - }else{ |
|
279 | + } else { |
|
280 | 280 | // Просто копируем файл. |
281 | 281 | Util::mwexec("/bin/cp '{$this->result_dir}{$filename}' '{$result_file}'", $arr_out); |
282 | 282 | } |
283 | - }else { |
|
283 | + } else { |
|
284 | 284 | Util::mwexec("7za e -y -r -spf '{$this->result_file}' '{$filename}'", $arr_out); |
285 | - if($filename !== $result_file && file_exists($filename)){ |
|
285 | + if ($filename !== $result_file && file_exists($filename)) { |
|
286 | 286 | Util::mwexec("mv '{$filename}' '{$result_file}'", $arr_out); |
287 | 287 | } |
288 | - if(in_array(basename($filename), ['mikopbx.db', 'cdr.db']) ){ |
|
288 | + if (in_array(basename($filename), ['mikopbx.db', 'cdr.db'])) { |
|
289 | 289 | Util::mwexec("chown -R www:www {$result_file}* > /dev/null 2> /dev/null"); |
290 | 290 | } |
291 | 291 | } |
@@ -302,8 +302,8 @@ discard block |
||
302 | 302 | $result['result'] = 'Success'; |
303 | 303 | $result['id'] = $data['dir_name']; |
304 | 304 | $result['extension'] = $data['extension']; |
305 | - if($data['extension'] === 'img'){ |
|
306 | - if(!file_exists($data['res_file']??'')){ |
|
305 | + if ($data['extension'] === 'img') { |
|
306 | + if (!file_exists($data['res_file'] ?? '')) { |
|
307 | 307 | $result['result'] = 'ERROR'; |
308 | 308 | $result['data'] = "Backup file {$data['res_file']} not found"; |
309 | 309 | Util::sys_log_msg('Backup_unpack_conf_img', $result['data']); |
@@ -311,7 +311,7 @@ discard block |
||
311 | 311 | } |
312 | 312 | |
313 | 313 | $res = Util::mwexec("/bin/mount -o loop {$data['res_file']} {$data['mnt_point']}"); |
314 | - if($res !== 0){ |
|
314 | + if ($res !== 0) { |
|
315 | 315 | $result['result'] = 'ERROR'; |
316 | 316 | $result['data'] = "Fail mount {$data['res_file']}... on loop device..."; |
317 | 317 | Util::sys_log_msg('Backup_unpack_conf_img', $result['data']); |
@@ -320,23 +320,23 @@ discard block |
||
320 | 320 | |
321 | 321 | // Если бекап выполнялся в каталоге оперативной памяти: |
322 | 322 | $path_b_dir = "{$data['mnt_point']}/var/asterisk/backup/{$data['dir_name']}"; |
323 | - if(!file_exists($path_b_dir)){ |
|
323 | + if (!file_exists($path_b_dir)) { |
|
324 | 324 | // Бекап выполнялся на диск - хранилище |
325 | 325 | $path_b_dir = "{$data['mnt_point']}/storage/usbdisk[1-9]/mikopbx/backup/{$data['dir_name']}"; |
326 | 326 | } |
327 | 327 | Util::mwexec("du {$data['mnt_point']}/storage/*/{$data['dir_name']}/flist.txt -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
328 | - if(($out[0] ?? false) && file_exists($out[0])){ |
|
328 | + if (($out[0] ?? false) && file_exists($out[0])) { |
|
329 | 329 | // бекап выполнялся на сетевой диск. |
330 | 330 | $path_b_dir = dirname($out[0]); |
331 | 331 | } |
332 | 332 | |
333 | - if(!file_exists($path_b_dir)){ |
|
333 | + if (!file_exists($path_b_dir)) { |
|
334 | 334 | Util::mwexec("du {$data['mnt_point']}/storage/usbdisk[1-9]/mikopbx/backup/*/flist.txt -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
335 | - if(($out[0] ?? false) && file_exists($out[0])){ |
|
335 | + if (($out[0] ?? false) && file_exists($out[0])) { |
|
336 | 336 | // бекап выполнялся на сетевой диск. |
337 | 337 | $path_b_dir = dirname($out[0]); |
338 | 338 | $new_id = basename($path_b_dir); |
339 | - if($data['dir_name'] !== $new_id){ |
|
339 | + if ($data['dir_name'] !== $new_id) { |
|
340 | 340 | $result['new_id'] = $new_id; |
341 | 341 | } |
342 | 342 | } |
@@ -345,25 +345,25 @@ discard block |
||
345 | 345 | $res = Util::mwexec("/bin/cp {$path_b_dir}/* {$data['backupdir']}/{$data['dir_name']}"); |
346 | 346 | |
347 | 347 | Util::mwexec("/bin/umount {$data['res_file']}"); |
348 | - if(isset($result['new_id'])){ |
|
348 | + if (isset($result['new_id'])) { |
|
349 | 349 | $res = Util::mwexec("/bin/mv {$data['backupdir']}/{$data['dir_name']} {$data['backupdir']}/{$result['new_id']}"); |
350 | 350 | $data['dir_name'] = $result['new_id']; |
351 | 351 | } |
352 | - if($res !== 0){ |
|
352 | + if ($res !== 0) { |
|
353 | 353 | $result['result'] = 'ERROR'; |
354 | 354 | $result['data'] = 'Fail mount cp data from loop device...'; |
355 | 355 | Util::sys_log_msg('Backup_unpack_conf_img', $result['data']); |
356 | 356 | } |
357 | 357 | |
358 | - if( ! file_exists("{$data['backupdir']}/{$data['dir_name']}/flist.txt") || |
|
359 | - ! file_exists("{$data['backupdir']}/{$data['dir_name']}/config.json")){ |
|
358 | + if (!file_exists("{$data['backupdir']}/{$data['dir_name']}/flist.txt") || |
|
359 | + !file_exists("{$data['backupdir']}/{$data['dir_name']}/config.json")) { |
|
360 | 360 | $result['result'] = 'ERROR'; |
361 | 361 | $result['data'] = 'Broken backup file'; |
362 | 362 | } |
363 | - if($result['result'] === 'ERROR'){ |
|
363 | + if ($result['result'] === 'ERROR') { |
|
364 | 364 | unlink($data['res_file']); |
365 | 365 | } |
366 | - }elseif($data['extension'] === 'zip'){ |
|
366 | + }elseif ($data['extension'] === 'zip') { |
|
367 | 367 | file_put_contents("{$data['backupdir']}/{$data['dir_name']}/progress.txt", '0'); |
368 | 368 | |
369 | 369 | self::static_extract_file($data['dir_name'], $data['res_file'], "{$data['backupdir']}/{$data['dir_name']}/flist.txt"); |
@@ -381,33 +381,33 @@ discard block |
||
381 | 381 | */ |
382 | 382 | public static function static_extract_file($id, $arh, $filename):void { |
383 | 383 | $type = Util::get_extension_file($arh); |
384 | - if($type==='img') { |
|
384 | + if ($type === 'img') { |
|
385 | 385 | $result_dir = basename($arh).'/mnt_point'; |
386 | - if(! Storage::disk_is_mounted($arh, '')) { |
|
386 | + if (!Storage::disk_is_mounted($arh, '')) { |
|
387 | 387 | Util::mwexec("/bin/mount -o loop {$arh} {$result_dir}"); |
388 | 388 | } |
389 | 389 | Util::mwexec("du /storage/*/{$id} -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
390 | - if(($out[0] ?? false) && file_exists($out[0])){ |
|
390 | + if (($out[0] ?? false) && file_exists($out[0])) { |
|
391 | 391 | $src_file = $out[0]; |
392 | - }else{ |
|
392 | + } else { |
|
393 | 393 | $src_file = "{$result_dir}{$filename}"; |
394 | 394 | } |
395 | 395 | Util::mwexec("/bin/cp '{$src_file}' '{$filename}'", $arr_out); |
396 | 396 | Util::mwexec("/bin/umount $arh"); |
397 | - }else { |
|
397 | + } else { |
|
398 | 398 | Util::mwexec("7za e -y -r -spf {$arh} {$filename}"); |
399 | - if(!file_exists($filename)){ |
|
399 | + if (!file_exists($filename)) { |
|
400 | 400 | $command_status = Util::mwexec("7za l {$arh} | grep '".basename($filename)."' | /bin/busybox awk '{print $6}'", $out); |
401 | - if($command_status === 0){ |
|
401 | + if ($command_status === 0) { |
|
402 | 402 | $path_to_file = implode('', $out); |
403 | 403 | |
404 | 404 | $file_dir = dirname($path_to_file); |
405 | - if(!file_exists($file_dir)){ |
|
406 | - Util::mwexec('mkdir -p '.escapeshellcmd($file_dir) ); |
|
405 | + if (!file_exists($file_dir)) { |
|
406 | + Util::mwexec('mkdir -p '.escapeshellcmd($file_dir)); |
|
407 | 407 | } |
408 | 408 | $file_dir = dirname($filename); |
409 | - if(!file_exists($file_dir)){ |
|
410 | - Util::mwexec('mkdir -p '.escapeshellcmd($file_dir) ); |
|
409 | + if (!file_exists($file_dir)) { |
|
410 | + Util::mwexec('mkdir -p '.escapeshellcmd($file_dir)); |
|
411 | 411 | } |
412 | 412 | Util::mwexec("7za e -y -r -spf {$arh} {$path_to_file}"); |
413 | 413 | Util::mwexec("mv $path_to_file $filename"); |
@@ -422,41 +422,41 @@ discard block |
||
422 | 422 | * @return array |
423 | 423 | */ |
424 | 424 | public function create_arhive():array { |
425 | - if(!file_exists("{$this->dirs['backup']}/{$this->id}")){ |
|
425 | + if (!file_exists("{$this->dirs['backup']}/{$this->id}")) { |
|
426 | 426 | return ['result' => 'ERROR', 'message' => 'Unable to create directory for the backup.']; |
427 | 427 | } |
428 | 428 | $result = $this->create_file_list(); |
429 | - if(!$result){ |
|
429 | + if (!$result) { |
|
430 | 430 | return ['result' => 'ERROR', 'message' => 'Unable to create file list. Failed to create file.']; |
431 | 431 | } |
432 | 432 | |
433 | - if(file_exists($this->progress_file)){ |
|
433 | + if (file_exists($this->progress_file)) { |
|
434 | 434 | $file_data = file_get_contents($this->progress_file); |
435 | 435 | $data = explode('/', $file_data); |
436 | - $this->progress = trim($data[0])*1; |
|
436 | + $this->progress = trim($data[0]) * 1; |
|
437 | 437 | } |
438 | - if(!file_exists($this->file_list)){ |
|
438 | + if (!file_exists($this->file_list)) { |
|
439 | 439 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
440 | 440 | } |
441 | 441 | $lines = file($this->file_list); |
442 | - if($lines === FALSE){ |
|
442 | + if ($lines === FALSE) { |
|
443 | 443 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
444 | 444 | } |
445 | 445 | $count_files = count($lines); |
446 | 446 | file_put_contents($this->progress_file, "{$this->progress}/{$count_files}"); |
447 | - while ($this->progress < $count_files){ |
|
447 | + while ($this->progress < $count_files) { |
|
448 | 448 | $filename_data = trim($lines[$this->progress]); |
449 | - if(strpos($filename_data,':')===false){ |
|
449 | + if (strpos($filename_data, ':') === false) { |
|
450 | 450 | $filename = $filename_data; |
451 | - }else{ |
|
451 | + } else { |
|
452 | 452 | $filename = (explode(':', $filename_data))[1]; |
453 | 453 | } |
454 | - if(is_dir($filename) === FALSE){ |
|
454 | + if (is_dir($filename) === FALSE) { |
|
455 | 455 | $this->add_file_to_arhive($filename); |
456 | 456 | } |
457 | 457 | |
458 | 458 | $this->progress++; |
459 | - if($this->progress % 10 === 0){ |
|
459 | + if ($this->progress % 10 === 0) { |
|
460 | 460 | file_put_contents($this->progress_file, "{$this->progress}/{$count_files}"); |
461 | 461 | } |
462 | 462 | } |
@@ -464,7 +464,7 @@ discard block |
||
464 | 464 | file_put_contents($this->progress_file, "{$this->progress}/{$count_files}"); |
465 | 465 | $this->add_file_to_arhive($this->progress_file); |
466 | 466 | |
467 | - if(Storage::disk_is_mounted($this->result_file, '')){ |
|
467 | + if (Storage::disk_is_mounted($this->result_file, '')) { |
|
468 | 468 | Util::mwexec("/bin/umount $this->result_file"); |
469 | 469 | } |
470 | 470 | |
@@ -477,15 +477,15 @@ discard block |
||
477 | 477 | */ |
478 | 478 | public function get_result_file():string { |
479 | 479 | |
480 | - if(!file_exists($this->result_file)){ |
|
480 | + if (!file_exists($this->result_file)) { |
|
481 | 481 | $BackupRules = Models\BackupRules::find('enabled="1"'); |
482 | - foreach ($BackupRules as $res){ |
|
482 | + foreach ($BackupRules as $res) { |
|
483 | 483 | $backup_dir = '/storage/'.$res->ftp_host.'.'.$res->ftp_port; |
484 | 484 | $filename = "{$backup_dir}/{$this->id}/resultfile"; |
485 | - if(file_exists("{$filename}.zip")){ |
|
485 | + if (file_exists("{$filename}.zip")) { |
|
486 | 486 | $this->result_file = "{$filename}.zip"; |
487 | 487 | } |
488 | - if(file_exists("{$filename}.img")){ |
|
488 | + if (file_exists("{$filename}.img")) { |
|
489 | 489 | $this->result_file = "{$filename}.img"; |
490 | 490 | } |
491 | 491 | } |
@@ -499,7 +499,7 @@ discard block |
||
499 | 499 | * @param string $backup_dir |
500 | 500 | * @return array |
501 | 501 | */ |
502 | - public static function list_backups($backup_dir=''):array { |
|
502 | + public static function list_backups($backup_dir = ''):array { |
|
503 | 503 | $result = array( |
504 | 504 | 'result' => 'Success' |
505 | 505 | ); |
@@ -507,55 +507,55 @@ discard block |
||
507 | 507 | $result['data'] = []; |
508 | 508 | |
509 | 509 | // Проверка каталогов FTP / SFTP бекапа: |
510 | - if(empty($backup_dir)){ |
|
510 | + if (empty($backup_dir)) { |
|
511 | 511 | self::list_backups_ftp($result['data']); |
512 | 512 | } |
513 | 513 | |
514 | 514 | $dirs = PBX::get_asterisk_dirs(); |
515 | - if(!empty($backup_dir)){ |
|
515 | + if (!empty($backup_dir)) { |
|
516 | 516 | $dirs['backup'] = $backup_dir; |
517 | 517 | } |
518 | 518 | |
519 | - if(!is_dir($dirs['backup'])){ |
|
519 | + if (!is_dir($dirs['backup'])) { |
|
520 | 520 | return $result; |
521 | 521 | } |
522 | 522 | $entries = scandir($dirs['backup']); |
523 | - foreach($entries as $entry) { |
|
523 | + foreach ($entries as $entry) { |
|
524 | 524 | $base_filename = basename($entry); |
525 | - if($base_filename === '.' || $base_filename === '..'){ |
|
525 | + if ($base_filename === '.' || $base_filename === '..') { |
|
526 | 526 | continue; |
527 | 527 | } |
528 | - $filename = "{$dirs['backup']}/{$base_filename}/resultfile.zip"; |
|
529 | - if(!file_exists($filename)) { |
|
530 | - $filename = "{$dirs['backup']}/{$base_filename}/resultfile.img"; |
|
528 | + $filename = "{$dirs['backup']}/{$base_filename}/resultfile.zip"; |
|
529 | + if (!file_exists($filename)) { |
|
530 | + $filename = "{$dirs['backup']}/{$base_filename}/resultfile.img"; |
|
531 | 531 | } |
532 | 532 | |
533 | 533 | $file_progress = "{$dirs['backup']}/{$base_filename}/progress.txt"; |
534 | - if(file_exists($file_progress)){ |
|
534 | + if (file_exists($file_progress)) { |
|
535 | 535 | $size = 0; |
536 | - if(file_exists($filename)){ |
|
536 | + if (file_exists($filename)) { |
|
537 | 537 | $size = round(filesize($filename) / 1024 / 1024, 2); // размер в мегабайтах. |
538 | 538 | } |
539 | 539 | // Получим данные по прогрессу и количеству файлов. |
540 | 540 | $file_data = file_get_contents($file_progress); |
541 | 541 | $data = explode('/', $file_data); |
542 | - $progress = (count($data)>0 && is_numeric($data[0]) )?trim($data[0])*1:0; |
|
543 | - $total = (count($data)>1 && is_numeric($data[1]) )?trim($data[1])*1:0; |
|
544 | - $config_file="{$dirs['backup']}/{$base_filename}/config.json"; |
|
542 | + $progress = (count($data) > 0 && is_numeric($data[0])) ?trim($data[0]) * 1 : 0; |
|
543 | + $total = (count($data) > 1 && is_numeric($data[1])) ?trim($data[1]) * 1 : 0; |
|
544 | + $config_file = "{$dirs['backup']}/{$base_filename}/config.json"; |
|
545 | 545 | |
546 | - if(file_exists("{$dirs['backup']}/{$base_filename}/progress_recover.txt")){ |
|
546 | + if (file_exists("{$dirs['backup']}/{$base_filename}/progress_recover.txt")) { |
|
547 | 547 | $file_data = file_get_contents("{$dirs['backup']}/{$base_filename}/progress_recover.txt"); |
548 | 548 | $data = explode('/', $file_data); |
549 | - $progress_recover = (count($data)>0)?trim($data[0])*1:0; |
|
550 | - if($total === 0 ){ |
|
551 | - $total = (count($data)>1)?trim($data[1])*1:0; |
|
549 | + $progress_recover = (count($data) > 0) ?trim($data[0]) * 1 : 0; |
|
550 | + if ($total === 0) { |
|
551 | + $total = (count($data) > 1) ?trim($data[1]) * 1 : 0; |
|
552 | 552 | } |
553 | - }else{ |
|
553 | + } else { |
|
554 | 554 | $progress_recover = ''; |
555 | 555 | } |
556 | 556 | |
557 | 557 | $config = null; |
558 | - if(file_exists($config_file)){ |
|
558 | + if (file_exists($config_file)) { |
|
559 | 559 | $config = json_decode(file_get_contents($config_file), true); |
560 | 560 | } |
561 | 561 | // Вычислим timestamp. |
@@ -589,26 +589,26 @@ discard block |
||
589 | 589 | $tmp_data = [$data]; |
590 | 590 | |
591 | 591 | $BackupRules = Models\BackupRules::find('enabled="1"'); |
592 | - foreach ($BackupRules as $res){ |
|
592 | + foreach ($BackupRules as $res) { |
|
593 | 593 | $backup_dir = '/storage/'.$res->ftp_host.'.'.$res->ftp_port; |
594 | 594 | $disk_mounted = Storage::is_storage_disk_mounted("$backup_dir "); |
595 | - if(!$disk_mounted){ |
|
596 | - if($res->ftp_sftp_mode === '1'){ |
|
595 | + if (!$disk_mounted) { |
|
596 | + if ($res->ftp_sftp_mode === '1') { |
|
597 | 597 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
598 | - }else{ |
|
598 | + } else { |
|
599 | 599 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
600 | 600 | } |
601 | 601 | } |
602 | - if(!$disk_mounted){ |
|
602 | + if (!$disk_mounted) { |
|
603 | 603 | continue; |
604 | 604 | } |
605 | 605 | |
606 | 606 | // Проверим, не является ли удаленный диск локальным. |
607 | 607 | $test_data = md5(time()); |
608 | 608 | file_put_contents("{$backup_dir}/test.tmp", $test_data); |
609 | - if(file_exists("{$dirs['backup']}/test.tmp")){ |
|
609 | + if (file_exists("{$dirs['backup']}/test.tmp")) { |
|
610 | 610 | $test_data_res = file_get_contents("{$dirs['backup']}/test.tmp"); |
611 | - if($test_data_res === $test_data){ |
|
611 | + if ($test_data_res === $test_data) { |
|
612 | 612 | unlink("{$backup_dir}/test.tmp"); |
613 | 613 | // Это локальный диск подключен по SFTP. Не нужно обрабатывать. |
614 | 614 | continue; |
@@ -617,16 +617,16 @@ discard block |
||
617 | 617 | // Чистим временный файл. |
618 | 618 | unlink("{$backup_dir}/test.tmp"); |
619 | 619 | |
620 | - $out = []; |
|
621 | - $command = "/usr/bin/timeout -t 3 ls -l {$backup_dir}"; |
|
622 | - Util::mwexec($command,$out); |
|
620 | + $out = []; |
|
621 | + $command = "/usr/bin/timeout -t 3 ls -l {$backup_dir}"; |
|
622 | + Util::mwexec($command, $out); |
|
623 | 623 | $response = trim(implode('', $out)); |
624 | - if('Terminated' === $response){ |
|
624 | + if ('Terminated' === $response) { |
|
625 | 625 | // Удаленный сервер не ответил / или не корректно указан пароль. |
626 | 626 | continue; |
627 | 627 | } |
628 | 628 | $result = self::list_backups($backup_dir); |
629 | - foreach ($result['data'] as &$b){ |
|
629 | + foreach ($result['data'] as &$b) { |
|
630 | 630 | $b['m_BackupRules_id'] = $res->id; |
631 | 631 | $b['m_BackupRules_host'] = $res->ftp_host; |
632 | 632 | $b['m_BackupRules_port'] = $res->ftp_port; |
@@ -643,12 +643,12 @@ discard block |
||
643 | 643 | * @param array | null $options |
644 | 644 | * @return array |
645 | 645 | */ |
646 | - public static function start($options=null):array { |
|
646 | + public static function start($options = null):array { |
|
647 | 647 | global $g; |
648 | 648 | $result = []; |
649 | 649 | $id = 'backup_'.time(); |
650 | - if($options !== null){ |
|
651 | - if(isset($options['id'])){ |
|
650 | + if ($options !== null) { |
|
651 | + if (isset($options['id'])) { |
|
652 | 652 | $id = $options['id']; |
653 | 653 | } |
654 | 654 | // Инициализируем настройки резервного копирования. |
@@ -670,11 +670,11 @@ discard block |
||
670 | 670 | * @param $options |
671 | 671 | * @return array |
672 | 672 | */ |
673 | - public static function start_recover($id, $options=null):array { |
|
673 | + public static function start_recover($id, $options = null):array { |
|
674 | 674 | global $g; |
675 | 675 | $result = []; |
676 | 676 | |
677 | - if(empty($id)){ |
|
677 | + if (empty($id)) { |
|
678 | 678 | $result['result'] = 'Error'; |
679 | 679 | $result['message'] = 'ID is empty'; |
680 | 680 | return $result; |
@@ -721,7 +721,7 @@ discard block |
||
721 | 721 | * @return array |
722 | 722 | */ |
723 | 723 | public static function remove($id):array { |
724 | - if(empty($id)){ |
|
724 | + if (empty($id)) { |
|
725 | 725 | $result['result'] = 'Error'; |
726 | 726 | $result['message'] = 'ID is empty'; |
727 | 727 | return $result; |
@@ -729,14 +729,14 @@ discard block |
||
729 | 729 | $result = []; |
730 | 730 | $b_dir = self::get_backup_dir()."/{$id}"; |
731 | 731 | $b_dirs = []; |
732 | - if(file_exists($b_dir)){ |
|
732 | + if (file_exists($b_dir)) { |
|
733 | 733 | $b_dirs[] = $b_dir; |
734 | 734 | } |
735 | - $list = self::list_backups(); |
|
736 | - foreach ($list['data'] as $backup_data){ |
|
737 | - if($id === $backup_data['id'] && isset($backup_data['config']['backup'])){ |
|
738 | - $b_dir = $backup_data['config']['backup']."/{$id}"; |
|
739 | - if(file_exists($b_dir)){ |
|
735 | + $list = self::list_backups(); |
|
736 | + foreach ($list['data'] as $backup_data) { |
|
737 | + if ($id === $backup_data['id'] && isset($backup_data['config']['backup'])) { |
|
738 | + $b_dir = $backup_data['config']['backup']."/{$id}"; |
|
739 | + if (file_exists($b_dir)) { |
|
740 | 740 | $b_dirs[] = $b_dir; |
741 | 741 | } |
742 | 742 | } |
@@ -744,22 +744,22 @@ discard block |
||
744 | 744 | |
745 | 745 | $BackupRules = Models\BackupRules::find('enabled="1"'); |
746 | 746 | foreach ($BackupRules as $res) { |
747 | - $b_dir = '/storage/' . $res->ftp_host . '.' . $res->ftp_port."/{$id}"; |
|
748 | - if(file_exists($b_dir)){ |
|
747 | + $b_dir = '/storage/'.$res->ftp_host.'.'.$res->ftp_port."/{$id}"; |
|
748 | + if (file_exists($b_dir)) { |
|
749 | 749 | $b_dirs[] = $b_dir; |
750 | 750 | } |
751 | 751 | } |
752 | 752 | |
753 | - if(count($b_dirs) === 0){ |
|
753 | + if (count($b_dirs) === 0) { |
|
754 | 754 | $result['result'] = 'Error'; |
755 | 755 | $result['message'] = 'File not found'; |
756 | 756 | return $result; |
757 | 757 | } |
758 | 758 | |
759 | - $ret = Util::mwexec('rm -rf '.implode(' ', $b_dirs) ); |
|
759 | + $ret = Util::mwexec('rm -rf '.implode(' ', $b_dirs)); |
|
760 | 760 | clearstatcache(); |
761 | 761 | |
762 | - $result['result'] = $ret !== 0 ?'Error':'Success'; |
|
762 | + $result['result'] = $ret !== 0 ? 'Error' : 'Success'; |
|
763 | 763 | return $result; |
764 | 764 | } |
765 | 765 | |
@@ -768,12 +768,12 @@ discard block |
||
768 | 768 | * @param $options |
769 | 769 | */ |
770 | 770 | public function save_options_recover_file($options):void { |
771 | - if($options === null && file_exists($this->options_recover_file)){ |
|
771 | + if ($options === null && file_exists($this->options_recover_file)) { |
|
772 | 772 | // Удаляем ненужный файл настроек. |
773 | 773 | unlink($this->options_recover_file); |
774 | 774 | } |
775 | 775 | |
776 | - if($options!==null){ |
|
776 | + if ($options !== null) { |
|
777 | 777 | // Сохраняем настройки. Файл будет использоваться фоновым процессом. |
778 | 778 | file_put_contents($this->options_recover_file, json_encode($options, JSON_UNESCAPED_SLASHES)); |
779 | 779 | } |
@@ -784,70 +784,70 @@ discard block |
||
784 | 784 | * @return array |
785 | 785 | */ |
786 | 786 | public function recover_with_progress():array { |
787 | - if(!Storage::is_storage_disk_mounted()){ |
|
787 | + if (!Storage::is_storage_disk_mounted()) { |
|
788 | 788 | return ['result' => 'ERROR', 'message' => 'Storage is not mounted.']; |
789 | 789 | } |
790 | 790 | $options = null; |
791 | - if(file_exists($this->options_recover_file)){ |
|
791 | + if (file_exists($this->options_recover_file)) { |
|
792 | 792 | $options = json_decode(file_get_contents($this->options_recover_file), true); |
793 | 793 | } |
794 | 794 | |
795 | - if(!file_exists($this->file_list)){ |
|
795 | + if (!file_exists($this->file_list)) { |
|
796 | 796 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
797 | 797 | } |
798 | 798 | $lines = file($this->file_list); |
799 | - if($lines === FALSE){ |
|
799 | + if ($lines === FALSE) { |
|
800 | 800 | return ['result' => 'ERROR', 'message' => 'File list not read.']; |
801 | 801 | } |
802 | 802 | |
803 | - if(file_exists($this->progress_file_recover)){ |
|
803 | + if (file_exists($this->progress_file_recover)) { |
|
804 | 804 | // Получим текущий прогресс. |
805 | 805 | $file_data = file_get_contents($this->progress_file_recover); |
806 | 806 | $data = explode('/', $file_data); |
807 | - $this->progress = trim($data[0])*1; |
|
807 | + $this->progress = trim($data[0]) * 1; |
|
808 | 808 | } |
809 | 809 | |
810 | 810 | $count_files = count($lines); |
811 | - if($this->progress === $count_files){ |
|
811 | + if ($this->progress === $count_files) { |
|
812 | 812 | $this->progress = 0; |
813 | 813 | } |
814 | 814 | |
815 | 815 | file_put_contents($this->progress_file_recover, "{$this->progress}/{$count_files}"); |
816 | - while ($this->progress < $count_files){ |
|
816 | + while ($this->progress < $count_files) { |
|
817 | 817 | $filename_data = trim($lines[$this->progress]); |
818 | - if(strpos($filename_data,':')===false){ |
|
818 | + if (strpos($filename_data, ':') === false) { |
|
819 | 819 | $section = ''; // Этот файл будет восстановленр в любом случае. |
820 | 820 | $filename = $filename_data; |
821 | - }else{ |
|
821 | + } else { |
|
822 | 822 | $tmp_data = explode(':', $filename_data); |
823 | 823 | $section = $tmp_data[0] ?? ''; |
824 | 824 | $filename = $tmp_data[1] ?? ''; |
825 | 825 | } |
826 | 826 | |
827 | 827 | $this->progress++; |
828 | - if(in_array(basename($filename),['flist.txt', 'config.json'])){ |
|
828 | + if (in_array(basename($filename), ['flist.txt', 'config.json'])) { |
|
829 | 829 | continue; |
830 | 830 | } |
831 | 831 | |
832 | - if( $section!=='' && is_array($options) && !isset($options[$section]) ){ |
|
832 | + if ($section !== '' && is_array($options) && !isset($options[$section])) { |
|
833 | 833 | // Если секция указана, и она не определена в массиве опций, |
834 | 834 | // то не восстанавливаем файл. |
835 | 835 | unset($filename); |
836 | - }else{ |
|
836 | + } else { |
|
837 | 837 | $this->extract_file($filename); |
838 | 838 | } |
839 | - if($this->progress % 10 === 0){ |
|
839 | + if ($this->progress % 10 === 0) { |
|
840 | 840 | file_put_contents($this->progress_file_recover, "{$this->progress}/{$count_files}"); |
841 | 841 | } |
842 | 842 | } |
843 | 843 | file_put_contents($this->progress_file_recover, "{$this->progress}/{$count_files}"); |
844 | 844 | |
845 | - if(Storage::disk_is_mounted($this->result_file, '')){ |
|
845 | + if (Storage::disk_is_mounted($this->result_file, '')) { |
|
846 | 846 | Util::mwexec("umount $this->result_file"); |
847 | 847 | } |
848 | 848 | Cdr::set_permit_to_db(); |
849 | 849 | |
850 | - if(isset($options['backup-config']) && $options['backup-config'] === '1') { |
|
850 | + if (isset($options['backup-config']) && $options['backup-config'] === '1') { |
|
851 | 851 | System::reboot_sync(false); |
852 | 852 | } |
853 | 853 | return ['result' => 'Success', 'count_files' => $count_files]; |
@@ -869,25 +869,25 @@ discard block |
||
869 | 869 | global $g; |
870 | 870 | |
871 | 871 | $commands = Models\BackupRules::find('enabled="1"'); |
872 | - foreach ($commands as $cmd){ |
|
873 | - $day = ('0' === $cmd->every)?'*':$cmd->every; |
|
872 | + foreach ($commands as $cmd) { |
|
873 | + $day = ('0' === $cmd->every) ? '*' : $cmd->every; |
|
874 | 874 | $arr_time = explode(':', $cmd->at_time); |
875 | - if(count($arr_time)!==2){ |
|
875 | + if (count($arr_time) !== 2) { |
|
876 | 876 | $h = '*'; |
877 | 877 | $m = '*'; |
878 | - }else{ |
|
878 | + } else { |
|
879 | 879 | $h = $arr_time[0]; |
880 | - if($h === '0'){ |
|
880 | + if ($h === '0') { |
|
881 | 881 | $h = '*'; |
882 | 882 | } |
883 | 883 | $m = $arr_time[1]; |
884 | - $m = (strpos($m,'0')===0)?substr($m,1,1):$m; |
|
885 | - if($m === '0'){ |
|
884 | + $m = (strpos($m, '0') === 0) ?substr($m, 1, 1) : $m; |
|
885 | + if ($m === '0') { |
|
886 | 886 | $m = '0'; |
887 | 887 | } |
888 | 888 | } |
889 | 889 | |
890 | - if('*' === $h && '*' === $m && '*' === $day){ |
|
890 | + if ('*' === $h && '*' === $m && '*' === $day) { |
|
891 | 891 | // Не корректно описано расписание. |
892 | 892 | continue; |
893 | 893 | } |
@@ -902,15 +902,15 @@ discard block |
||
902 | 902 | global $g; |
903 | 903 | $commands = Models\BackupRules::find('enabled="1"'); |
904 | 904 | $queue_commands = []; |
905 | - foreach ($commands as $cmd){ |
|
905 | + foreach ($commands as $cmd) { |
|
906 | 906 | $command = "/usr/bin/nohup /usr/bin/php -f {$g['pt1c_inc_path']}/workers/worker_backup.php "; |
907 | 907 | $params = "none backup {$cmd->id} > /dev/null 2>&1 &"; |
908 | 908 | $queue_commands[] = "{$command} {$params}\n"; |
909 | 909 | } |
910 | 910 | Util::mwexec_commands($queue_commands); |
911 | - if(count($queue_commands) === 0){ |
|
911 | + if (count($queue_commands) === 0) { |
|
912 | 912 | $result['result'] = 'Error'; |
913 | - }else{ |
|
913 | + } else { |
|
914 | 914 | $result['result'] = 'Success'; |
915 | 915 | } |
916 | 916 | |
@@ -926,25 +926,25 @@ discard block |
||
926 | 926 | $result = []; |
927 | 927 | /** @var Models\BackupRules $res */ |
928 | 928 | $res = BackupRules::findFirst("id='{$id}'"); |
929 | - if(!$res){ |
|
929 | + if (!$res) { |
|
930 | 930 | return ['result' => 'Error', 'message' => 'Backup rule not found.']; |
931 | 931 | } |
932 | 932 | $backup_dir = '/storage/'.$res->ftp_host.'.'.$res->ftp_port; |
933 | 933 | /** @var Storage::is_storage_disk_mounted $disk_mounted */ |
934 | 934 | $disk_mounted = Storage::is_storage_disk_mounted("$backup_dir "); |
935 | 935 | $disk_mounted_start = $disk_mounted; |
936 | - if(!$disk_mounted){ |
|
937 | - if($res->ftp_sftp_mode === '1'){ |
|
936 | + if (!$disk_mounted) { |
|
937 | + if ($res->ftp_sftp_mode === '1') { |
|
938 | 938 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
939 | - }else{ |
|
939 | + } else { |
|
940 | 940 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
941 | 941 | } |
942 | 942 | } |
943 | - if(!$disk_mounted){ |
|
943 | + if (!$disk_mounted) { |
|
944 | 944 | return ['result' => 'Error', 'message' => 'Failed to mount backup disk...']; |
945 | 945 | } |
946 | - $result['result'] = 'Success'; |
|
947 | - if(!$disk_mounted_start){ |
|
946 | + $result['result'] = 'Success'; |
|
947 | + if (!$disk_mounted_start) { |
|
948 | 948 | Storage::umount_disk($backup_dir); |
949 | 949 | } |
950 | 950 | return $result; |
@@ -10,7 +10,8 @@ discard block |
||
10 | 10 | |
11 | 11 | require_once 'globals.php'; |
12 | 12 | |
13 | -class Backup { |
|
13 | +class Backup |
|
14 | +{ |
|
14 | 15 | private $id; |
15 | 16 | private $dirs; |
16 | 17 | private $dirs_mem; |
@@ -25,14 +26,15 @@ discard block |
||
25 | 26 | private $progress=0; |
26 | 27 | private $type='img'; // img | zip |
27 | 28 | |
28 | - public function __construct($id, $options=null){ |
|
29 | + public function __construct($id, $options=null) |
|
30 | + { |
|
29 | 31 | $this->dirs = PBX::get_asterisk_dirs(); |
30 | 32 | $this->dirs_mem = PBX::get_asterisk_dirs_mem(); |
31 | 33 | // Проверим особенность бекапа на сетевой диск. |
32 | 34 | Util::mwexec("du /storage/*/{$id}/flist.txt -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
33 | 35 | if(($out[0] ?? false) && file_exists($out[0])){ |
34 | 36 | $this->dirs['backup'] = dirname($out[0], 2); |
35 | - }elseif (is_array($options) && isset($options['backup'])){ |
|
37 | + } elseif (is_array($options) && isset($options['backup'])){ |
|
36 | 38 | // Переопределяем каталог с бекапом. |
37 | 39 | $this->dirs['backup'] = $options['backup']; |
38 | 40 | } |
@@ -60,7 +62,7 @@ discard block |
||
60 | 62 | |
61 | 63 | if((!is_array($options) || $options === null) && file_exists($this->config_file)){ |
62 | 64 | $this->options = json_decode(file_get_contents($this->config_file), true); |
63 | - }else{ |
|
65 | + } else{ |
|
64 | 66 | $this->options = $options; |
65 | 67 | } |
66 | 68 | |
@@ -85,7 +87,7 @@ discard block |
||
85 | 87 | |
86 | 88 | try{ |
87 | 89 | $result = @file_put_contents($this->file_list, ''); |
88 | - }catch (Exception $e){ |
|
90 | + } catch (Exception $e){ |
|
89 | 91 | Util::sys_log_msg('Backup', $e->getMessage()); |
90 | 92 | $result = false; |
91 | 93 | } |
@@ -213,11 +215,11 @@ discard block |
||
213 | 215 | // Выполняем копирование через dump. |
214 | 216 | // Наиболее безопасный вариант. |
215 | 217 | Util::mwexec("/usr/bin/sqlite3 '{$filename}' .dump | /usr/bin/sqlite3 '{$this->result_dir}{$filename}' ", $out); |
216 | - }else{ |
|
218 | + } else{ |
|
217 | 219 | // Просто копируем файл. |
218 | 220 | Util::mwexec("/bin/cp '{$filename}' '{$this->result_dir}{$filename}' ", $out); |
219 | 221 | } |
220 | - }else{ |
|
222 | + } else{ |
|
221 | 223 | Util::mwexec("7za a -tzip -spf '{$this->result_file}' '{$filename}'", $out); |
222 | 224 | } |
223 | 225 | } |
@@ -276,11 +278,11 @@ discard block |
||
276 | 278 | Util::mwexec("/usr/bin/sqlite3 '{$this->result_dir}{$filename}' .dump $sed_command | /usr/bin/sqlite3 '{$result_file}' ", $arr_out); |
277 | 279 | Util::mwexec("chown -R www:www {$result_file}* > /dev/null 2> /dev/null"); |
278 | 280 | |
279 | - }else{ |
|
281 | + } else{ |
|
280 | 282 | // Просто копируем файл. |
281 | 283 | Util::mwexec("/bin/cp '{$this->result_dir}{$filename}' '{$result_file}'", $arr_out); |
282 | 284 | } |
283 | - }else { |
|
285 | + } else { |
|
284 | 286 | Util::mwexec("7za e -y -r -spf '{$this->result_file}' '{$filename}'", $arr_out); |
285 | 287 | if($filename !== $result_file && file_exists($filename)){ |
286 | 288 | Util::mwexec("mv '{$filename}' '{$result_file}'", $arr_out); |
@@ -363,7 +365,7 @@ discard block |
||
363 | 365 | if($result['result'] === 'ERROR'){ |
364 | 366 | unlink($data['res_file']); |
365 | 367 | } |
366 | - }elseif($data['extension'] === 'zip'){ |
|
368 | + } elseif($data['extension'] === 'zip'){ |
|
367 | 369 | file_put_contents("{$data['backupdir']}/{$data['dir_name']}/progress.txt", '0'); |
368 | 370 | |
369 | 371 | self::static_extract_file($data['dir_name'], $data['res_file'], "{$data['backupdir']}/{$data['dir_name']}/flist.txt"); |
@@ -389,12 +391,12 @@ discard block |
||
389 | 391 | Util::mwexec("du /storage/*/{$id} -d 0 2> /dev/null | /bin/busybox awk '{print $2}'", $out); |
390 | 392 | if(($out[0] ?? false) && file_exists($out[0])){ |
391 | 393 | $src_file = $out[0]; |
392 | - }else{ |
|
394 | + } else{ |
|
393 | 395 | $src_file = "{$result_dir}{$filename}"; |
394 | 396 | } |
395 | 397 | Util::mwexec("/bin/cp '{$src_file}' '{$filename}'", $arr_out); |
396 | 398 | Util::mwexec("/bin/umount $arh"); |
397 | - }else { |
|
399 | + } else { |
|
398 | 400 | Util::mwexec("7za e -y -r -spf {$arh} {$filename}"); |
399 | 401 | if(!file_exists($filename)){ |
400 | 402 | $command_status = Util::mwexec("7za l {$arh} | grep '".basename($filename)."' | /bin/busybox awk '{print $6}'", $out); |
@@ -448,7 +450,7 @@ discard block |
||
448 | 450 | $filename_data = trim($lines[$this->progress]); |
449 | 451 | if(strpos($filename_data,':')===false){ |
450 | 452 | $filename = $filename_data; |
451 | - }else{ |
|
453 | + } else{ |
|
452 | 454 | $filename = (explode(':', $filename_data))[1]; |
453 | 455 | } |
454 | 456 | if(is_dir($filename) === FALSE){ |
@@ -550,7 +552,7 @@ discard block |
||
550 | 552 | if($total === 0 ){ |
551 | 553 | $total = (count($data)>1)?trim($data[1])*1:0; |
552 | 554 | } |
553 | - }else{ |
|
555 | + } else{ |
|
554 | 556 | $progress_recover = ''; |
555 | 557 | } |
556 | 558 | |
@@ -595,7 +597,7 @@ discard block |
||
595 | 597 | if(!$disk_mounted){ |
596 | 598 | if($res->ftp_sftp_mode === '1'){ |
597 | 599 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
598 | - }else{ |
|
600 | + } else{ |
|
599 | 601 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
600 | 602 | } |
601 | 603 | } |
@@ -818,7 +820,7 @@ discard block |
||
818 | 820 | if(strpos($filename_data,':')===false){ |
819 | 821 | $section = ''; // Этот файл будет восстановленр в любом случае. |
820 | 822 | $filename = $filename_data; |
821 | - }else{ |
|
823 | + } else{ |
|
822 | 824 | $tmp_data = explode(':', $filename_data); |
823 | 825 | $section = $tmp_data[0] ?? ''; |
824 | 826 | $filename = $tmp_data[1] ?? ''; |
@@ -833,7 +835,7 @@ discard block |
||
833 | 835 | // Если секция указана, и она не определена в массиве опций, |
834 | 836 | // то не восстанавливаем файл. |
835 | 837 | unset($filename); |
836 | - }else{ |
|
838 | + } else{ |
|
837 | 839 | $this->extract_file($filename); |
838 | 840 | } |
839 | 841 | if($this->progress % 10 === 0){ |
@@ -875,7 +877,7 @@ discard block |
||
875 | 877 | if(count($arr_time)!==2){ |
876 | 878 | $h = '*'; |
877 | 879 | $m = '*'; |
878 | - }else{ |
|
880 | + } else{ |
|
879 | 881 | $h = $arr_time[0]; |
880 | 882 | if($h === '0'){ |
881 | 883 | $h = '*'; |
@@ -910,7 +912,7 @@ discard block |
||
910 | 912 | Util::mwexec_commands($queue_commands); |
911 | 913 | if(count($queue_commands) === 0){ |
912 | 914 | $result['result'] = 'Error'; |
913 | - }else{ |
|
915 | + } else{ |
|
914 | 916 | $result['result'] = 'Success'; |
915 | 917 | } |
916 | 918 | |
@@ -936,7 +938,7 @@ discard block |
||
936 | 938 | if(!$disk_mounted){ |
937 | 939 | if($res->ftp_sftp_mode === '1'){ |
938 | 940 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
939 | - }else{ |
|
941 | + } else{ |
|
940 | 942 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
941 | 943 | } |
942 | 944 | } |
@@ -72,7 +72,7 @@ discard block |
||
72 | 72 | 'backup-sound-files'=> '1' |
73 | 73 | ]; |
74 | 74 | } |
75 | - if(!file_exists($this->config_file) && FALSE === @file_put_contents($this->config_file, json_encode($this->options), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)){ |
|
75 | + if(!file_exists($this->config_file) && false === @file_put_contents($this->config_file, json_encode($this->options), JSON_PRETTY_PRINT | JSON_UNESCAPED_SLASHES)){ |
|
76 | 76 | Util::sys_log_msg('Backup', 'Failed create file '.$this->config_file); |
77 | 77 | } |
78 | 78 | } |
@@ -171,7 +171,7 @@ discard block |
||
171 | 171 | $result_size = $result_size < 1?1:round($result_size); |
172 | 172 | $tmp_name = $this->dirs['tmp'].'/'.Util::generateRandomString(); |
173 | 173 | // Создаем образ файловой системы. |
174 | - $res = Util::mwexec("/bin/dd if=/dev/zero of={$tmp_name} bs=1 count=0 seek={$result_size}M"); |
|
174 | + $res = Util::mwexec("/bin/dd if=/dev/zero of={$tmp_name} bs=1 count=0 seek={$result_size}m"); |
|
175 | 175 | if ($res !== 0) { |
176 | 176 | Util::sys_log_msg('Backup', 'Error creating img file...'); |
177 | 177 | } |
@@ -290,7 +290,7 @@ discard block |
||
290 | 290 | } |
291 | 291 | } |
292 | 292 | $out = implode(' ', $arr_out); |
293 | - return (strpos($out, 'ERROR') === FALSE); |
|
293 | + return (strpos($out, 'ERROR') === false); |
|
294 | 294 | } |
295 | 295 | |
296 | 296 | /** |
@@ -439,7 +439,7 @@ discard block |
||
439 | 439 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
440 | 440 | } |
441 | 441 | $lines = file($this->file_list); |
442 | - if($lines === FALSE){ |
|
442 | + if($lines === false){ |
|
443 | 443 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
444 | 444 | } |
445 | 445 | $count_files = count($lines); |
@@ -451,7 +451,7 @@ discard block |
||
451 | 451 | }else{ |
452 | 452 | $filename = (explode(':', $filename_data))[1]; |
453 | 453 | } |
454 | - if(is_dir($filename) === FALSE){ |
|
454 | + if(is_dir($filename) === false){ |
|
455 | 455 | $this->add_file_to_arhive($filename); |
456 | 456 | } |
457 | 457 | |
@@ -796,7 +796,7 @@ discard block |
||
796 | 796 | return ['result' => 'ERROR', 'message' => 'File list not found.']; |
797 | 797 | } |
798 | 798 | $lines = file($this->file_list); |
799 | - if($lines === FALSE){ |
|
799 | + if($lines === false){ |
|
800 | 800 | return ['result' => 'ERROR', 'message' => 'File list not read.']; |
801 | 801 | } |
802 | 802 |
@@ -12,8 +12,8 @@ |
||
12 | 12 | $network = new Network(); |
13 | 13 | $action = trim($argv[1]); |
14 | 14 | |
15 | -if($action === 'deconfig'){ |
|
15 | +if ($action === 'deconfig') { |
|
16 | 16 | $network->udhcpc_configure_deconfig(); |
17 | -}elseif( 'bound' === $action || 'renew' === $action){ |
|
17 | +}elseif ('bound' === $action || 'renew' === $action) { |
|
18 | 18 | $network->udhcpc_configure_renew_bound(); |
19 | 19 | } |
@@ -14,6 +14,6 @@ |
||
14 | 14 | |
15 | 15 | if($action === 'deconfig'){ |
16 | 16 | $network->udhcpc_configure_deconfig(); |
17 | -}elseif( 'bound' === $action || 'renew' === $action){ |
|
17 | +} elseif( 'bound' === $action || 'renew' === $action){ |
|
18 | 18 | $network->udhcpc_configure_renew_bound(); |
19 | 19 | } |
@@ -8,8 +8,8 @@ |
||
8 | 8 | |
9 | 9 | require_once 'globals.php'; |
10 | 10 | |
11 | -$id = trim($argv[1]); |
|
12 | -if(empty($id)){ |
|
11 | +$id = trim($argv[1]); |
|
12 | +if (empty($id)) { |
|
13 | 13 | exit; |
14 | 14 | } |
15 | 15 |
@@ -8,47 +8,47 @@ discard block |
||
8 | 8 | |
9 | 9 | require_once 'globals.php'; |
10 | 10 | |
11 | -if(count($argv)<3) { |
|
11 | +if (count($argv) < 3) { |
|
12 | 12 | exit; |
13 | 13 | } |
14 | 14 | |
15 | 15 | $id = trim($argv[1]); |
16 | 16 | $command = trim($argv[2]); |
17 | -if(empty($id)){ |
|
17 | +if (empty($id)) { |
|
18 | 18 | exit; |
19 | 19 | } |
20 | 20 | |
21 | -if('none' !== $id ){ |
|
21 | +if ('none' !== $id) { |
|
22 | 22 | $b = new Backup($id); |
23 | 23 | $b->create_arhive(); |
24 | -}elseif(count($argv)===4){ |
|
24 | +}elseif (count($argv) === 4) { |
|
25 | 25 | $PID = Util::get_pid_process("{$argv[1]} {$argv[2]} {$argv[3]}", ''.getmypid().' '); |
26 | - if(empty($PID)){ |
|
26 | + if (empty($PID)) { |
|
27 | 27 | // Другого процесса с аналогичными установками не запущено. |
28 | 28 | /** @var Models\BackupRules $res */ |
29 | 29 | $res = Models\BackupRules::findFirst("id='{$argv[3]}'"); |
30 | - if($res && Util::is_json($res->what_backup)){ |
|
30 | + if ($res && Util::is_json($res->what_backup)) { |
|
31 | 31 | $backup_dir = '/storage/'.$res->ftp_host.'.'.$res->ftp_port; |
32 | 32 | $disk_mounted = Storage::is_storage_disk_mounted("$backup_dir "); |
33 | - if(!$disk_mounted){ |
|
34 | - if($res->ftp_sftp_mode === '1'){ |
|
33 | + if (!$disk_mounted) { |
|
34 | + if ($res->ftp_sftp_mode === '1') { |
|
35 | 35 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
36 | - }else{ |
|
36 | + } else { |
|
37 | 37 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
38 | 38 | } |
39 | 39 | } |
40 | - if(!$disk_mounted){ |
|
40 | + if (!$disk_mounted) { |
|
41 | 41 | Util::sys_log_msg('Backup', 'Failed to mount backup disk...'); |
42 | 42 | exit; |
43 | 43 | } |
44 | 44 | |
45 | 45 | // Удаляем старые резервные копии, если необходимо. |
46 | - if($res->keep_older_versions > 0){ |
|
46 | + if ($res->keep_older_versions > 0) { |
|
47 | 47 | $out = []; |
48 | 48 | Util::mwexec("find {$backup_dir} -mindepth 1 -type d | sort", $out); |
49 | - if(count($out)>=$res->keep_older_versions){ |
|
49 | + if (count($out) >= $res->keep_older_versions) { |
|
50 | 50 | $count_dir = count($out) - $res->keep_older_versions; |
51 | - for ($count_dir; $count_dir>=0; $count_dir--){ |
|
51 | + for ($count_dir; $count_dir >= 0; $count_dir--) { |
|
52 | 52 | Util::mwexec("rm -rf {$out[$count_dir]}"); |
53 | 53 | } |
54 | 54 | } |
@@ -58,7 +58,7 @@ discard block |
||
58 | 58 | $id = 'backup_'.time(); |
59 | 59 | $options = json_decode($res->what_backup, true); |
60 | 60 | $options['backup'] = $backup_dir; |
61 | - if($res->ftp_sftp_mode !== '1') { |
|
61 | + if ($res->ftp_sftp_mode !== '1') { |
|
62 | 62 | $options['type'] = 'zip'; |
63 | 63 | } |
64 | 64 | $b = new Backup($id, $options); |
@@ -21,7 +21,7 @@ discard block |
||
21 | 21 | if('none' !== $id ){ |
22 | 22 | $b = new Backup($id); |
23 | 23 | $b->create_arhive(); |
24 | -}elseif(count($argv)===4){ |
|
24 | +} elseif(count($argv)===4){ |
|
25 | 25 | $PID = Util::get_pid_process("{$argv[1]} {$argv[2]} {$argv[3]}", ''.getmypid().' '); |
26 | 26 | if(empty($PID)){ |
27 | 27 | // Другого процесса с аналогичными установками не запущено. |
@@ -33,7 +33,7 @@ discard block |
||
33 | 33 | if(!$disk_mounted){ |
34 | 34 | if($res->ftp_sftp_mode === '1'){ |
35 | 35 | $disk_mounted = Storage::mount_sftp_disk($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
36 | - }else{ |
|
36 | + } else{ |
|
37 | 37 | $disk_mounted = Storage::mount_ftp($res->ftp_host, $res->ftp_port, $res->ftp_username, $res->ftp_secret, $res->ftp_path, $backup_dir); |
38 | 38 | } |
39 | 39 | } |
@@ -16,7 +16,7 @@ discard block |
||
16 | 16 | * worker_ami_listener constructor. |
17 | 17 | * @throws Exception |
18 | 18 | */ |
19 | - function __construct(){ |
|
19 | + function __construct() { |
|
20 | 20 | $this->client = new BeanstalkClient('call_events'); |
21 | 21 | $this->am = Util::get_am(); |
22 | 22 | $this->set_filter(); |
@@ -26,27 +26,27 @@ discard block |
||
26 | 26 | * Отправка данных на сервер очередей. |
27 | 27 | * @param string $result - данные в ормате json для отправки. |
28 | 28 | */ |
29 | - private function Action_SendToBeanstalk($result){ |
|
29 | + private function Action_SendToBeanstalk($result) { |
|
30 | 30 | |
31 | - $this->message_is_sent = false; $error =''; |
|
31 | + $this->message_is_sent = false; $error = ''; |
|
32 | 32 | for ($i = 1; $i <= 10; $i++) { |
33 | - try{ |
|
33 | + try { |
|
34 | 34 | $result_send = $this->client->publish($result); |
35 | - if($result_send == false){ |
|
35 | + if ($result_send == false) { |
|
36 | 36 | $this->client->reconnect(); |
37 | 37 | } |
38 | 38 | $this->message_is_sent = ($result_send !== false); |
39 | - if($this->message_is_sent == true){ |
|
39 | + if ($this->message_is_sent == true) { |
|
40 | 40 | // Проверка |
41 | 41 | break; |
42 | 42 | } |
43 | - }catch (Exception $e){ |
|
43 | + } catch (Exception $e) { |
|
44 | 44 | $this->client = new BeanstalkClient('call_events'); |
45 | 45 | $error = $e->getMessage(); |
46 | 46 | } |
47 | 47 | } |
48 | 48 | |
49 | - if($this->message_is_sent == false){ |
|
49 | + if ($this->message_is_sent == false) { |
|
50 | 50 | Util::sys_log_msg('CDR_AMI_Connector', "Error send data to queue. ".$error); |
51 | 51 | } |
52 | 52 | // Логируем оповещение. |
@@ -57,13 +57,13 @@ discard block |
||
57 | 57 | * Функция обработки оповещений. |
58 | 58 | * @param $parameters |
59 | 59 | */ |
60 | - public function callback($parameters){ |
|
61 | - if('CdrConnectorPing' == $parameters['UserEvent']){ |
|
60 | + public function callback($parameters) { |
|
61 | + if ('CdrConnectorPing' == $parameters['UserEvent']) { |
|
62 | 62 | usleep(50000); |
63 | 63 | $this->am->UserEvent("CdrConnectorPong", []); |
64 | 64 | return; |
65 | 65 | } |
66 | - if('CdrConnector' != $parameters['UserEvent']){ |
|
66 | + if ('CdrConnector' != $parameters['UserEvent']) { |
|
67 | 67 | return; |
68 | 68 | } |
69 | 69 | |
@@ -74,11 +74,11 @@ discard block |
||
74 | 74 | /** |
75 | 75 | * Старт работы листнера. |
76 | 76 | */ |
77 | - public function start(){ |
|
77 | + public function start() { |
|
78 | 78 | $this->am->add_event_handler("userevent", [$this, "callback"]); |
79 | 79 | while (true) { |
80 | 80 | $result = $this->am->wait_user_event(true); |
81 | - if($result == false){ |
|
81 | + if ($result == false) { |
|
82 | 82 | // Нужен реконнект. |
83 | 83 | usleep(100000); |
84 | 84 | $this->am = Util::get_am(); |
@@ -91,17 +91,17 @@ discard block |
||
91 | 91 | * Установка фильтра |
92 | 92 | * @return array |
93 | 93 | */ |
94 | - private function set_filter(){ |
|
95 | - $params = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent']; |
|
96 | - $res = $this->am->send_request_timeout('Filter', $params); |
|
94 | + private function set_filter() { |
|
95 | + $params = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent']; |
|
96 | + $res = $this->am->send_request_timeout('Filter', $params); |
|
97 | 97 | return $res; |
98 | 98 | } |
99 | 99 | } |
100 | 100 | |
101 | -if(count($argv)>1 && $argv[1] == 'start') { |
|
102 | - try{ |
|
101 | +if (count($argv) > 1 && $argv[1] == 'start') { |
|
102 | + try { |
|
103 | 103 | $listener = new worker_ami_listener(); |
104 | - }catch (Exception $e) { |
|
104 | + } catch (Exception $e) { |
|
105 | 105 | Util::sys_log_msg("AMI_WORKER_EXCEPTION", $e->getMessage()); |
106 | 106 | } |
107 | 107 | $listener->start(); |
@@ -7,7 +7,8 @@ discard block |
||
7 | 7 | */ |
8 | 8 | require_once 'globals.php'; |
9 | 9 | |
10 | -class worker_ami_listener { |
|
10 | +class worker_ami_listener |
|
11 | +{ |
|
11 | 12 | private $client; |
12 | 13 | private $am; |
13 | 14 | private $message_is_sent; |
@@ -16,7 +17,8 @@ discard block |
||
16 | 17 | * worker_ami_listener constructor. |
17 | 18 | * @throws Exception |
18 | 19 | */ |
19 | - function __construct(){ |
|
20 | + function __construct() |
|
21 | + { |
|
20 | 22 | $this->client = new BeanstalkClient('call_events'); |
21 | 23 | $this->am = Util::get_am(); |
22 | 24 | $this->set_filter(); |
@@ -26,7 +28,8 @@ discard block |
||
26 | 28 | * Отправка данных на сервер очередей. |
27 | 29 | * @param string $result - данные в ормате json для отправки. |
28 | 30 | */ |
29 | - private function Action_SendToBeanstalk($result){ |
|
31 | + private function Action_SendToBeanstalk($result) |
|
32 | + { |
|
30 | 33 | |
31 | 34 | $this->message_is_sent = false; $error =''; |
32 | 35 | for ($i = 1; $i <= 10; $i++) { |
@@ -40,7 +43,7 @@ discard block |
||
40 | 43 | // Проверка |
41 | 44 | break; |
42 | 45 | } |
43 | - }catch (Exception $e){ |
|
46 | + } catch (Exception $e){ |
|
44 | 47 | $this->client = new BeanstalkClient('call_events'); |
45 | 48 | $error = $e->getMessage(); |
46 | 49 | } |
@@ -57,7 +60,8 @@ discard block |
||
57 | 60 | * Функция обработки оповещений. |
58 | 61 | * @param $parameters |
59 | 62 | */ |
60 | - public function callback($parameters){ |
|
63 | + public function callback($parameters) |
|
64 | + { |
|
61 | 65 | if('CdrConnectorPing' == $parameters['UserEvent']){ |
62 | 66 | usleep(50000); |
63 | 67 | $this->am->UserEvent("CdrConnectorPong", []); |
@@ -74,7 +78,8 @@ discard block |
||
74 | 78 | /** |
75 | 79 | * Старт работы листнера. |
76 | 80 | */ |
77 | - public function start(){ |
|
81 | + public function start() |
|
82 | + { |
|
78 | 83 | $this->am->add_event_handler("userevent", [$this, "callback"]); |
79 | 84 | while (true) { |
80 | 85 | $result = $this->am->wait_user_event(true); |
@@ -91,7 +96,8 @@ discard block |
||
91 | 96 | * Установка фильтра |
92 | 97 | * @return array |
93 | 98 | */ |
94 | - private function set_filter(){ |
|
99 | + private function set_filter() |
|
100 | + { |
|
95 | 101 | $params = ['Operation'=>'Add', 'Filter' => 'Event: UserEvent']; |
96 | 102 | $res = $this->am->send_request_timeout('Filter', $params); |
97 | 103 | return $res; |
@@ -101,7 +107,7 @@ discard block |
||
101 | 107 | if(count($argv)>1 && $argv[1] == 'start') { |
102 | 108 | try{ |
103 | 109 | $listener = new worker_ami_listener(); |
104 | - }catch (Exception $e) { |
|
110 | + } catch (Exception $e) { |
|
105 | 111 | Util::sys_log_msg("AMI_WORKER_EXCEPTION", $e->getMessage()); |
106 | 112 | } |
107 | 113 | $listener->start(); |
@@ -12,54 +12,54 @@ discard block |
||
12 | 12 | * Обработчик пинга. |
13 | 13 | * @param BeanstalkClient $message |
14 | 14 | */ |
15 | -$ping_worker = function ($message) { |
|
15 | +$ping_worker = function($message) { |
|
16 | 16 | $message->reply(json_encode($message->getBody().':pong')); |
17 | 17 | }; |
18 | 18 | |
19 | -$notify_by_email = function ($message){ |
|
19 | +$notify_by_email = function($message) { |
|
20 | 20 | $config = new \Config(); |
21 | 21 | $settings = $config->get_general_settings(); |
22 | 22 | |
23 | 23 | /** @var BeanstalkClient $message */ |
24 | 24 | $data = json_decode($message->getBody(), true); |
25 | - if( isset($data['NOANSWER']) ){ |
|
25 | + if (isset($data['NOANSWER'])) { |
|
26 | 26 | // Вызов клиента отвечен одним из сотрудников. Но не все участники подняли трубку. |
27 | 27 | return; |
28 | 28 | } |
29 | 29 | $template_body = $settings['MailTplMissedCallBody']; |
30 | 30 | $template_Footer = $settings['MailTplMissedCallFooter']; |
31 | 31 | $emails = []; |
32 | - foreach ($data as $call){ |
|
32 | + foreach ($data as $call) { |
|
33 | 33 | /** |
34 | 34 | 'language' |
35 | 35 | 'is_internal' |
36 | 36 | */ |
37 | - if(!isset($emails[$call['email']])){ |
|
37 | + if (!isset($emails[$call['email']])) { |
|
38 | 38 | $emails[$call['email']] = ''; |
39 | 39 | } |
40 | 40 | |
41 | - if(empty($template_body)){ |
|
41 | + if (empty($template_body)) { |
|
42 | 42 | $email = Util::translate("You have missing call"); |
43 | - }else{ |
|
43 | + } else { |
|
44 | 44 | $email = str_replace("\n", "<br>", $template_body); |
45 | - $email = str_replace("NOTIFICATION_MISSEDCAUSE",'NOANSWER', $email); |
|
46 | - $email = str_replace("NOTIFICATION_CALLERID", $call['from_number'], $email); |
|
47 | - $email = str_replace("NOTIFICATION_TO", $call['to_number'], $email); |
|
48 | - $email = str_replace("NOTIFICATION_DURATION", $call['duration'], $email); |
|
49 | - $email = str_replace("NOTIFICATION_DATE", $call['start'], $email); |
|
45 | + $email = str_replace("NOTIFICATION_MISSEDCAUSE", 'NOANSWER', $email); |
|
46 | + $email = str_replace("NOTIFICATION_CALLERID", $call['from_number'], $email); |
|
47 | + $email = str_replace("NOTIFICATION_TO", $call['to_number'], $email); |
|
48 | + $email = str_replace("NOTIFICATION_DURATION", $call['duration'], $email); |
|
49 | + $email = str_replace("NOTIFICATION_DATE", $call['start'], $email); |
|
50 | 50 | } |
51 | - $emails[$call['email']] .= "$email <br> <hr> <br>"; |
|
51 | + $emails[$call['email']] .= "$email <br> <hr> <br>"; |
|
52 | 52 | } |
53 | 53 | |
54 | - if(isset($settings['MailSMTPSenderAddress']) && trim($settings['MailSMTPSenderAddress'])!=''){ |
|
54 | + if (isset($settings['MailSMTPSenderAddress']) && trim($settings['MailSMTPSenderAddress']) != '') { |
|
55 | 55 | $from_address = $settings['MailSMTPSenderAddress']; |
56 | - }else{ |
|
56 | + } else { |
|
57 | 57 | $from_address = $settings['MailSMTPUsername']; |
58 | 58 | } |
59 | 59 | |
60 | - foreach ($emails as $to => $text){ |
|
60 | + foreach ($emails as $to => $text) { |
|
61 | 61 | $subject = str_replace("MailSMTPSenderAddress", $from_address, $settings['MailTplMissedCallSubject']); |
62 | - if(empty($subject)){ |
|
62 | + if (empty($subject)) { |
|
63 | 63 | $subject = Util::translate("You have missing call"); |
64 | 64 | } |
65 | 65 | |
@@ -73,13 +73,13 @@ discard block |
||
73 | 73 | * Основной цикл демона. |
74 | 74 | */ |
75 | 75 | while (true) { |
76 | - try{ |
|
77 | - $client = new BeanstalkClient('notify_by_email'); |
|
78 | - $client->subscribe('notify_by_email', $notify_by_email ); |
|
79 | - $client->subscribe('ping_notify_by_email', $ping_worker); |
|
76 | + try { |
|
77 | + $client = new BeanstalkClient('notify_by_email'); |
|
78 | + $client->subscribe('notify_by_email', $notify_by_email); |
|
79 | + $client->subscribe('ping_notify_by_email', $ping_worker); |
|
80 | 80 | |
81 | 81 | $client->wait(); |
82 | - }catch (Exception $e){ |
|
82 | + } catch (Exception $e) { |
|
83 | 83 | sleep(1); |
84 | 84 | } |
85 | 85 | } |
86 | 86 | \ No newline at end of file |
@@ -12,11 +12,13 @@ discard block |
||
12 | 12 | * Обработчик пинга. |
13 | 13 | * @param BeanstalkClient $message |
14 | 14 | */ |
15 | -$ping_worker = function ($message) { |
|
15 | +$ping_worker = function ($message) |
|
16 | +{ |
|
16 | 17 | $message->reply(json_encode($message->getBody().':pong')); |
17 | 18 | }; |
18 | 19 | |
19 | -$notify_by_email = function ($message){ |
|
20 | +$notify_by_email = function ($message) |
|
21 | +{ |
|
20 | 22 | $config = new \Config(); |
21 | 23 | $settings = $config->get_general_settings(); |
22 | 24 | |
@@ -40,7 +42,7 @@ discard block |
||
40 | 42 | |
41 | 43 | if(empty($template_body)){ |
42 | 44 | $email = Util::translate("You have missing call"); |
43 | - }else{ |
|
45 | + } else{ |
|
44 | 46 | $email = str_replace("\n", "<br>", $template_body); |
45 | 47 | $email = str_replace("NOTIFICATION_MISSEDCAUSE",'NOANSWER', $email); |
46 | 48 | $email = str_replace("NOTIFICATION_CALLERID", $call['from_number'], $email); |
@@ -53,7 +55,7 @@ discard block |
||
53 | 55 | |
54 | 56 | if(isset($settings['MailSMTPSenderAddress']) && trim($settings['MailSMTPSenderAddress'])!=''){ |
55 | 57 | $from_address = $settings['MailSMTPSenderAddress']; |
56 | - }else{ |
|
58 | + } else{ |
|
57 | 59 | $from_address = $settings['MailSMTPUsername']; |
58 | 60 | } |
59 | 61 | |
@@ -79,7 +81,7 @@ discard block |
||
79 | 81 | $client->subscribe('ping_notify_by_email', $ping_worker); |
80 | 82 | |
81 | 83 | $client->wait(); |
82 | - }catch (Exception $e){ |
|
84 | + } catch (Exception $e){ |
|
83 | 85 | sleep(1); |
84 | 86 | } |
85 | 87 | } |
86 | 88 | \ No newline at end of file |
@@ -15,7 +15,7 @@ discard block |
||
15 | 15 | * @param $data |
16 | 16 | */ |
17 | 17 | function Action_dial($data){ |
18 | - Cdr::insert_data_to_db_m($data); |
|
18 | + Cdr::insert_data_to_db_m($data); |
|
19 | 19 | Action_app_end($data); |
20 | 20 | } |
21 | 21 | |
@@ -744,11 +744,11 @@ discard block |
||
744 | 744 | * @param $data |
745 | 745 | */ |
746 | 746 | function Action_unpark_call($data){ |
747 | - $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $data['UNIQUEID']); |
|
748 | - Cdr::insert_data_to_db_m($data); |
|
749 | - if( is_array($data['data_parking']) ){ |
|
750 | - Cdr::insert_data_to_db_m($data['data_parking']); |
|
751 | - } |
|
747 | + $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $data['UNIQUEID']); |
|
748 | + Cdr::insert_data_to_db_m($data); |
|
749 | + if( is_array($data['data_parking']) ){ |
|
750 | + Cdr::insert_data_to_db_m($data['data_parking']); |
|
751 | + } |
|
752 | 752 | $filter = [ |
753 | 753 | "linkedid=:linkedid: AND src_chan=:src_chan:", |
754 | 754 | 'bind' => [ |
@@ -897,10 +897,10 @@ discard block |
||
897 | 897 | */ |
898 | 898 | $call_events = function ($message) { |
899 | 899 | $data = json_decode($message->getBody(), true); |
900 | - $func_name = 'Action_'.$data['action']; |
|
901 | - if( function_exists($func_name) ){ |
|
902 | - $func_name($data); |
|
903 | - } |
|
900 | + $func_name = 'Action_'.$data['action']; |
|
901 | + if( function_exists($func_name) ){ |
|
902 | + $func_name($data); |
|
903 | + } |
|
904 | 904 | $message->reply(json_encode(true)); |
905 | 905 | }; |
906 | 906 | |
@@ -909,7 +909,7 @@ discard block |
||
909 | 909 | * @param array | BeanstalkClient $message |
910 | 910 | */ |
911 | 911 | $ping_worker = function ($message) { |
912 | - $message->reply(json_encode($message->getBody().':pong')); |
|
912 | + $message->reply(json_encode($message->getBody().':pong')); |
|
913 | 913 | |
914 | 914 | set_global_settings(); |
915 | 915 | }; |
@@ -986,7 +986,7 @@ discard block |
||
986 | 986 | */ |
987 | 987 | while (true) { |
988 | 988 | set_global_settings(); |
989 | - try{ |
|
989 | + try{ |
|
990 | 990 | $client = new BeanstalkClient('call_events'); |
991 | 991 | $client->subscribe('call_events', $call_events); |
992 | 992 | $client->subscribe('select_cdr', $select_cdr ); |
@@ -996,8 +996,8 @@ discard block |
||
996 | 996 | |
997 | 997 | $client->wait(); |
998 | 998 | }catch (Exception $e){ |
999 | - $errorLogger = $g['error_logger']; |
|
1000 | - $errorLogger->captureException($e); |
|
1001 | - sleep(1); |
|
999 | + $errorLogger = $g['error_logger']; |
|
1000 | + $errorLogger->captureException($e); |
|
1001 | + sleep(1); |
|
1002 | 1002 | } |
1003 | 1003 | } |
1004 | 1004 | \ No newline at end of file |
@@ -14,7 +14,7 @@ discard block |
||
14 | 14 | * Обработка события начала телефонного звонка. |
15 | 15 | * @param $data |
16 | 16 | */ |
17 | -function Action_dial($data){ |
|
17 | +function Action_dial($data) { |
|
18 | 18 | Cdr::insert_data_to_db_m($data); |
19 | 19 | Action_app_end($data); |
20 | 20 | } |
@@ -23,14 +23,14 @@ discard block |
||
23 | 23 | * Обработка события создания канала - пары, при начале телефонного звонка. |
24 | 24 | * @param $data |
25 | 25 | */ |
26 | -function Action_dial_create_chan($data){ |
|
26 | +function Action_dial_create_chan($data) { |
|
27 | 27 | |
28 | - if( isset($data['org_id']) ) { |
|
28 | + if (isset($data['org_id'])) { |
|
29 | 29 | // Вероятно необходимо переопределить искать по двум ID. |
30 | 30 | // Применимо только для Originate, когда в качестве звонящего используем два канала |
31 | 31 | // мобильный и внутренний номер. |
32 | - $filter = ['(UNIQUEID=:UNIQUEID: OR UNIQUEID=:org_id:) AND endtime IS NULL', 'bind' => ['UNIQUEID' => $data['UNIQUEID'], 'org_id' => $data['org_id'],]]; |
|
33 | - }else{ |
|
32 | + $filter = ['(UNIQUEID=:UNIQUEID: OR UNIQUEID=:org_id:) AND endtime IS NULL', 'bind' => ['UNIQUEID' => $data['UNIQUEID'], 'org_id' => $data['org_id'], ]]; |
|
33 | + } else { |
|
34 | 34 | $filter = [ |
35 | 35 | 'UNIQUEID=:UNIQUEID: AND answer IS NULL AND endtime IS NULL', |
36 | 36 | 'bind' => [ |
@@ -44,23 +44,23 @@ discard block |
||
44 | 44 | /** @var CallDetailRecordsTmp $m_data */ |
45 | 45 | /** @var CallDetailRecordsTmp $row */ |
46 | 46 | $m_data = CallDetailRecordsTmp::find($filter); |
47 | - foreach ($m_data as $row){ |
|
48 | - if(!is_object($row)){ |
|
47 | + foreach ($m_data as $row) { |
|
48 | + if (!is_object($row)) { |
|
49 | 49 | continue; |
50 | 50 | } |
51 | 51 | /// |
52 | 52 | // Проверим, если более одного канала SIP/256 при входящем. |
53 | - $column_chan_name = ('ORIGINATE' === $row->dialstatus)?'src_chan':'dst_chan'; |
|
53 | + $column_chan_name = ('ORIGINATE' === $row->dialstatus) ? 'src_chan' : 'dst_chan'; |
|
54 | 54 | |
55 | - if( !empty($row->$column_chan_name) && $data['dst_chan'] !== $row->$column_chan_name){ |
|
56 | - if($row_create){ |
|
55 | + if (!empty($row->$column_chan_name) && $data['dst_chan'] !== $row->$column_chan_name) { |
|
56 | + if ($row_create) { |
|
57 | 57 | continue; |
58 | 58 | } |
59 | 59 | // Необходимо дублировать строку звонка. |
60 | 60 | $new_row = new CallDetailRecordsTmp(); |
61 | 61 | $f_list = $row->toArray(); |
62 | - foreach ($f_list as $attribute => $value){ |
|
63 | - if($attribute === 'id'){ |
|
62 | + foreach ($f_list as $attribute => $value) { |
|
63 | + if ($attribute === 'id') { |
|
64 | 64 | continue; |
65 | 65 | } |
66 | 66 | $new_row->writeAttribute($attribute, $value); |
@@ -74,29 +74,29 @@ discard block |
||
74 | 74 | // конец проверки |
75 | 75 | /// |
76 | 76 | |
77 | - if($row->dialstatus === 'ORIGINATE'){ |
|
77 | + if ($row->dialstatus === 'ORIGINATE') { |
|
78 | 78 | $account_col = 'from_account'; |
79 | 79 | // При оригинации меняется местами srs_chan в поле dst_chan. |
80 | - $row->writeAttribute('src_chan', $data['dst_chan']); |
|
81 | - }else{ |
|
82 | - if(!$rec_start){ |
|
83 | - $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $row->UNIQUEID, null, $row->recordingfile); |
|
80 | + $row->writeAttribute('src_chan', $data['dst_chan']); |
|
81 | + } else { |
|
82 | + if (!$rec_start) { |
|
83 | + $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $row->UNIQUEID, null, $row->recordingfile); |
|
84 | 84 | $row->writeAttribute('recordingfile', $data['recordingfile']); |
85 | 85 | $rec_start = true; |
86 | 86 | } |
87 | 87 | $account_col = 'to_account'; |
88 | - $row->writeAttribute('dst_chan', $data['dst_chan']); |
|
88 | + $row->writeAttribute('dst_chan', $data['dst_chan']); |
|
89 | 89 | } |
90 | 90 | |
91 | - if( isset($data['to_account']) && !empty($data['to_account']) ){ |
|
91 | + if (isset($data['to_account']) && !empty($data['to_account'])) { |
|
92 | 92 | $row->writeAttribute($account_col, $data['to_account']); |
93 | 93 | } |
94 | - if( isset($data['dst_call_id']) && !empty($data['dst_call_id']) ){ |
|
94 | + if (isset($data['dst_call_id']) && !empty($data['dst_call_id'])) { |
|
95 | 95 | $row->writeAttribute('dst_call_id', $data['dst_call_id']); |
96 | 96 | } |
97 | 97 | $res = $row->save(); |
98 | - if(!$res) { |
|
99 | - Util::sys_log_msg('Action_dial_create_chan', implode(' ',$row->getMessages())); |
|
98 | + if (!$res) { |
|
99 | + Util::sys_log_msg('Action_dial_create_chan', implode(' ', $row->getMessages())); |
|
100 | 100 | } |
101 | 101 | } |
102 | 102 | } |
@@ -105,18 +105,18 @@ discard block |
||
105 | 105 | * Обработка события ответа на звонок. Соединение абонентов. |
106 | 106 | * @param $data |
107 | 107 | */ |
108 | -function Action_dial_answer($data){ |
|
108 | +function Action_dial_answer($data) { |
|
109 | 109 | $pickupexten = Config::get_pickupexten(); |
110 | - if(trim($data['dnid']) === $pickupexten){ |
|
110 | + if (trim($data['dnid']) === $pickupexten) { |
|
111 | 111 | // Pickup / перехват вызова. |
112 | 112 | // Событие возникает, когда мы пытаемся перехватить вызов на соседний телефон. |
113 | 113 | $filter = [ |
114 | 114 | 'UNIQUEID=:UNIQUEID:', |
115 | - 'bind' => ['UNIQUEID' => $data['old_id'],] |
|
115 | + 'bind' => ['UNIQUEID' => $data['old_id'], ] |
|
116 | 116 | ]; |
117 | 117 | /** @var CallDetailRecordsTmp $m_data */ |
118 | 118 | $m_data = CallDetailRecordsTmp::find($filter); |
119 | - if(count($m_data->toArray()) === 1){ |
|
119 | + if (count($m_data->toArray()) === 1) { |
|
120 | 120 | /** @var CallDetailRecordsTmp $m_row_data */ |
121 | 121 | $m_row_data = $m_data[0]; |
122 | 122 | $new_data = $m_row_data->toArray(); |
@@ -135,10 +135,10 @@ discard block |
||
135 | 135 | $new_data['action'] = 'answer_pickup_create_cdr'; |
136 | 136 | $am = Util::get_am('off'); |
137 | 137 | $AgiData = base64_encode(json_encode($new_data)); |
138 | - $am->UserEvent('CdrConnector', [ 'AgiData' => $AgiData]); |
|
138 | + $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
|
139 | 139 | } |
140 | - }else{ |
|
141 | - if(!empty($data['ENDCALLONANSWER'])){ |
|
140 | + } else { |
|
141 | + if (!empty($data['ENDCALLONANSWER'])) { |
|
142 | 142 | // Переменная ENDCALLONANSWER устанавливается при начале работы умной маршуртизации. |
143 | 143 | // Как только произошел ответ на вызов, отметим вызов на приложение как завершенный. |
144 | 144 | $filter = [ |
@@ -151,17 +151,17 @@ discard block |
||
151 | 151 | /** @var CallDetailRecordsTmp $m_data */ |
152 | 152 | /** @var CallDetailRecordsTmp $row */ |
153 | 153 | $m_data = CallDetailRecordsTmp::find($filter); |
154 | - foreach ($m_data as $row){ |
|
154 | + foreach ($m_data as $row) { |
|
155 | 155 | $row->writeAttribute('endtime', $data['answer']); |
156 | - $row->writeAttribute('is_app', 1); |
|
156 | + $row->writeAttribute('is_app', 1); |
|
157 | 157 | $res = $row->save(); |
158 | - if(!$res) { |
|
159 | - Util::sys_log_msg('ENDCALLONANSWER', implode(' ',$row->getMessages())); |
|
158 | + if (!$res) { |
|
159 | + Util::sys_log_msg('ENDCALLONANSWER', implode(' ', $row->getMessages())); |
|
160 | 160 | } |
161 | 161 | } |
162 | 162 | } |
163 | 163 | |
164 | - if( isset($data['org_id']) ){ |
|
164 | + if (isset($data['org_id'])) { |
|
165 | 165 | // Вероятно необходимо переопределить искать по двум ID. |
166 | 166 | // Применимо только для Originate, когда в качестве звонящего используем два канала |
167 | 167 | // мобильный и внутренний номер. |
@@ -172,7 +172,7 @@ discard block |
||
172 | 172 | 'org_id' => $data['org_id'], |
173 | 173 | ] |
174 | 174 | ]; |
175 | - }else{ |
|
175 | + } else { |
|
176 | 176 | $filter = [ |
177 | 177 | '(UNIQUEID=:UNIQUEID: OR UNIQUEID=:UNIQUEID_CHAN:) AND answer IS NULL AND endtime IS NULL', |
178 | 178 | 'bind' => [ |
@@ -183,9 +183,9 @@ discard block |
||
183 | 183 | } |
184 | 184 | // Отмечаем вызов как отвеченный. |
185 | 185 | $m_data = CallDetailRecordsTmp::find($filter); |
186 | - foreach ($m_data as $row){ |
|
187 | - if($row->dialstatus === 'ORIGINATE'){ |
|
188 | - if($row->src_chan !== $data['agi_channel']){ |
|
186 | + foreach ($m_data as $row) { |
|
187 | + if ($row->dialstatus === 'ORIGINATE') { |
|
188 | + if ($row->src_chan !== $data['agi_channel']) { |
|
189 | 189 | // Ищем совпадающий канал |
190 | 190 | continue; |
191 | 191 | } |
@@ -199,8 +199,8 @@ discard block |
||
199 | 199 | ]; |
200 | 200 | $m_orgn_data = CallDetailRecordsTmp::find($filter); |
201 | 201 | /** @var CallDetailRecordsTmp $orgn_row */ |
202 | - foreach ($m_orgn_data as $orgn_row){ |
|
203 | - if(empty($orgn_row->endtime)){ |
|
202 | + foreach ($m_orgn_data as $orgn_row) { |
|
203 | + if (empty($orgn_row->endtime)) { |
|
204 | 204 | $orgn_row->writeAttribute('endtime', $data['answer']); |
205 | 205 | } |
206 | 206 | $orgn_row->writeAttribute('dst_chan', ''); |
@@ -213,12 +213,12 @@ discard block |
||
213 | 213 | $row->writeAttribute('UNIQUEID', $data['id']); |
214 | 214 | $row->save(); |
215 | 215 | break; |
216 | - }else{ |
|
216 | + } else { |
|
217 | 217 | $row->writeAttribute('answer', $data['answer']); |
218 | 218 | } |
219 | 219 | $res = $row->save(); |
220 | - if(!$res) { |
|
221 | - Util::sys_log_msg('Action_dial_answer', implode(' ',$row->getMessages())); |
|
220 | + if (!$res) { |
|
221 | + Util::sys_log_msg('Action_dial_answer', implode(' ', $row->getMessages())); |
|
222 | 222 | } |
223 | 223 | } |
224 | 224 | } |
@@ -229,7 +229,7 @@ discard block |
||
229 | 229 | * Завершение / уничтожение канала. |
230 | 230 | * @param $data |
231 | 231 | */ |
232 | -function Action_hangup_chan($data){ |
|
232 | +function Action_hangup_chan($data) { |
|
233 | 233 | $channels = []; |
234 | 234 | $transfer_calls = []; |
235 | 235 | $filter = [ |
@@ -243,34 +243,34 @@ discard block |
||
243 | 243 | /** @var CallDetailRecordsTmp $m_data */ |
244 | 244 | /** @var CallDetailRecordsTmp $row */ |
245 | 245 | $m_data = CallDetailRecordsTmp::find($filter); |
246 | - foreach ($m_data as $row){ |
|
247 | - if($row->transfer==1){ |
|
246 | + foreach ($m_data as $row) { |
|
247 | + if ($row->transfer == 1) { |
|
248 | 248 | $transfer_calls[] = $row->toArray(); |
249 | 249 | } |
250 | - if($row->dialstatus === 'ORIGINATE'){ |
|
251 | - $row->writeAttribute('dialstatus', ''); |
|
250 | + if ($row->dialstatus === 'ORIGINATE') { |
|
251 | + $row->writeAttribute('dialstatus', ''); |
|
252 | 252 | } |
253 | - $row->writeAttribute('endtime', $data['end']); |
|
253 | + $row->writeAttribute('endtime', $data['end']); |
|
254 | 254 | $row->writeAttribute('transfer', 0); |
255 | - if($data['dialstatus'] !== ''){ |
|
256 | - if($data['dialstatus'] === 'ORIGINATE'){ |
|
255 | + if ($data['dialstatus'] !== '') { |
|
256 | + if ($data['dialstatus'] === 'ORIGINATE') { |
|
257 | 257 | $row->writeAttribute('dst_chan', ''); |
258 | 258 | } |
259 | 259 | $row->writeAttribute('dialstatus', $data['dialstatus']); |
260 | 260 | } |
261 | 261 | $res = $row->update(); |
262 | - if(!$res) { |
|
263 | - Util::sys_log_msg('Action_hangup_chan', implode(' ',$row->getMessages())); |
|
262 | + if (!$res) { |
|
263 | + Util::sys_log_msg('Action_hangup_chan', implode(' ', $row->getMessages())); |
|
264 | 264 | } |
265 | 265 | |
266 | - if($row->src_chan !== $data['agi_channel']){ |
|
266 | + if ($row->src_chan !== $data['agi_channel']) { |
|
267 | 267 | $channels[] = [ |
268 | 268 | 'chan' => $row->src_chan, |
269 | 269 | 'did' => $row->did, |
270 | 270 | 'num' => $row->src_num, |
271 | 271 | 'out' => true |
272 | 272 | ]; |
273 | - }else{ |
|
273 | + } else { |
|
274 | 274 | $channels[] = [ |
275 | 275 | 'chan' => $row->dst_chan, |
276 | 276 | 'did' => $row->did, |
@@ -284,35 +284,35 @@ discard block |
||
284 | 284 | Action_CreateRowTransfer('hangup_chan', $data, $transfer_calls); |
285 | 285 | |
286 | 286 | $not_local = (stripos($data['agi_channel'], 'local/') === false); |
287 | - if($not_local === true && $data['OLD_LINKEDID'] === $data['linkedid']){ |
|
287 | + if ($not_local === true && $data['OLD_LINKEDID'] === $data['linkedid']) { |
|
288 | 288 | $am = Util::get_am('off'); |
289 | 289 | $active_chans = $am->GetChannels(false); |
290 | 290 | // TODO / Намек на SIP трансфер. |
291 | - foreach ($channels as $data_chan){ |
|
292 | - if(!in_array($data_chan['chan'], $active_chans, true)){ |
|
291 | + foreach ($channels as $data_chan) { |
|
292 | + if (!in_array($data_chan['chan'], $active_chans, true)) { |
|
293 | 293 | // Вызов уже завершен. Не интересно. |
294 | 294 | continue; |
295 | 295 | } |
296 | 296 | $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', NULL, false); |
297 | - if(!in_array($BRIDGEPEER, $active_chans, true)){ |
|
297 | + if (!in_array($BRIDGEPEER, $active_chans, true)) { |
|
298 | 298 | // Вызов уже завершен. Не интересно. |
299 | 299 | continue; |
300 | 300 | } |
301 | 301 | $linkedid = $am->GetVar($data_chan['chan'], 'CDR(linkedid)', NULL, false); |
302 | 302 | $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', NULL, false); |
303 | - if(!empty($linkedid) && $linkedid !== $data['linkedid']){ |
|
304 | - $n_data['action'] = 'sip_transfer'; |
|
305 | - $n_data['src_chan'] = $data_chan['out']?$data_chan['chan']:$BRIDGEPEER; |
|
306 | - $n_data['src_num'] = $data_chan['out']?$data_chan['num']: $CALLERID; |
|
307 | - $n_data['dst_chan'] = $data_chan['out']?$BRIDGEPEER:$data_chan['chan']; |
|
308 | - $n_data['dst_num'] = $data_chan['out']?$CALLERID:$data_chan['num']; |
|
309 | - $n_data['start'] = date('Y-m-d H:i:s'); |
|
310 | - $n_data['answer'] = date('Y-m-d H:i:s'); |
|
303 | + if (!empty($linkedid) && $linkedid !== $data['linkedid']) { |
|
304 | + $n_data['action'] = 'sip_transfer'; |
|
305 | + $n_data['src_chan'] = $data_chan['out'] ? $data_chan['chan'] : $BRIDGEPEER; |
|
306 | + $n_data['src_num'] = $data_chan['out'] ? $data_chan['num'] : $CALLERID; |
|
307 | + $n_data['dst_chan'] = $data_chan['out'] ? $BRIDGEPEER : $data_chan['chan']; |
|
308 | + $n_data['dst_num'] = $data_chan['out'] ? $CALLERID : $data_chan['num']; |
|
309 | + $n_data['start'] = date('Y-m-d H:i:s'); |
|
310 | + $n_data['answer'] = date('Y-m-d H:i:s'); |
|
311 | 311 | $n_data['linkedid'] = $linkedid; |
312 | 312 | $n_data['UNIQUEID'] = $data['linkedid'].Util::generateRandomString(); |
313 | 313 | $n_data['transfer'] = '0'; |
314 | 314 | $n_data['recordingfile'] = Cdr::MixMonitor($n_data['dst_chan'], $n_data['UNIQUEID']); |
315 | - $n_data['did'] = $data_chan['did']; |
|
315 | + $n_data['did'] = $data_chan['did']; |
|
316 | 316 | // $data['from_account'] = $from_account; |
317 | 317 | Util::log_msg_db('call_events', json_encode($n_data)); |
318 | 318 | Cdr::insert_data_to_db_m($n_data); |
@@ -321,7 +321,7 @@ discard block |
||
321 | 321 | 'bind' => ['linkedid' => $data['linkedid']] |
322 | 322 | ]; |
323 | 323 | $m_data = CallDetailRecordsTmp::find($filter); |
324 | - foreach ($m_data as $row){ |
|
324 | + foreach ($m_data as $row) { |
|
325 | 325 | $row->writeAttribute('linkedid', $linkedid); |
326 | 326 | $row->save(); |
327 | 327 | } |
@@ -331,7 +331,7 @@ discard block |
||
331 | 331 | */ |
332 | 332 | $am = Util::get_am('off'); |
333 | 333 | $AgiData = base64_encode(json_encode($n_data)); |
334 | - $am->UserEvent('CdrConnector', [ 'AgiData' => $AgiData]); |
|
334 | + $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
|
335 | 335 | } |
336 | 336 | } // Обход текущих каналов. |
337 | 337 | |
@@ -342,7 +342,7 @@ discard block |
||
342 | 342 | * Завершение звонка. Завершение прееадресации. |
343 | 343 | * @param $data |
344 | 344 | */ |
345 | -function Action_dial_hangup($data){ |
|
345 | +function Action_dial_hangup($data) { |
|
346 | 346 | // Action_CreateRowTransfer('dial_hangup', $data); |
347 | 347 | } |
348 | 348 | |
@@ -352,9 +352,9 @@ discard block |
||
352 | 352 | * @param $data |
353 | 353 | * @param array $calls_data |
354 | 354 | */ |
355 | -function Action_CreateRowTransfer($action, $data, $calls_data=null){ |
|
355 | +function Action_CreateRowTransfer($action, $data, $calls_data = null) { |
|
356 | 356 | |
357 | - if(null === $calls_data){ |
|
357 | + if (null === $calls_data) { |
|
358 | 358 | $filter = [ |
359 | 359 | 'linkedid=:linkedid: AND endtime IS NULL AND transfer=1 AND (src_chan=:chan: OR dst_chan=:chan:)', |
360 | 360 | 'bind' => [ |
@@ -364,21 +364,21 @@ discard block |
||
364 | 364 | 'order' => 'is_app', |
365 | 365 | ]; |
366 | 366 | $m_data = CallDetailRecordsTmp::find($filter); |
367 | - $calls_data = $m_data->toArray(); |
|
367 | + $calls_data = $m_data->toArray(); |
|
368 | 368 | } |
369 | 369 | |
370 | - if(count($calls_data) > 1){ |
|
370 | + if (count($calls_data) > 1) { |
|
371 | 371 | $insert_data = array(); |
372 | - foreach ($calls_data as $row_data){ |
|
373 | - if($row_data['src_chan'] === $data['agi_channel'] ){ |
|
374 | - $fname_chan = isset($insert_data['dst_chan']) ? 'src_chan': 'dst_chan'; |
|
375 | - $fname_num = isset($insert_data['dst_num']) ? 'src_num' : 'dst_num'; |
|
372 | + foreach ($calls_data as $row_data) { |
|
373 | + if ($row_data['src_chan'] === $data['agi_channel']) { |
|
374 | + $fname_chan = isset($insert_data['dst_chan']) ? 'src_chan' : 'dst_chan'; |
|
375 | + $fname_num = isset($insert_data['dst_num']) ? 'src_num' : 'dst_num'; |
|
376 | 376 | |
377 | 377 | $insert_data[$fname_chan] = $row_data['dst_chan']; |
378 | 378 | $insert_data[$fname_num] = $row_data['dst_num']; |
379 | - }else{ |
|
380 | - $fname_chan = !isset($insert_data['src_chan']) ? 'src_chan': 'dst_chan'; |
|
381 | - $fname_num = !isset($insert_data['src_num']) ? 'src_num' : 'dst_num'; |
|
379 | + } else { |
|
380 | + $fname_chan = !isset($insert_data['src_chan']) ? 'src_chan' : 'dst_chan'; |
|
381 | + $fname_num = !isset($insert_data['src_num']) ? 'src_num' : 'dst_num'; |
|
382 | 382 | |
383 | 383 | $insert_data[$fname_chan] = $row_data['src_chan']; |
384 | 384 | $insert_data[$fname_num] = $row_data['src_num']; |
@@ -387,31 +387,31 @@ discard block |
||
387 | 387 | // Запись разговора. |
388 | 388 | Cdr::StopMixMonitor($insert_data['src_chan']); |
389 | 389 | Cdr::StopMixMonitor($insert_data['dst_chan']); |
390 | - $recordingfile = Cdr::MixMonitor($insert_data['dst_chan'], 'transfer_'.$insert_data['src_num'].'_'.$insert_data['dst_num'].'_'.$data['linkedid']); |
|
390 | + $recordingfile = Cdr::MixMonitor($insert_data['dst_chan'], 'transfer_'.$insert_data['src_num'].'_'.$insert_data['dst_num'].'_'.$data['linkedid']); |
|
391 | 391 | // |
392 | 392 | $insert_data['action'] = "{$action}_end_trasfer"; |
393 | - $insert_data['recordingfile'] = $recordingfile; |
|
393 | + $insert_data['recordingfile'] = $recordingfile; |
|
394 | 394 | $insert_data['start'] = $data['end']; |
395 | 395 | $insert_data['answer'] = $data['end']; |
396 | 396 | $insert_data['linkedid'] = $data['linkedid']; |
397 | 397 | $insert_data['UNIQUEID'] = $data['agi_threadid']; |
398 | - $insert_data['did'] = $data['did']; |
|
399 | - $insert_data['transfer'] = '0'; |
|
398 | + $insert_data['did'] = $data['did']; |
|
399 | + $insert_data['transfer'] = '0'; |
|
400 | 400 | |
401 | 401 | /** |
402 | 402 | * Отправка UserEvent |
403 | 403 | */ |
404 | - $insert_data['action'] = 'transfer_dial_create_cdr'; |
|
404 | + $insert_data['action'] = 'transfer_dial_create_cdr'; |
|
405 | 405 | $am = Util::get_am('off'); |
406 | 406 | $AgiData = base64_encode(json_encode($insert_data)); |
407 | - $am->UserEvent('CdrConnector', [ 'AgiData' => $AgiData]); |
|
407 | + $am->UserEvent('CdrConnector', ['AgiData' => $AgiData]); |
|
408 | 408 | |
409 | 409 | Cdr::insert_data_to_db_m($insert_data); |
410 | 410 | Cdr::LogEvent(json_encode($insert_data)); |
411 | 411 | |
412 | - }elseif(empty($calls_data[0]['answer']) && count($calls_data) === 1 && !empty($calls_data[0]['recordingfile'])){ |
|
412 | + }elseif (empty($calls_data[0]['answer']) && count($calls_data) === 1 && !empty($calls_data[0]['recordingfile'])) { |
|
413 | 413 | $row_data = $calls_data[0]; |
414 | - $chan = ($data['agi_channel'] === $row_data['src_chan'])?$row_data['dst_chan']:$row_data['src_chan']; |
|
414 | + $chan = ($data['agi_channel'] === $row_data['src_chan']) ? $row_data['dst_chan'] : $row_data['src_chan']; |
|
415 | 415 | $filter = [ |
416 | 416 | 'linkedid=:linkedid: AND endtime IS NULL AND transfer=1 AND (src_chan=:chan: OR dst_chan=:chan:)', |
417 | 417 | 'bind' => [ |
@@ -421,11 +421,11 @@ discard block |
||
421 | 421 | 'order' => 'is_app', |
422 | 422 | ]; |
423 | 423 | /** @var CallDetailRecordsTmp $not_ended_cdr */ |
424 | - $not_ended_cdr = CallDetailRecordsTmp::findFirst($filter); |
|
425 | - if($not_ended_cdr){ |
|
424 | + $not_ended_cdr = CallDetailRecordsTmp::findFirst($filter); |
|
425 | + if ($not_ended_cdr) { |
|
426 | 426 | Cdr::StopMixMonitor($not_ended_cdr->src_chan); |
427 | 427 | // Cdr::StopMixMonitor($not_ended_cdr->dst_chan); |
428 | - Cdr::MixMonitor($not_ended_cdr->dst_chan, '', '',$not_ended_cdr->recordingfile); |
|
428 | + Cdr::MixMonitor($not_ended_cdr->dst_chan, '', '', $not_ended_cdr->recordingfile); |
|
429 | 429 | } |
430 | 430 | |
431 | 431 | } |
@@ -435,7 +435,7 @@ discard block |
||
435 | 435 | * Обработка начала переадресации. |
436 | 436 | * @param $data |
437 | 437 | */ |
438 | -function Action_transfer_dial($data){ |
|
438 | +function Action_transfer_dial($data) { |
|
439 | 439 | |
440 | 440 | Action_transfer_check($data); |
441 | 441 | Cdr::insert_data_to_db_m($data); |
@@ -447,7 +447,7 @@ discard block |
||
447 | 447 | * Проверка на транфер |
448 | 448 | * @param $data |
449 | 449 | */ |
450 | -function Action_transfer_check($data){ |
|
450 | +function Action_transfer_check($data) { |
|
451 | 451 | $filter = [ |
452 | 452 | "linkedid=:linkedid: AND endtime IS NULL AND transfer=0 AND (src_chan=:src_chan: OR dst_chan=:src_chan:)", |
453 | 453 | 'bind' => [ |
@@ -458,7 +458,7 @@ discard block |
||
458 | 458 | /** @var CallDetailRecordsTmp $m_data */ |
459 | 459 | /** @var CallDetailRecordsTmp $row */ |
460 | 460 | $m_data = CallDetailRecordsTmp::find($filter); |
461 | - foreach ($m_data as $row){ |
|
461 | + foreach ($m_data as $row) { |
|
462 | 462 | // Пробуем остановить записть разговора. |
463 | 463 | Cdr::StopMixMonitor($row->dst_chan); |
464 | 464 | Cdr::StopMixMonitor($row->src_chan); |
@@ -472,7 +472,7 @@ discard block |
||
472 | 472 | * Обработка события создания канала - пары, при начале переадресации звонка. |
473 | 473 | * @param $data |
474 | 474 | */ |
475 | -function Action_transfer_dial_create_chan($data){ |
|
475 | +function Action_transfer_dial_create_chan($data) { |
|
476 | 476 | |
477 | 477 | $filter = [ |
478 | 478 | 'UNIQUEID=:UNIQUEID: AND endtime IS NULL AND answer IS NULL', |
@@ -484,18 +484,18 @@ discard block |
||
484 | 484 | /** @var CallDetailRecordsTmp $m_data */ |
485 | 485 | /** @var CallDetailRecordsTmp $row */ |
486 | 486 | $m_data = CallDetailRecordsTmp::find($filter); |
487 | - foreach ($m_data as $row){ |
|
487 | + foreach ($m_data as $row) { |
|
488 | 488 | /// |
489 | 489 | // Проверим, если более одного канала SIP/256 при входящем. |
490 | - if( !empty($row->dst_chan) && $data['dst_chan'] !== $row->dst_chan ){ |
|
491 | - if($row_create){ |
|
490 | + if (!empty($row->dst_chan) && $data['dst_chan'] !== $row->dst_chan) { |
|
491 | + if ($row_create) { |
|
492 | 492 | continue; |
493 | 493 | } |
494 | 494 | // Необходимо дублировать строку звонка. |
495 | 495 | $new_row = new CallDetailRecordsTmp(); |
496 | 496 | $f_list = $row->toArray(); |
497 | - foreach ($f_list as $attribute => $value){ |
|
498 | - if($attribute === 'id'){ |
|
497 | + foreach ($f_list as $attribute => $value) { |
|
498 | + if ($attribute === 'id') { |
|
499 | 499 | continue; |
500 | 500 | } |
501 | 501 | $new_row->writeAttribute($attribute, $value); |
@@ -508,18 +508,18 @@ discard block |
||
508 | 508 | $row_create = true; |
509 | 509 | } |
510 | 510 | |
511 | - $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $row->UNIQUEID); |
|
511 | + $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $row->UNIQUEID); |
|
512 | 512 | // конец проверки |
513 | 513 | /// |
514 | 514 | |
515 | - $row->writeAttribute('dst_chan', $data['dst_chan']); |
|
515 | + $row->writeAttribute('dst_chan', $data['dst_chan']); |
|
516 | 516 | $row->writeAttribute('recordingfile', $data['recordingfile']); |
517 | - if( isset($data['dst_call_id']) && !empty($data['dst_call_id']) ){ |
|
517 | + if (isset($data['dst_call_id']) && !empty($data['dst_call_id'])) { |
|
518 | 518 | $row->writeAttribute('dst_call_id', $data['dst_call_id']); |
519 | 519 | } |
520 | 520 | $res = $row->save(); |
521 | - if(!$res) { |
|
522 | - Util::sys_log_msg('Action_transfer_dial_create_chan', implode(' ',$row->getMessages())); |
|
521 | + if (!$res) { |
|
522 | + Util::sys_log_msg('Action_transfer_dial_create_chan', implode(' ', $row->getMessages())); |
|
523 | 523 | } |
524 | 524 | } |
525 | 525 | } |
@@ -528,7 +528,7 @@ discard block |
||
528 | 528 | * Обработка события ответа на переадресацию. Соединение абонентов. |
529 | 529 | * @param $data |
530 | 530 | */ |
531 | -function Action_transfer_dial_answer($data){ |
|
531 | +function Action_transfer_dial_answer($data) { |
|
532 | 532 | $filter = [ |
533 | 533 | '(UNIQUEID=:UNIQUEID: OR UNIQUEID=:UNIQUEID_CHAN:) AND answer IS NULL AND endtime IS NULL', |
534 | 534 | 'bind' => [ |
@@ -540,11 +540,11 @@ discard block |
||
540 | 540 | /** @var CallDetailRecordsTmp $m_data */ |
541 | 541 | /** @var CallDetailRecordsTmp $row */ |
542 | 542 | $m_data = CallDetailRecordsTmp::find($filter); |
543 | - foreach ($m_data as $row){ |
|
543 | + foreach ($m_data as $row) { |
|
544 | 544 | $row->writeAttribute('answer', $data['answer']); |
545 | 545 | $res = $row->save(); |
546 | - if(!$res) { |
|
547 | - Util::sys_log_msg('Action_transfer_dial_answer', implode(' ',$row->getMessages())); |
|
546 | + if (!$res) { |
|
547 | + Util::sys_log_msg('Action_transfer_dial_answer', implode(' ', $row->getMessages())); |
|
548 | 548 | } |
549 | 549 | } |
550 | 550 | } |
@@ -553,10 +553,10 @@ discard block |
||
553 | 553 | * Завершение канала при прееадресации. |
554 | 554 | * @param $data |
555 | 555 | */ |
556 | -function Action_transfer_dial_hangup($data){ |
|
556 | +function Action_transfer_dial_hangup($data) { |
|
557 | 557 | |
558 | - $pos = stripos( $data['agi_channel'], 'local/'); |
|
559 | - if($pos === false){ |
|
558 | + $pos = stripos($data['agi_channel'], 'local/'); |
|
559 | + if ($pos === false) { |
|
560 | 560 | // Это НЕ локальный канал. |
561 | 561 | // Если это завершение переадресации (консультативной). Создадим новую строку CDR. |
562 | 562 | // Action_CreateRowTransfer('transfer_dial_hangup', $data); |
@@ -572,12 +572,12 @@ discard block |
||
572 | 572 | /** @var CallDetailRecordsTmp $m_data */ |
573 | 573 | /** @var CallDetailRecordsTmp $row */ |
574 | 574 | $m_data = CallDetailRecordsTmp::find($filter); |
575 | - foreach ($m_data as $row){ |
|
575 | + foreach ($m_data as $row) { |
|
576 | 576 | // Завершим вызов в CDR. |
577 | - $row->writeAttribute('endtime', $data['end']); |
|
577 | + $row->writeAttribute('endtime', $data['end']); |
|
578 | 578 | $row->writeAttribute('transfer', 0); |
579 | - if(!$row->save()) { |
|
580 | - Util::sys_log_msg('Action_transfer_dial_answer', implode(' ',$row->getMessages())); |
|
579 | + if (!$row->save()) { |
|
580 | + Util::sys_log_msg('Action_transfer_dial_answer', implode(' ', $row->getMessages())); |
|
581 | 581 | } |
582 | 582 | } |
583 | 583 | // Попробуем начать запись разговора. |
@@ -589,13 +589,13 @@ discard block |
||
589 | 589 | ]; |
590 | 590 | /** @var CallDetailRecordsTmp $res */ |
591 | 591 | $res = CallDetailRecordsTmp::findFirst($filter); |
592 | - if($res){ |
|
592 | + if ($res) { |
|
593 | 593 | $info = pathinfo($res->recordingfile); |
594 | - $data_time = ($res->answer == null)?$res->start:$res->answer; |
|
595 | - $subdir = date('Y/m/d/H/',strtotime($data_time)); |
|
594 | + $data_time = ($res->answer == null) ? $res->start : $res->answer; |
|
595 | + $subdir = date('Y/m/d/H/', strtotime($data_time)); |
|
596 | 596 | Cdr::MixMonitor($res->src_chan, $info['filename'], $subdir); |
597 | 597 | } |
598 | - }else if('' === $data['ANSWEREDTIME'] ){ |
|
598 | + } else if ('' === $data['ANSWEREDTIME']) { |
|
599 | 599 | $filter = [ |
600 | 600 | 'linkedid=:linkedid: AND endtime IS NULL AND (src_chan=:src_chan: OR dst_chan=:dst_chan:)', |
601 | 601 | 'bind' => [ |
@@ -607,12 +607,12 @@ discard block |
||
607 | 607 | /** @var CallDetailRecordsTmp $m_data */ |
608 | 608 | /** @var CallDetailRecordsTmp $row */ |
609 | 609 | $m_data = CallDetailRecordsTmp::find($filter); |
610 | - foreach ($m_data as $row){ |
|
610 | + foreach ($m_data as $row) { |
|
611 | 611 | // Ответа не было. Переадресация отменена. |
612 | - $row->writeAttribute('endtime', $data['end']); |
|
612 | + $row->writeAttribute('endtime', $data['end']); |
|
613 | 613 | $row->writeAttribute('transfer', 0); |
614 | - if(!$row->save()) { |
|
615 | - Util::sys_log_msg('Action_transfer_dial_answer', implode(' ',$row->getMessages())); |
|
614 | + if (!$row->save()) { |
|
615 | + Util::sys_log_msg('Action_transfer_dial_answer', implode(' ', $row->getMessages())); |
|
616 | 616 | }; |
617 | 617 | } |
618 | 618 | |
@@ -624,15 +624,15 @@ discard block |
||
624 | 624 | ] |
625 | 625 | ]; |
626 | 626 | $m_data = CallDetailRecordsTmp::find($filter); |
627 | - foreach ($m_data as $row){ |
|
627 | + foreach ($m_data as $row) { |
|
628 | 628 | $info = pathinfo($row->recordingfile); |
629 | - $data_time = ($row->answer == null)?$row->start:$row->answer; |
|
630 | - $subdir = date('Y/m/d/H/',strtotime($data_time)); |
|
629 | + $data_time = ($row->answer == null) ? $row->start : $row->answer; |
|
630 | + $subdir = date('Y/m/d/H/', strtotime($data_time)); |
|
631 | 631 | Cdr::MixMonitor($row->src_chan, $info['filename'], $subdir); |
632 | 632 | // Снимем со строк признак переадресации. |
633 | 633 | $row->writeAttribute('transfer', 0); |
634 | - if(!$row->save()) { |
|
635 | - Util::sys_log_msg('Action_transfer_dial_answer', implode(' ',$row->getMessages())); |
|
634 | + if (!$row->save()) { |
|
635 | + Util::sys_log_msg('Action_transfer_dial_answer', implode(' ', $row->getMessages())); |
|
636 | 636 | } |
637 | 637 | } |
638 | 638 | |
@@ -644,7 +644,7 @@ discard block |
||
644 | 644 | * Начало работы приложения. |
645 | 645 | * @param $data |
646 | 646 | */ |
647 | -function Action_dial_app($data){ |
|
647 | +function Action_dial_app($data) { |
|
648 | 648 | Action_app_end($data); |
649 | 649 | Cdr::insert_data_to_db_m($data); |
650 | 650 | } |
@@ -653,7 +653,7 @@ discard block |
||
653 | 653 | * Завершение работы приложения. |
654 | 654 | * @param $data |
655 | 655 | */ |
656 | -function Action_app_end($data){ |
|
656 | +function Action_app_end($data) { |
|
657 | 657 | $filter = [ |
658 | 658 | 'linkedid=:linkedid: AND is_app=1 AND endtime IS NULL', |
659 | 659 | 'bind' => [ |
@@ -663,11 +663,11 @@ discard block |
||
663 | 663 | /** @var CallDetailRecordsTmp $m_data */ |
664 | 664 | /** @var CallDetailRecordsTmp $row */ |
665 | 665 | $m_data = CallDetailRecordsTmp::find($filter); |
666 | - foreach ($m_data as $row){ |
|
667 | - $row->writeAttribute('endtime', $data['start']); |
|
666 | + foreach ($m_data as $row) { |
|
667 | + $row->writeAttribute('endtime', $data['start']); |
|
668 | 668 | $res = $row->update(); |
669 | - if(!$res) { |
|
670 | - Util::sys_log_msg('Action_app_end', implode(' ',$row->getMessages())); |
|
669 | + if (!$res) { |
|
670 | + Util::sys_log_msg('Action_app_end', implode(' ', $row->getMessages())); |
|
671 | 671 | } |
672 | 672 | } |
673 | 673 | } |
@@ -676,7 +676,7 @@ discard block |
||
676 | 676 | * Вызов в нерабочее время. |
677 | 677 | * @param $data |
678 | 678 | */ |
679 | -function Action_dial_outworktimes($data){ |
|
679 | +function Action_dial_outworktimes($data) { |
|
680 | 680 | Cdr::insert_data_to_db_m($data); |
681 | 681 | } |
682 | 682 | |
@@ -684,16 +684,16 @@ discard block |
||
684 | 684 | * Старт очереди. |
685 | 685 | * @param $data |
686 | 686 | */ |
687 | -function Action_queue_start($data){ |
|
687 | +function Action_queue_start($data) { |
|
688 | 688 | |
689 | - if($data['transfer'] == '1'){ |
|
689 | + if ($data['transfer'] == '1') { |
|
690 | 690 | // Если это трансфер выполним поиск связанных данных. |
691 | 691 | Action_transfer_check($data); |
692 | 692 | } |
693 | - if(isset($data['start'])){ |
|
693 | + if (isset($data['start'])) { |
|
694 | 694 | // Это новая строка. |
695 | 695 | Cdr::insert_data_to_db_m($data); |
696 | - }else{ |
|
696 | + } else { |
|
697 | 697 | // Требуется только обновление данных. |
698 | 698 | Cdr::update_data_in_db_m($data); |
699 | 699 | } |
@@ -704,10 +704,10 @@ discard block |
||
704 | 704 | * Событие входа в конференцкомнату. |
705 | 705 | * @param $data |
706 | 706 | */ |
707 | -function Action_meetme_dial($data){ |
|
707 | +function Action_meetme_dial($data) { |
|
708 | 708 | Cdr::StopMixMonitor($data['src_chan']); |
709 | 709 | |
710 | - if(strpos($data['src_chan'], 'internal-originate') !== false){ |
|
710 | + if (strpos($data['src_chan'], 'internal-originate') !== false) { |
|
711 | 711 | // Уточним канал и ID записи; |
712 | 712 | $filter = [ |
713 | 713 | 'linkedid=:linkedid: AND src_num=:src_num:', |
@@ -719,13 +719,13 @@ discard block |
||
719 | 719 | /** @var CallDetailRecordsTmp $m_data */ |
720 | 720 | /** @var CallDetailRecordsTmp $row */ |
721 | 721 | $m_data = CallDetailRecordsTmp::findFirst($filter); |
722 | - if($m_data){ |
|
722 | + if ($m_data) { |
|
723 | 723 | $data['src_chan'] = $m_data->src_chan; |
724 | 724 | $m_data->UNIQUEID = $data['UNIQUEID']; |
725 | 725 | |
726 | 726 | $f_list = Cdr::get_db_fealds(); |
727 | - foreach ($data as $attribute => $value){ |
|
728 | - if(!array_key_exists($attribute, $f_list)){ |
|
727 | + foreach ($data as $attribute => $value) { |
|
728 | + if (!array_key_exists($attribute, $f_list)) { |
|
729 | 729 | continue; |
730 | 730 | } |
731 | 731 | $m_data->writeAttribute($attribute, $value); |
@@ -733,7 +733,7 @@ discard block |
||
733 | 733 | // Переопределяем идентификатор, это Originate на конференцию. |
734 | 734 | $m_data->save(); |
735 | 735 | } |
736 | - }else{ |
|
736 | + } else { |
|
737 | 737 | Cdr::insert_data_to_db_m($data); |
738 | 738 | Action_app_end($data); |
739 | 739 | } |
@@ -743,10 +743,10 @@ discard block |
||
743 | 743 | * Снятие вызова с парковки. |
744 | 744 | * @param $data |
745 | 745 | */ |
746 | -function Action_unpark_call($data){ |
|
747 | - $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $data['UNIQUEID']); |
|
746 | +function Action_unpark_call($data) { |
|
747 | + $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $data['UNIQUEID']); |
|
748 | 748 | Cdr::insert_data_to_db_m($data); |
749 | - if( is_array($data['data_parking']) ){ |
|
749 | + if (is_array($data['data_parking'])) { |
|
750 | 750 | Cdr::insert_data_to_db_m($data['data_parking']); |
751 | 751 | } |
752 | 752 | $filter = [ |
@@ -759,7 +759,7 @@ discard block |
||
759 | 759 | /** @var CallDetailRecordsTmp $m_data */ |
760 | 760 | /** @var CallDetailRecordsTmp $row */ |
761 | 761 | $m_data = CallDetailRecordsTmp::find($filter); |
762 | - foreach ($m_data as $row){ |
|
762 | + foreach ($m_data as $row) { |
|
763 | 763 | $row->delete(); |
764 | 764 | } |
765 | 765 | } |
@@ -768,7 +768,7 @@ discard block |
||
768 | 768 | * Возвращаем вызов с парковки по таймауту. |
769 | 769 | * @param $data |
770 | 770 | */ |
771 | -function Action_unpark_call_timeout($data){ |
|
771 | +function Action_unpark_call_timeout($data) { |
|
772 | 772 | Cdr::insert_data_to_db_m($data); |
773 | 773 | } |
774 | 774 | |
@@ -776,7 +776,7 @@ discard block |
||
776 | 776 | * Ответ агента очереди. |
777 | 777 | * @param $data |
778 | 778 | */ |
779 | -function Action_queue_answer($data){ |
|
779 | +function Action_queue_answer($data) { |
|
780 | 780 | |
781 | 781 | $filter = [ |
782 | 782 | "UNIQUEID=:UNIQUEID: AND answer IS NULL", |
@@ -787,12 +787,12 @@ discard block |
||
787 | 787 | /** @var CallDetailRecordsTmp $m_data */ |
788 | 788 | /** @var CallDetailRecordsTmp $row */ |
789 | 789 | $m_data = CallDetailRecordsTmp::find($filter); |
790 | - foreach ($m_data as $row){ |
|
790 | + foreach ($m_data as $row) { |
|
791 | 791 | $row->writeAttribute('answer', $data['answer']); |
792 | - $row->writeAttribute('endtime',$data['answer']); |
|
792 | + $row->writeAttribute('endtime', $data['answer']); |
|
793 | 793 | $res = $row->save(); |
794 | - if(!$res) { |
|
795 | - Util::sys_log_msg('Action_queue_answer', implode(' ',$row->getMessages())); |
|
794 | + if (!$res) { |
|
795 | + Util::sys_log_msg('Action_queue_answer', implode(' ', $row->getMessages())); |
|
796 | 796 | }; |
797 | 797 | } |
798 | 798 | } |
@@ -801,7 +801,7 @@ discard block |
||
801 | 801 | * Завершение работы очереди. |
802 | 802 | * @param $data |
803 | 803 | */ |
804 | -function Action_queue_end($data){ |
|
804 | +function Action_queue_end($data) { |
|
805 | 805 | $filter = [ |
806 | 806 | "UNIQUEID=:UNIQUEID:", |
807 | 807 | 'bind' => [ |
@@ -811,15 +811,15 @@ discard block |
||
811 | 811 | /** @var CallDetailRecordsTmp $m_data */ |
812 | 812 | /** @var CallDetailRecordsTmp $row */ |
813 | 813 | $m_data = CallDetailRecordsTmp::find($filter); |
814 | - foreach ($m_data as $row){ |
|
815 | - $row->writeAttribute('endtime',$data['end']); |
|
814 | + foreach ($m_data as $row) { |
|
815 | + $row->writeAttribute('endtime', $data['end']); |
|
816 | 816 | $row->writeAttribute('is_app', 1); |
817 | - if($data['dialstatus'] != ''){ |
|
818 | - $row->writeAttribute('dialstatus',$data['dialstatus']); |
|
817 | + if ($data['dialstatus'] != '') { |
|
818 | + $row->writeAttribute('dialstatus', $data['dialstatus']); |
|
819 | 819 | } |
820 | 820 | $res = $row->save(); |
821 | - if(!$res) { |
|
822 | - Util::sys_log_msg('Action_queue_end', implode(' ',$row->getMessages())); |
|
821 | + if (!$res) { |
|
822 | + Util::sys_log_msg('Action_queue_end', implode(' ', $row->getMessages())); |
|
823 | 823 | }; |
824 | 824 | } |
825 | 825 | |
@@ -829,7 +829,7 @@ discard block |
||
829 | 829 | * Завершение / уничтожение канала. |
830 | 830 | * @param $data |
831 | 831 | */ |
832 | -function Action_hangup_chan_meetme($data){ |
|
832 | +function Action_hangup_chan_meetme($data) { |
|
833 | 833 | clearstatcache(); |
834 | 834 | $recordingfile = ''; |
835 | 835 | $dest_chan = "MeetMe:{$data['conference']}"; |
@@ -844,47 +844,47 @@ discard block |
||
844 | 844 | $m_data = CallDetailRecordsTmp::find($filter); |
845 | 845 | /** @var CallDetailRecordsTmp $row */ |
846 | 846 | foreach ($m_data as $row) { |
847 | - if($dest_chan === $row->dst_chan){ |
|
847 | + if ($dest_chan === $row->dst_chan) { |
|
848 | 848 | $is_local = (stripos($data['src_chan'], 'local/') !== false); |
849 | 849 | $is_stored_local = (stripos($row->src_chan, 'local/') !== false); |
850 | - if($row->UNIQUEID === $data['UNIQUEID'] && $is_local && !$is_stored_local){ |
|
850 | + if ($row->UNIQUEID === $data['UNIQUEID'] && $is_local && !$is_stored_local) { |
|
851 | 851 | $data['src_chan'] = $row->src_chan; |
852 | 852 | } |
853 | - if( file_exists($row->recordingfile) || file_exists(Util::trim_extension_file($row->recordingfile).'.wav') ){ |
|
853 | + if (file_exists($row->recordingfile) || file_exists(Util::trim_extension_file($row->recordingfile).'.wav')) { |
|
854 | 854 | // Переопределим путь к файлу записи разговора. Для конферецнии файл один. |
855 | 855 | $recordingfile = $row->recordingfile; |
856 | 856 | } |
857 | 857 | |
858 | 858 | } |
859 | - if($row->linkedid === $data['meetme_id']){ |
|
859 | + if ($row->linkedid === $data['meetme_id']) { |
|
860 | 860 | continue; |
861 | 861 | } |
862 | 862 | // Подменим ID на идентификатор конференции. |
863 | 863 | $row->writeAttribute('linkedid', $data['meetme_id']); |
864 | 864 | $res = $row->save(); |
865 | - if(!$res) { |
|
866 | - Util::sys_log_msg('Action_hangup_chan_meetme', implode(' ',$row->getMessages())); |
|
865 | + if (!$res) { |
|
866 | + Util::sys_log_msg('Action_hangup_chan_meetme', implode(' ', $row->getMessages())); |
|
867 | 867 | } |
868 | 868 | } |
869 | 869 | |
870 | 870 | /** @var CallDetailRecordsTmp $m_data */ |
871 | 871 | /** @var CallDetailRecordsTmp $row */ |
872 | 872 | /** @var CallDetailRecordsTmp $rec_data */ |
873 | - foreach ($m_data as $row){ |
|
874 | - if($row->src_chan !== $data['src_chan']){ |
|
873 | + foreach ($m_data as $row) { |
|
874 | + if ($row->src_chan !== $data['src_chan']) { |
|
875 | 875 | continue; |
876 | 876 | } |
877 | 877 | // Заполняем данные для текущего оповещения. |
878 | - $row->writeAttribute('endtime', $data['end']); |
|
878 | + $row->writeAttribute('endtime', $data['end']); |
|
879 | 879 | $row->writeAttribute('transfer', 0); |
880 | - $row->writeAttribute('linkedid', $data['meetme_id']); |
|
880 | + $row->writeAttribute('linkedid', $data['meetme_id']); |
|
881 | 881 | |
882 | - if(!empty($recordingfile) ){ |
|
882 | + if (!empty($recordingfile)) { |
|
883 | 883 | $row->writeAttribute('recordingfile', $recordingfile); |
884 | 884 | } |
885 | 885 | $res = $row->save(); |
886 | - if(!$res) { |
|
887 | - Util::sys_log_msg('Action_hangup_chan_meetme', implode(' ',$row->getMessages())); |
|
886 | + if (!$res) { |
|
887 | + Util::sys_log_msg('Action_hangup_chan_meetme', implode(' ', $row->getMessages())); |
|
888 | 888 | } |
889 | 889 | } |
890 | 890 | |
@@ -895,10 +895,10 @@ discard block |
||
895 | 895 | * Обработчик событий изменения состояния звонка. |
896 | 896 | * @param array | BeanstalkClient $message |
897 | 897 | */ |
898 | -$call_events = function ($message) { |
|
898 | +$call_events = function($message) { |
|
899 | 899 | $data = json_decode($message->getBody(), true); |
900 | 900 | $func_name = 'Action_'.$data['action']; |
901 | - if( function_exists($func_name) ){ |
|
901 | + if (function_exists($func_name)) { |
|
902 | 902 | $func_name($data); |
903 | 903 | } |
904 | 904 | $message->reply(json_encode(true)); |
@@ -908,7 +908,7 @@ discard block |
||
908 | 908 | * Обработчик пинга. |
909 | 909 | * @param array | BeanstalkClient $message |
910 | 910 | */ |
911 | -$ping_worker = function ($message) { |
|
911 | +$ping_worker = function($message) { |
|
912 | 912 | $message->reply(json_encode($message->getBody().':pong')); |
913 | 913 | |
914 | 914 | set_global_settings(); |
@@ -918,7 +918,7 @@ discard block |
||
918 | 918 | * Получения CDR к обработке. |
919 | 919 | * @param array | BeanstalkClient $message |
920 | 920 | */ |
921 | -$update_cdr = function ($message){ |
|
921 | +$update_cdr = function($message) { |
|
922 | 922 | $q = $message->getBody(); |
923 | 923 | $data = json_decode($q, true); |
924 | 924 | $res = Cdr::update_data_in_db_m($data); |
@@ -928,38 +928,38 @@ discard block |
||
928 | 928 | /** |
929 | 929 | * @param array | BeanstalkClient $message |
930 | 930 | */ |
931 | -$select_cdr = function ($message){ |
|
931 | +$select_cdr = function($message) { |
|
932 | 932 | $q = $message->getBody(); |
933 | 933 | $filter = json_decode($q, true); |
934 | 934 | $res = null; |
935 | - try{ |
|
936 | - if(isset($filter['miko_tmp_db'])){ |
|
935 | + try { |
|
936 | + if (isset($filter['miko_tmp_db'])) { |
|
937 | 937 | $res = CallDetailRecordsTmp::find($filter); |
938 | - }else{ |
|
938 | + } else { |
|
939 | 939 | $res = CallDetailRecords::find($filter); |
940 | 940 | } |
941 | 941 | $res_data = json_encode($res->toArray()); |
942 | - }catch (Exception $e){ |
|
942 | + } catch (Exception $e) { |
|
943 | 943 | $res_data = '[]'; |
944 | 944 | } |
945 | 945 | |
946 | - if($res && isset($filter['add_pack_query'])) { |
|
946 | + if ($res && isset($filter['add_pack_query'])) { |
|
947 | 947 | $arr = []; |
948 | - foreach ($res->toArray() as $row){ |
|
948 | + foreach ($res->toArray() as $row) { |
|
949 | 949 | $arr[] = $row[$filter['columns']]; |
950 | 950 | } |
951 | 951 | $filter['add_pack_query']['bind'][$filter['columns']] = $arr; |
952 | - try{ |
|
953 | - $res = CallDetailRecords::find($filter['add_pack_query']); |
|
952 | + try { |
|
953 | + $res = CallDetailRecords::find($filter['add_pack_query']); |
|
954 | 954 | $res_data = json_encode($res->toArray()); |
955 | - }catch (Exception $e){ |
|
955 | + } catch (Exception $e) { |
|
956 | 956 | $res_data = '[]'; |
957 | 957 | } |
958 | 958 | } |
959 | 959 | |
960 | - if( isset($filter['miko_result_in_file']) ){ |
|
960 | + if (isset($filter['miko_result_in_file'])) { |
|
961 | 961 | $ast_dirs = PBX::get_asterisk_dirs(); |
962 | - $filename = $ast_dirs['tmp'].'/'.md5( microtime(true) ); |
|
962 | + $filename = $ast_dirs['tmp'].'/'.md5(microtime(true)); |
|
963 | 963 | file_put_contents("$filename", $res_data); |
964 | 964 | Util::mwexec("chown -R www:www {$filename} > /dev/null 2> /dev/null"); |
965 | 965 | $res_data = json_encode("$filename"); |
@@ -968,7 +968,7 @@ discard block |
||
968 | 968 | $message->reply($res_data); |
969 | 969 | }; |
970 | 970 | |
971 | -function set_global_settings(){ |
|
971 | +function set_global_settings() { |
|
972 | 972 | global $g; |
973 | 973 | $config = new Config(); |
974 | 974 | $g['record_calls'] = $config->get_general_settings('PBXRecordCalls'); |
@@ -977,7 +977,7 @@ discard block |
||
977 | 977 | } |
978 | 978 | echo "starting...\n"; |
979 | 979 | |
980 | -$err_handler = function ($m){ |
|
980 | +$err_handler = function($m) { |
|
981 | 981 | Util::sys_log_msg("CDR_WORKER_ERROR", $m); |
982 | 982 | }; |
983 | 983 | |
@@ -986,16 +986,16 @@ discard block |
||
986 | 986 | */ |
987 | 987 | while (true) { |
988 | 988 | set_global_settings(); |
989 | - try{ |
|
990 | - $client = new BeanstalkClient('call_events'); |
|
991 | - $client->subscribe('call_events', $call_events); |
|
992 | - $client->subscribe('select_cdr', $select_cdr ); |
|
993 | - $client->subscribe('update_cdr', $update_cdr ); |
|
994 | - $client->subscribe('ping_worker_call_events', $ping_worker); |
|
989 | + try { |
|
990 | + $client = new BeanstalkClient('call_events'); |
|
991 | + $client->subscribe('call_events', $call_events); |
|
992 | + $client->subscribe('select_cdr', $select_cdr); |
|
993 | + $client->subscribe('update_cdr', $update_cdr); |
|
994 | + $client->subscribe('ping_worker_call_events', $ping_worker); |
|
995 | 995 | $client->setErrorHendler($err_handler); |
996 | 996 | |
997 | 997 | $client->wait(); |
998 | - }catch (Exception $e){ |
|
998 | + } catch (Exception $e) { |
|
999 | 999 | $errorLogger = $g['error_logger']; |
1000 | 1000 | $errorLogger->captureException($e); |
1001 | 1001 | sleep(1); |
@@ -14,7 +14,8 @@ discard block |
||
14 | 14 | * Обработка события начала телефонного звонка. |
15 | 15 | * @param $data |
16 | 16 | */ |
17 | -function Action_dial($data){ |
|
17 | +function Action_dial($data) |
|
18 | +{ |
|
18 | 19 | Cdr::insert_data_to_db_m($data); |
19 | 20 | Action_app_end($data); |
20 | 21 | } |
@@ -23,14 +24,15 @@ discard block |
||
23 | 24 | * Обработка события создания канала - пары, при начале телефонного звонка. |
24 | 25 | * @param $data |
25 | 26 | */ |
26 | -function Action_dial_create_chan($data){ |
|
27 | +function Action_dial_create_chan($data) |
|
28 | +{ |
|
27 | 29 | |
28 | 30 | if( isset($data['org_id']) ) { |
29 | 31 | // Вероятно необходимо переопределить искать по двум ID. |
30 | 32 | // Применимо только для Originate, когда в качестве звонящего используем два канала |
31 | 33 | // мобильный и внутренний номер. |
32 | 34 | $filter = ['(UNIQUEID=:UNIQUEID: OR UNIQUEID=:org_id:) AND endtime IS NULL', 'bind' => ['UNIQUEID' => $data['UNIQUEID'], 'org_id' => $data['org_id'],]]; |
33 | - }else{ |
|
35 | + } else{ |
|
34 | 36 | $filter = [ |
35 | 37 | 'UNIQUEID=:UNIQUEID: AND answer IS NULL AND endtime IS NULL', |
36 | 38 | 'bind' => [ |
@@ -78,7 +80,7 @@ discard block |
||
78 | 80 | $account_col = 'from_account'; |
79 | 81 | // При оригинации меняется местами srs_chan в поле dst_chan. |
80 | 82 | $row->writeAttribute('src_chan', $data['dst_chan']); |
81 | - }else{ |
|
83 | + } else{ |
|
82 | 84 | if(!$rec_start){ |
83 | 85 | $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $row->UNIQUEID, null, $row->recordingfile); |
84 | 86 | $row->writeAttribute('recordingfile', $data['recordingfile']); |
@@ -105,7 +107,8 @@ discard block |
||
105 | 107 | * Обработка события ответа на звонок. Соединение абонентов. |
106 | 108 | * @param $data |
107 | 109 | */ |
108 | -function Action_dial_answer($data){ |
|
110 | +function Action_dial_answer($data) |
|
111 | +{ |
|
109 | 112 | $pickupexten = Config::get_pickupexten(); |
110 | 113 | if(trim($data['dnid']) === $pickupexten){ |
111 | 114 | // Pickup / перехват вызова. |
@@ -137,7 +140,7 @@ discard block |
||
137 | 140 | $AgiData = base64_encode(json_encode($new_data)); |
138 | 141 | $am->UserEvent('CdrConnector', [ 'AgiData' => $AgiData]); |
139 | 142 | } |
140 | - }else{ |
|
143 | + } else{ |
|
141 | 144 | if(!empty($data['ENDCALLONANSWER'])){ |
142 | 145 | // Переменная ENDCALLONANSWER устанавливается при начале работы умной маршуртизации. |
143 | 146 | // Как только произошел ответ на вызов, отметим вызов на приложение как завершенный. |
@@ -172,7 +175,7 @@ discard block |
||
172 | 175 | 'org_id' => $data['org_id'], |
173 | 176 | ] |
174 | 177 | ]; |
175 | - }else{ |
|
178 | + } else{ |
|
176 | 179 | $filter = [ |
177 | 180 | '(UNIQUEID=:UNIQUEID: OR UNIQUEID=:UNIQUEID_CHAN:) AND answer IS NULL AND endtime IS NULL', |
178 | 181 | 'bind' => [ |
@@ -213,7 +216,7 @@ discard block |
||
213 | 216 | $row->writeAttribute('UNIQUEID', $data['id']); |
214 | 217 | $row->save(); |
215 | 218 | break; |
216 | - }else{ |
|
219 | + } else{ |
|
217 | 220 | $row->writeAttribute('answer', $data['answer']); |
218 | 221 | } |
219 | 222 | $res = $row->save(); |
@@ -229,7 +232,8 @@ discard block |
||
229 | 232 | * Завершение / уничтожение канала. |
230 | 233 | * @param $data |
231 | 234 | */ |
232 | -function Action_hangup_chan($data){ |
|
235 | +function Action_hangup_chan($data) |
|
236 | +{ |
|
233 | 237 | $channels = []; |
234 | 238 | $transfer_calls = []; |
235 | 239 | $filter = [ |
@@ -270,7 +274,7 @@ discard block |
||
270 | 274 | 'num' => $row->src_num, |
271 | 275 | 'out' => true |
272 | 276 | ]; |
273 | - }else{ |
|
277 | + } else{ |
|
274 | 278 | $channels[] = [ |
275 | 279 | 'chan' => $row->dst_chan, |
276 | 280 | 'did' => $row->did, |
@@ -342,7 +346,8 @@ discard block |
||
342 | 346 | * Завершение звонка. Завершение прееадресации. |
343 | 347 | * @param $data |
344 | 348 | */ |
345 | -function Action_dial_hangup($data){ |
|
349 | +function Action_dial_hangup($data) |
|
350 | +{ |
|
346 | 351 | // Action_CreateRowTransfer('dial_hangup', $data); |
347 | 352 | } |
348 | 353 | |
@@ -352,7 +357,8 @@ discard block |
||
352 | 357 | * @param $data |
353 | 358 | * @param array $calls_data |
354 | 359 | */ |
355 | -function Action_CreateRowTransfer($action, $data, $calls_data=null){ |
|
360 | +function Action_CreateRowTransfer($action, $data, $calls_data=null) |
|
361 | +{ |
|
356 | 362 | |
357 | 363 | if(null === $calls_data){ |
358 | 364 | $filter = [ |
@@ -376,7 +382,7 @@ discard block |
||
376 | 382 | |
377 | 383 | $insert_data[$fname_chan] = $row_data['dst_chan']; |
378 | 384 | $insert_data[$fname_num] = $row_data['dst_num']; |
379 | - }else{ |
|
385 | + } else{ |
|
380 | 386 | $fname_chan = !isset($insert_data['src_chan']) ? 'src_chan': 'dst_chan'; |
381 | 387 | $fname_num = !isset($insert_data['src_num']) ? 'src_num' : 'dst_num'; |
382 | 388 | |
@@ -409,7 +415,7 @@ discard block |
||
409 | 415 | Cdr::insert_data_to_db_m($insert_data); |
410 | 416 | Cdr::LogEvent(json_encode($insert_data)); |
411 | 417 | |
412 | - }elseif(empty($calls_data[0]['answer']) && count($calls_data) === 1 && !empty($calls_data[0]['recordingfile'])){ |
|
418 | + } elseif(empty($calls_data[0]['answer']) && count($calls_data) === 1 && !empty($calls_data[0]['recordingfile'])){ |
|
413 | 419 | $row_data = $calls_data[0]; |
414 | 420 | $chan = ($data['agi_channel'] === $row_data['src_chan'])?$row_data['dst_chan']:$row_data['src_chan']; |
415 | 421 | $filter = [ |
@@ -435,7 +441,8 @@ discard block |
||
435 | 441 | * Обработка начала переадресации. |
436 | 442 | * @param $data |
437 | 443 | */ |
438 | -function Action_transfer_dial($data){ |
|
444 | +function Action_transfer_dial($data) |
|
445 | +{ |
|
439 | 446 | |
440 | 447 | Action_transfer_check($data); |
441 | 448 | Cdr::insert_data_to_db_m($data); |
@@ -447,7 +454,8 @@ discard block |
||
447 | 454 | * Проверка на транфер |
448 | 455 | * @param $data |
449 | 456 | */ |
450 | -function Action_transfer_check($data){ |
|
457 | +function Action_transfer_check($data) |
|
458 | +{ |
|
451 | 459 | $filter = [ |
452 | 460 | "linkedid=:linkedid: AND endtime IS NULL AND transfer=0 AND (src_chan=:src_chan: OR dst_chan=:src_chan:)", |
453 | 461 | 'bind' => [ |
@@ -472,7 +480,8 @@ discard block |
||
472 | 480 | * Обработка события создания канала - пары, при начале переадресации звонка. |
473 | 481 | * @param $data |
474 | 482 | */ |
475 | -function Action_transfer_dial_create_chan($data){ |
|
483 | +function Action_transfer_dial_create_chan($data) |
|
484 | +{ |
|
476 | 485 | |
477 | 486 | $filter = [ |
478 | 487 | 'UNIQUEID=:UNIQUEID: AND endtime IS NULL AND answer IS NULL', |
@@ -528,7 +537,8 @@ discard block |
||
528 | 537 | * Обработка события ответа на переадресацию. Соединение абонентов. |
529 | 538 | * @param $data |
530 | 539 | */ |
531 | -function Action_transfer_dial_answer($data){ |
|
540 | +function Action_transfer_dial_answer($data) |
|
541 | +{ |
|
532 | 542 | $filter = [ |
533 | 543 | '(UNIQUEID=:UNIQUEID: OR UNIQUEID=:UNIQUEID_CHAN:) AND answer IS NULL AND endtime IS NULL', |
534 | 544 | 'bind' => [ |
@@ -553,7 +563,8 @@ discard block |
||
553 | 563 | * Завершение канала при прееадресации. |
554 | 564 | * @param $data |
555 | 565 | */ |
556 | -function Action_transfer_dial_hangup($data){ |
|
566 | +function Action_transfer_dial_hangup($data) |
|
567 | +{ |
|
557 | 568 | |
558 | 569 | $pos = stripos( $data['agi_channel'], 'local/'); |
559 | 570 | if($pos === false){ |
@@ -595,7 +606,7 @@ discard block |
||
595 | 606 | $subdir = date('Y/m/d/H/',strtotime($data_time)); |
596 | 607 | Cdr::MixMonitor($res->src_chan, $info['filename'], $subdir); |
597 | 608 | } |
598 | - }else if('' === $data['ANSWEREDTIME'] ){ |
|
609 | + } else if('' === $data['ANSWEREDTIME'] ){ |
|
599 | 610 | $filter = [ |
600 | 611 | 'linkedid=:linkedid: AND endtime IS NULL AND (src_chan=:src_chan: OR dst_chan=:dst_chan:)', |
601 | 612 | 'bind' => [ |
@@ -644,7 +655,8 @@ discard block |
||
644 | 655 | * Начало работы приложения. |
645 | 656 | * @param $data |
646 | 657 | */ |
647 | -function Action_dial_app($data){ |
|
658 | +function Action_dial_app($data) |
|
659 | +{ |
|
648 | 660 | Action_app_end($data); |
649 | 661 | Cdr::insert_data_to_db_m($data); |
650 | 662 | } |
@@ -653,7 +665,8 @@ discard block |
||
653 | 665 | * Завершение работы приложения. |
654 | 666 | * @param $data |
655 | 667 | */ |
656 | -function Action_app_end($data){ |
|
668 | +function Action_app_end($data) |
|
669 | +{ |
|
657 | 670 | $filter = [ |
658 | 671 | 'linkedid=:linkedid: AND is_app=1 AND endtime IS NULL', |
659 | 672 | 'bind' => [ |
@@ -676,7 +689,8 @@ discard block |
||
676 | 689 | * Вызов в нерабочее время. |
677 | 690 | * @param $data |
678 | 691 | */ |
679 | -function Action_dial_outworktimes($data){ |
|
692 | +function Action_dial_outworktimes($data) |
|
693 | +{ |
|
680 | 694 | Cdr::insert_data_to_db_m($data); |
681 | 695 | } |
682 | 696 | |
@@ -684,7 +698,8 @@ discard block |
||
684 | 698 | * Старт очереди. |
685 | 699 | * @param $data |
686 | 700 | */ |
687 | -function Action_queue_start($data){ |
|
701 | +function Action_queue_start($data) |
|
702 | +{ |
|
688 | 703 | |
689 | 704 | if($data['transfer'] == '1'){ |
690 | 705 | // Если это трансфер выполним поиск связанных данных. |
@@ -693,7 +708,7 @@ discard block |
||
693 | 708 | if(isset($data['start'])){ |
694 | 709 | // Это новая строка. |
695 | 710 | Cdr::insert_data_to_db_m($data); |
696 | - }else{ |
|
711 | + } else{ |
|
697 | 712 | // Требуется только обновление данных. |
698 | 713 | Cdr::update_data_in_db_m($data); |
699 | 714 | } |
@@ -704,7 +719,8 @@ discard block |
||
704 | 719 | * Событие входа в конференцкомнату. |
705 | 720 | * @param $data |
706 | 721 | */ |
707 | -function Action_meetme_dial($data){ |
|
722 | +function Action_meetme_dial($data) |
|
723 | +{ |
|
708 | 724 | Cdr::StopMixMonitor($data['src_chan']); |
709 | 725 | |
710 | 726 | if(strpos($data['src_chan'], 'internal-originate') !== false){ |
@@ -733,7 +749,7 @@ discard block |
||
733 | 749 | // Переопределяем идентификатор, это Originate на конференцию. |
734 | 750 | $m_data->save(); |
735 | 751 | } |
736 | - }else{ |
|
752 | + } else{ |
|
737 | 753 | Cdr::insert_data_to_db_m($data); |
738 | 754 | Action_app_end($data); |
739 | 755 | } |
@@ -743,7 +759,8 @@ discard block |
||
743 | 759 | * Снятие вызова с парковки. |
744 | 760 | * @param $data |
745 | 761 | */ |
746 | -function Action_unpark_call($data){ |
|
762 | +function Action_unpark_call($data) |
|
763 | +{ |
|
747 | 764 | $data['recordingfile'] = Cdr::MixMonitor($data['dst_chan'], $data['UNIQUEID']); |
748 | 765 | Cdr::insert_data_to_db_m($data); |
749 | 766 | if( is_array($data['data_parking']) ){ |
@@ -768,7 +785,8 @@ discard block |
||
768 | 785 | * Возвращаем вызов с парковки по таймауту. |
769 | 786 | * @param $data |
770 | 787 | */ |
771 | -function Action_unpark_call_timeout($data){ |
|
788 | +function Action_unpark_call_timeout($data) |
|
789 | +{ |
|
772 | 790 | Cdr::insert_data_to_db_m($data); |
773 | 791 | } |
774 | 792 | |
@@ -776,7 +794,8 @@ discard block |
||
776 | 794 | * Ответ агента очереди. |
777 | 795 | * @param $data |
778 | 796 | */ |
779 | -function Action_queue_answer($data){ |
|
797 | +function Action_queue_answer($data) |
|
798 | +{ |
|
780 | 799 | |
781 | 800 | $filter = [ |
782 | 801 | "UNIQUEID=:UNIQUEID: AND answer IS NULL", |
@@ -801,7 +820,8 @@ discard block |
||
801 | 820 | * Завершение работы очереди. |
802 | 821 | * @param $data |
803 | 822 | */ |
804 | -function Action_queue_end($data){ |
|
823 | +function Action_queue_end($data) |
|
824 | +{ |
|
805 | 825 | $filter = [ |
806 | 826 | "UNIQUEID=:UNIQUEID:", |
807 | 827 | 'bind' => [ |
@@ -829,7 +849,8 @@ discard block |
||
829 | 849 | * Завершение / уничтожение канала. |
830 | 850 | * @param $data |
831 | 851 | */ |
832 | -function Action_hangup_chan_meetme($data){ |
|
852 | +function Action_hangup_chan_meetme($data) |
|
853 | +{ |
|
833 | 854 | clearstatcache(); |
834 | 855 | $recordingfile = ''; |
835 | 856 | $dest_chan = "MeetMe:{$data['conference']}"; |
@@ -895,7 +916,8 @@ discard block |
||
895 | 916 | * Обработчик событий изменения состояния звонка. |
896 | 917 | * @param array | BeanstalkClient $message |
897 | 918 | */ |
898 | -$call_events = function ($message) { |
|
919 | +$call_events = function ($message) |
|
920 | +{ |
|
899 | 921 | $data = json_decode($message->getBody(), true); |
900 | 922 | $func_name = 'Action_'.$data['action']; |
901 | 923 | if( function_exists($func_name) ){ |
@@ -908,7 +930,8 @@ discard block |
||
908 | 930 | * Обработчик пинга. |
909 | 931 | * @param array | BeanstalkClient $message |
910 | 932 | */ |
911 | -$ping_worker = function ($message) { |
|
933 | +$ping_worker = function ($message) |
|
934 | +{ |
|
912 | 935 | $message->reply(json_encode($message->getBody().':pong')); |
913 | 936 | |
914 | 937 | set_global_settings(); |
@@ -918,7 +941,8 @@ discard block |
||
918 | 941 | * Получения CDR к обработке. |
919 | 942 | * @param array | BeanstalkClient $message |
920 | 943 | */ |
921 | -$update_cdr = function ($message){ |
|
944 | +$update_cdr = function ($message) |
|
945 | +{ |
|
922 | 946 | $q = $message->getBody(); |
923 | 947 | $data = json_decode($q, true); |
924 | 948 | $res = Cdr::update_data_in_db_m($data); |
@@ -928,18 +952,19 @@ discard block |
||
928 | 952 | /** |
929 | 953 | * @param array | BeanstalkClient $message |
930 | 954 | */ |
931 | -$select_cdr = function ($message){ |
|
955 | +$select_cdr = function ($message) |
|
956 | +{ |
|
932 | 957 | $q = $message->getBody(); |
933 | 958 | $filter = json_decode($q, true); |
934 | 959 | $res = null; |
935 | 960 | try{ |
936 | 961 | if(isset($filter['miko_tmp_db'])){ |
937 | 962 | $res = CallDetailRecordsTmp::find($filter); |
938 | - }else{ |
|
963 | + } else{ |
|
939 | 964 | $res = CallDetailRecords::find($filter); |
940 | 965 | } |
941 | 966 | $res_data = json_encode($res->toArray()); |
942 | - }catch (Exception $e){ |
|
967 | + } catch (Exception $e){ |
|
943 | 968 | $res_data = '[]'; |
944 | 969 | } |
945 | 970 | |
@@ -952,7 +977,7 @@ discard block |
||
952 | 977 | try{ |
953 | 978 | $res = CallDetailRecords::find($filter['add_pack_query']); |
954 | 979 | $res_data = json_encode($res->toArray()); |
955 | - }catch (Exception $e){ |
|
980 | + } catch (Exception $e){ |
|
956 | 981 | $res_data = '[]'; |
957 | 982 | } |
958 | 983 | } |
@@ -968,7 +993,8 @@ discard block |
||
968 | 993 | $message->reply($res_data); |
969 | 994 | }; |
970 | 995 | |
971 | -function set_global_settings(){ |
|
996 | +function set_global_settings() |
|
997 | +{ |
|
972 | 998 | global $g; |
973 | 999 | $config = new Config(); |
974 | 1000 | $g['record_calls'] = $config->get_general_settings('PBXRecordCalls'); |
@@ -977,7 +1003,8 @@ discard block |
||
977 | 1003 | } |
978 | 1004 | echo "starting...\n"; |
979 | 1005 | |
980 | -$err_handler = function ($m){ |
|
1006 | +$err_handler = function ($m) |
|
1007 | +{ |
|
981 | 1008 | Util::sys_log_msg("CDR_WORKER_ERROR", $m); |
982 | 1009 | }; |
983 | 1010 | |
@@ -995,7 +1022,7 @@ discard block |
||
995 | 1022 | $client->setErrorHendler($err_handler); |
996 | 1023 | |
997 | 1024 | $client->wait(); |
998 | - }catch (Exception $e){ |
|
1025 | + } catch (Exception $e){ |
|
999 | 1026 | $errorLogger = $g['error_logger']; |
1000 | 1027 | $errorLogger->captureException($e); |
1001 | 1028 | sleep(1); |
@@ -293,13 +293,13 @@ |
||
293 | 293 | // Вызов уже завершен. Не интересно. |
294 | 294 | continue; |
295 | 295 | } |
296 | - $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', NULL, false); |
|
296 | + $BRIDGEPEER = $am->GetVar($data_chan['chan'], 'BRIDGEPEER', null, false); |
|
297 | 297 | if(!in_array($BRIDGEPEER, $active_chans, true)){ |
298 | 298 | // Вызов уже завершен. Не интересно. |
299 | 299 | continue; |
300 | 300 | } |
301 | - $linkedid = $am->GetVar($data_chan['chan'], 'CDR(linkedid)', NULL, false); |
|
302 | - $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', NULL, false); |
|
301 | + $linkedid = $am->GetVar($data_chan['chan'], 'CDR(linkedid)', null, false); |
|
302 | + $CALLERID = $am->GetVar($BRIDGEPEER, 'CALLERID(num)', null, false); |
|
303 | 303 | if(!empty($linkedid) && $linkedid !== $data['linkedid']){ |
304 | 304 | $n_data['action'] = 'sip_transfer'; |
305 | 305 | $n_data['src_chan'] = $data_chan['out']?$data_chan['chan']:$BRIDGEPEER; |
@@ -40,11 +40,11 @@ discard block |
||
40 | 40 | ini_set('memory_limit', '300M'); |
41 | 41 | |
42 | 42 | $temp_dir = dirname($this->settings['res_file']); |
43 | - $this->progress_file = $temp_dir . '/progress'; |
|
44 | - $this->installed_file = $temp_dir . '/installed'; |
|
45 | - $this->error_file = $temp_dir . '/error'; |
|
43 | + $this->progress_file = $temp_dir.'/progress'; |
|
44 | + $this->installed_file = $temp_dir.'/installed'; |
|
45 | + $this->error_file = $temp_dir.'/error'; |
|
46 | 46 | |
47 | - if ( ! is_dir($temp_dir) && ! mkdir($temp_dir, 0777, true) && ! is_dir($temp_dir)) { |
|
47 | + if (!is_dir($temp_dir) && !mkdir($temp_dir, 0777, true) && !is_dir($temp_dir)) { |
|
48 | 48 | Util::sys_log_msg('FileDownloader', 'Error on create module folder'); |
49 | 49 | } |
50 | 50 | } |
@@ -106,18 +106,18 @@ discard block |
||
106 | 106 | */ |
107 | 107 | public function get_file() |
108 | 108 | { |
109 | - if ( ! $this->settings) { |
|
109 | + if (!$this->settings) { |
|
110 | 110 | return false; |
111 | 111 | } |
112 | - if(strpos($this->settings['url'], 'file://') !== FALSE){ |
|
112 | + if (strpos($this->settings['url'], 'file://') !== FALSE) { |
|
113 | 113 | // Это локальный файл. |
114 | 114 | $src_file = str_replace('file://', '', $this->settings['url']); |
115 | 115 | Util::mwexec("mv {$src_file} {$this->settings['res_file']}"); |
116 | 116 | |
117 | - if(file_exists($this->settings['res_file'])){ |
|
117 | + if (file_exists($this->settings['res_file'])) { |
|
118 | 118 | file_put_contents($this->progress_file, 100); |
119 | 119 | $result = true; |
120 | - }else{ |
|
120 | + } else { |
|
121 | 121 | file_put_contents($this->error_file, "Can not find module file {$src_file}", FILE_APPEND); |
122 | 122 | $result = false; |
123 | 123 | } |
@@ -178,15 +178,15 @@ discard block |
||
178 | 178 | */ |
179 | 179 | public function action() |
180 | 180 | { |
181 | - if ( ! $this->settings || ! isset($this->settings['action'])) { |
|
181 | + if (!$this->settings || !isset($this->settings['action'])) { |
|
182 | 182 | return; |
183 | 183 | } |
184 | - if ( ! file_exists($this->settings['res_file'])) { |
|
184 | + if (!file_exists($this->settings['res_file'])) { |
|
185 | 185 | file_put_contents($this->error_file, 'File does not uploaded', FILE_APPEND); |
186 | 186 | |
187 | 187 | return; |
188 | 188 | } |
189 | - if ( ! file_exists($this->settings['res_file']) || md5_file($this->settings['res_file']) !== $this->settings['md5']) { |
|
189 | + if (!file_exists($this->settings['res_file']) || md5_file($this->settings['res_file']) !== $this->settings['md5']) { |
|
190 | 190 | |
191 | 191 | if (file_exists($this->settings['res_file'])) { |
192 | 192 | unlink($this->settings['res_file']); |
@@ -200,7 +200,7 @@ discard block |
||
200 | 200 | if ('module_install' === $this->settings['action']) { |
201 | 201 | |
202 | 202 | $error = false; |
203 | - $currentModuleDir = $GLOBALS['g']['phalcon_settings']['application']['modulesDir'] . $this->settings['module']; |
|
203 | + $currentModuleDir = $GLOBALS['g']['phalcon_settings']['application']['modulesDir'].$this->settings['module']; |
|
204 | 204 | $needBackup = is_dir($currentModuleDir); |
205 | 205 | $path_class = "\\Modules\\{$this->settings['module']}\\setup\\PbxExtensionSetup"; |
206 | 206 | |
@@ -221,7 +221,7 @@ discard block |
||
221 | 221 | 'keepSettings' => 'true' |
222 | 222 | ]; |
223 | 223 | $data_string = json_encode($data); |
224 | - $ch = curl_init(); |
|
224 | + $ch = curl_init(); |
|
225 | 225 | curl_setopt($ch, CURLOPT_URL, $url); |
226 | 226 | curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); |
227 | 227 | curl_setopt($ch, CURLOPT_TIMEOUT, 15); |
@@ -230,7 +230,7 @@ discard block |
||
230 | 230 | curl_exec($ch); |
231 | 231 | curl_close($ch); |
232 | 232 | } |
233 | - } catch (Exception $error){ |
|
233 | + } catch (Exception $error) { |
|
234 | 234 | // Broken or very old module. Force uninstall. |
235 | 235 | Util::mwexec("rm -rf $currentModuleDir"); |
236 | 236 | } finally { |
@@ -243,9 +243,9 @@ discard block |
||
243 | 243 | Util::mwexec("7za e -spf -aoa -o$currentModuleDir {$this->settings['res_file']}"); |
244 | 244 | Util::mwexec("chown www:www -R $currentModuleDir"); |
245 | 245 | |
246 | - if ( ! $error && class_exists($path_class) && method_exists($path_class, 'installModule')) { |
|
246 | + if (!$error && class_exists($path_class) && method_exists($path_class, 'installModule')) { |
|
247 | 247 | $setup = new $path_class($this->settings['module']); |
248 | - if ( ! $setup->installModule()) { |
|
248 | + if (!$setup->installModule()) { |
|
249 | 249 | $error = true; |
250 | 250 | $result['data'] = 'Install error:'.implode('<br>', $setup->getMessages()); |
251 | 251 | } |
@@ -256,7 +256,7 @@ discard block |
||
256 | 256 | |
257 | 257 | if ($error) { |
258 | 258 | $result['result'] = 'Error'; |
259 | - file_put_contents($this->error_file, 'Install error ' . $result['data'], FILE_APPEND); |
|
259 | + file_put_contents($this->error_file, 'Install error '.$result['data'], FILE_APPEND); |
|
260 | 260 | } else { |
261 | 261 | $result['result'] = 'Success'; |
262 | 262 | file_put_contents($this->installed_file, ''); |
@@ -264,7 +264,7 @@ discard block |
||
264 | 264 | Util::restart_module_dependent_workers(); |
265 | 265 | Util::restart_worker('worker_api_commands'); |
266 | 266 | } |
267 | - Util::mwexec('rm -rf ' . $this->settings['res_file']); |
|
267 | + Util::mwexec('rm -rf '.$this->settings['res_file']); |
|
268 | 268 | } elseif ('upgrade_online' === $this->settings['action']) { |
269 | 269 | sleep(3); |
270 | 270 | unlink($this->progress_file); |
@@ -276,8 +276,8 @@ discard block |
||
276 | 276 | |
277 | 277 | if (count($argv) > 1 && file_exists($argv[1])) { |
278 | 278 | // php -dxdebug.remote_autostart=On -f /etc/inc/workers/worker_download.php /storage/usbdisk1/mikopbx/tmp/ModuleCTIClient/download_settings.json |
279 | - $PID = Util::get_pid_process($argv[1], '' . getmypid() . ' '); |
|
280 | - if ( ! empty($PID)) { |
|
279 | + $PID = Util::get_pid_process($argv[1], ''.getmypid().' '); |
|
280 | + if (!empty($PID)) { |
|
281 | 281 | echo 'Error start download script... '; |
282 | 282 | exit(4); |
283 | 283 | } |
@@ -117,7 +117,7 @@ |
||
117 | 117 | if(file_exists($this->settings['res_file'])){ |
118 | 118 | file_put_contents($this->progress_file, 100); |
119 | 119 | $result = true; |
120 | - }else{ |
|
120 | + } else{ |
|
121 | 121 | file_put_contents($this->error_file, "Can not find module file {$src_file}", FILE_APPEND); |
122 | 122 | $result = false; |
123 | 123 | } |
@@ -109,7 +109,7 @@ |
||
109 | 109 | if ( ! $this->settings) { |
110 | 110 | return false; |
111 | 111 | } |
112 | - if(strpos($this->settings['url'], 'file://') !== FALSE){ |
|
112 | + if(strpos($this->settings['url'], 'file://') !== false){ |
|
113 | 113 | // Это локальный файл. |
114 | 114 | $src_file = str_replace('file://', '', $this->settings['url']); |
115 | 115 | Util::mwexec("mv {$src_file} {$this->settings['res_file']}"); |
@@ -8,19 +8,19 @@ discard block |
||
8 | 8 | |
9 | 9 | require_once 'globals.php'; |
10 | 10 | $filename = "{$GLOBALS['g']['varetc_path']}/storage_device"; |
11 | -if(file_exists($filename)) { |
|
11 | +if (file_exists($filename)) { |
|
12 | 12 | $mount_point = file_get_contents($filename); |
13 | -}else{ |
|
13 | +} else { |
|
14 | 14 | exit(0); |
15 | 15 | } |
16 | -$out=[]; |
|
16 | +$out = []; |
|
17 | 17 | Util::mwexec("/bin/mount | /bin/busybox grep {$mount_point} | /bin/busybox awk '{print $1}' | head -n 1", $out); |
18 | -$dev = implode('',$out); |
|
18 | +$dev = implode('', $out); |
|
19 | 19 | |
20 | 20 | $s = new Storage(); |
21 | 21 | $MIN_SPACE = 100; // MB |
22 | 22 | $free_space = $s->get_free_space($dev); |
23 | -if($free_space > $MIN_SPACE){ |
|
23 | +if ($free_space > $MIN_SPACE) { |
|
24 | 24 | // Очистка диска не требуется. |
25 | 25 | exit(0); |
26 | 26 | } |
@@ -28,13 +28,13 @@ discard block |
||
28 | 28 | $out = []; |
29 | 29 | $count_dir = 1; |
30 | 30 | Util::mwexec("/bin/find {$monitor_dir}*/*/* -maxdepth 0 -type d -printf '%T+ %p\n' 2> /dev/null | /bin/sort | /bin/head -n 10 | /bin/busybox awk '{print $2}'", $out); |
31 | -foreach ($out as $dir_info){ |
|
32 | - if(!is_dir($dir_info)){ |
|
31 | +foreach ($out as $dir_info) { |
|
32 | + if (!is_dir($dir_info)) { |
|
33 | 33 | echo 'error'; |
34 | 34 | continue; |
35 | 35 | } |
36 | 36 | $free_space = $s->get_free_space($dev); |
37 | - if($free_space > $MIN_SPACE){ |
|
37 | + if ($free_space > $MIN_SPACE) { |
|
38 | 38 | // Очистка диска не требуется. |
39 | 39 | break; |
40 | 40 | } |
@@ -10,7 +10,7 @@ |
||
10 | 10 | $filename = "{$GLOBALS['g']['varetc_path']}/storage_device"; |
11 | 11 | if(file_exists($filename)) { |
12 | 12 | $mount_point = file_get_contents($filename); |
13 | -}else{ |
|
13 | +} else{ |
|
14 | 14 | exit(0); |
15 | 15 | } |
16 | 16 | $out=[]; |