@@ -90,8 +90,8 @@ discard block |
||
| 90 | 90 | } |
| 91 | 91 | $parameters['uploadDir'] = $di->getShared('config')->path('www.uploadDir'); |
| 92 | 92 | $parameters['tempDir'] = "{$parameters['uploadDir']}/{$parameters['resumableIdentifier']}"; |
| 93 | - if ( ! Util::mwMkdir($parameters['tempDir'])) { |
|
| 94 | - $res->messages[] = 'Temp dir does not exist ' . $parameters['tempDir']; |
|
| 93 | + if (!Util::mwMkdir($parameters['tempDir'])) { |
|
| 94 | + $res->messages[] = 'Temp dir does not exist '.$parameters['tempDir']; |
|
| 95 | 95 | |
| 96 | 96 | return $res; |
| 97 | 97 | } |
@@ -109,8 +109,8 @@ discard block |
||
| 109 | 109 | } |
| 110 | 110 | |
| 111 | 111 | foreach ($parameters['files'] as $file_data) { |
| 112 | - if ( ! self::moveUploadedPartToSeparateDir($parameters, $file_data)) { |
|
| 113 | - $res->messages[] = 'Does not found any uploaded chunks on with path ' . $file_data['file_path']; |
|
| 112 | + if (!self::moveUploadedPartToSeparateDir($parameters, $file_data)) { |
|
| 113 | + $res->messages[] = 'Does not found any uploaded chunks on with path '.$file_data['file_path']; |
|
| 114 | 114 | |
| 115 | 115 | return $res; |
| 116 | 116 | } |
@@ -138,7 +138,7 @@ discard block |
||
| 138 | 138 | */ |
| 139 | 139 | private static function moveUploadedPartToSeparateDir(array $parameters, array $file_data): bool |
| 140 | 140 | { |
| 141 | - if ( ! file_exists($file_data['file_path'])) { |
|
| 141 | + if (!file_exists($file_data['file_path'])) { |
|
| 142 | 142 | return false; |
| 143 | 143 | } |
| 144 | 144 | $factory = new StreamFactory(); |
@@ -171,7 +171,7 @@ discard block |
||
| 171 | 171 | { |
| 172 | 172 | $totalFilesOnServerSize = 0; |
| 173 | 173 | foreach (scandir($parameters['tempDir']) as $file) { |
| 174 | - $totalFilesOnServerSize += filesize($parameters['tempDir'] . '/' . $file); |
|
| 174 | + $totalFilesOnServerSize += filesize($parameters['tempDir'].'/'.$file); |
|
| 175 | 175 | } |
| 176 | 176 | |
| 177 | 177 | if ($totalFilesOnServerSize >= $parameters['resumableTotalSize']) { |
@@ -183,7 +183,7 @@ discard block |
||
| 183 | 183 | 'resumableTotalSize' => $parameters['resumableTotalSize'], |
| 184 | 184 | 'resumableTotalChunks' => $parameters['resumableTotalChunks'], |
| 185 | 185 | ]; |
| 186 | - $settings_file = "{$parameters['tempDir']}/merge_settings"; |
|
| 186 | + $settings_file = "{$parameters['tempDir']}/merge_settings"; |
|
| 187 | 187 | file_put_contents( |
| 188 | 188 | $settings_file, |
| 189 | 189 | json_encode($merge_settings, JSON_UNESCAPED_SLASHES | JSON_PRETTY_PRINT) |
@@ -220,22 +220,22 @@ discard block |
||
| 220 | 220 | $uploadDir = $di->getShared('config')->path('www.uploadDir'); |
| 221 | 221 | |
| 222 | 222 | $upload_id = $postData['id'] ?? null; |
| 223 | - $progress_dir = $uploadDir . '/' . $upload_id; |
|
| 224 | - $progress_file = $progress_dir . '/merging_progress'; |
|
| 223 | + $progress_dir = $uploadDir.'/'.$upload_id; |
|
| 224 | + $progress_file = $progress_dir.'/merging_progress'; |
|
| 225 | 225 | if (empty($upload_id)) { |
| 226 | 226 | $res->success = false; |
| 227 | 227 | $res->data['d_status_progress'] = '0'; |
| 228 | 228 | $res->data['d_status'] = 'ID_NOT_SET'; |
| 229 | 229 | $res->messages[] = 'Upload ID does not set'; |
| 230 | - } elseif ( ! file_exists($progress_file) && file_exists($progress_dir)) { |
|
| 230 | + } elseif (!file_exists($progress_file) && file_exists($progress_dir)) { |
|
| 231 | 231 | $res->success = true; |
| 232 | 232 | $res->data['d_status_progress'] = '0'; |
| 233 | 233 | $res->data['d_status'] = 'INPROGRESS'; |
| 234 | - } elseif ( ! file_exists($progress_dir)) { |
|
| 234 | + } elseif (!file_exists($progress_dir)) { |
|
| 235 | 235 | $res->success = false; |
| 236 | 236 | $res->data['d_status_progress'] = '0'; |
| 237 | 237 | $res->data['d_status'] = 'NOT_FOUND'; |
| 238 | - $res->messages[] = 'Does not found anything with path: ' . $progress_dir; |
|
| 238 | + $res->messages[] = 'Does not found anything with path: '.$progress_dir; |
|
| 239 | 239 | } elseif ('100' === file_get_contents($progress_file)) { |
| 240 | 240 | $res->success = true; |
| 241 | 241 | $res->data['d_status_progress'] = '100'; |
@@ -261,14 +261,14 @@ discard block |
||
| 261 | 261 | $res = new PBXApiResult(); |
| 262 | 262 | $res->processor = __METHOD__; |
| 263 | 263 | $extension = Util::getExtensionOfFile($filePath); |
| 264 | - if ( ! in_array($extension, ['mp3', 'wav', 'alaw'])) { |
|
| 264 | + if (!in_array($extension, ['mp3', 'wav', 'alaw'])) { |
|
| 265 | 265 | $res->success = false; |
| 266 | 266 | $res->messages[] = "It is forbidden to remove the file type $extension."; |
| 267 | 267 | |
| 268 | 268 | return $res; |
| 269 | 269 | } |
| 270 | 270 | |
| 271 | - if ( ! file_exists($filePath)) { |
|
| 271 | + if (!file_exists($filePath)) { |
|
| 272 | 272 | $res->success = true; |
| 273 | 273 | $res->data['message'] = "File '{$filePath}' already deleted"; |
| 274 | 274 | |
@@ -278,13 +278,13 @@ discard block |
||
| 278 | 278 | $out = []; |
| 279 | 279 | |
| 280 | 280 | $arrDeletedFiles = [ |
| 281 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".wav"), |
|
| 282 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".mp3"), |
|
| 283 | - escapeshellarg(Util::trimExtensionForFile($filePath) . ".alaw"), |
|
| 281 | + escapeshellarg(Util::trimExtensionForFile($filePath).".wav"), |
|
| 282 | + escapeshellarg(Util::trimExtensionForFile($filePath).".mp3"), |
|
| 283 | + escapeshellarg(Util::trimExtensionForFile($filePath).".alaw"), |
|
| 284 | 284 | ]; |
| 285 | 285 | |
| 286 | 286 | $rmPath = Util::which('rm'); |
| 287 | - Util::mwExec("{$rmPath} -rf " . implode(' ', $arrDeletedFiles), $out); |
|
| 287 | + Util::mwExec("{$rmPath} -rf ".implode(' ', $arrDeletedFiles), $out); |
|
| 288 | 288 | if (file_exists($filePath)) { |
| 289 | 289 | $res->success = false; |
| 290 | 290 | $res->messages = $out; |
@@ -317,13 +317,13 @@ discard block |
||
| 317 | 317 | $cat = Util::which('cat'); |
| 318 | 318 | $di = Di::getDefault(); |
| 319 | 319 | $dirsConfig = $di->getShared('config'); |
| 320 | - $filenameTmp = $dirsConfig->path('www.downloadCacheDir') . '/' . __FUNCTION__ . '_' . time() . '.conf'; |
|
| 320 | + $filenameTmp = $dirsConfig->path('www.downloadCacheDir').'/'.__FUNCTION__.'_'.time().'.conf'; |
|
| 321 | 321 | $cmd = "{$cat} {$filename} > {$filenameTmp}"; |
| 322 | 322 | Util::mwExec("{$cmd}; chown www:www {$filenameTmp}"); |
| 323 | 323 | $res->data['filename'] = $filenameTmp; |
| 324 | 324 | } else { |
| 325 | 325 | $res->success = false; |
| 326 | - $res->messages[] = 'No access to the file ' . $filename; |
|
| 326 | + $res->messages[] = 'No access to the file '.$filename; |
|
| 327 | 327 | } |
| 328 | 328 | |
| 329 | 329 | return $res; |
@@ -392,7 +392,7 @@ discard block |
||
| 392 | 392 | $res->success = true; |
| 393 | 393 | |
| 394 | 394 | $firmwareDirTmp = dirname($imgFileName); |
| 395 | - $progress_file = $firmwareDirTmp . '/progress'; |
|
| 395 | + $progress_file = $firmwareDirTmp.'/progress'; |
|
| 396 | 396 | |
| 397 | 397 | // Wait until download process started |
| 398 | 398 | $d_pid = Util::getPidOfProcess("{$firmwareDirTmp}/download_settings.json"); |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $error = trim(file_get_contents("{$firmwareDirTmp}/error")); |
| 405 | 405 | } |
| 406 | 406 | |
| 407 | - if ( ! file_exists($progress_file)) { |
|
| 407 | + if (!file_exists($progress_file)) { |
|
| 408 | 408 | $res->data['d_status_progress'] = '0'; |
| 409 | 409 | $res->messages[] = 'NOT_FOUND'; |
| 410 | 410 | $res->success = false; |
@@ -508,11 +508,11 @@ discard block |
||
| 508 | 508 | } else { |
| 509 | 509 | $tempDir = '/tmp'; |
| 510 | 510 | } |
| 511 | - $moduleDirTmp = $tempDir . '/' . $moduleUniqueID; |
|
| 512 | - $progress_file = $moduleDirTmp . '/progress'; |
|
| 511 | + $moduleDirTmp = $tempDir.'/'.$moduleUniqueID; |
|
| 512 | + $progress_file = $moduleDirTmp.'/progress'; |
|
| 513 | 513 | $error = ''; |
| 514 | - if (file_exists($moduleDirTmp . '/error')) { |
|
| 515 | - $error = trim(file_get_contents($moduleDirTmp . '/error')); |
|
| 514 | + if (file_exists($moduleDirTmp.'/error')) { |
|
| 515 | + $error = trim(file_get_contents($moduleDirTmp.'/error')); |
|
| 516 | 516 | } |
| 517 | 517 | |
| 518 | 518 | // Wait until download process started |
@@ -521,7 +521,7 @@ discard block |
||
| 521 | 521 | usleep(500000); |
| 522 | 522 | } |
| 523 | 523 | |
| 524 | - if ( ! file_exists($progress_file)) { |
|
| 524 | + if (!file_exists($progress_file)) { |
|
| 525 | 525 | $res->data['d_status_progress'] = '0'; |
| 526 | 526 | $res->data['d_status'] = 'NOT_FOUND'; |
| 527 | 527 | $res->success = false; |
@@ -529,7 +529,7 @@ discard block |
||
| 529 | 529 | $res->data['d_status'] = 'DOWNLOAD_ERROR'; |
| 530 | 530 | $res->data['d_status_progress'] = file_get_contents($progress_file); |
| 531 | 531 | $res->data['d_error'] = $error; |
| 532 | - $res->messages[] = file_get_contents($moduleDirTmp . '/error'); |
|
| 532 | + $res->messages[] = file_get_contents($moduleDirTmp.'/error'); |
|
| 533 | 533 | $res->success = false; |
| 534 | 534 | } elseif ('100' === file_get_contents($progress_file)) { |
| 535 | 535 | $res->data['d_status_progress'] = '100'; |
@@ -538,11 +538,11 @@ discard block |
||
| 538 | 538 | $res->success = true; |
| 539 | 539 | } else { |
| 540 | 540 | $res->data['d_status_progress'] = file_get_contents($progress_file); |
| 541 | - $d_pid = Util::getPidOfProcess($moduleDirTmp . '/download_settings.json'); |
|
| 541 | + $d_pid = Util::getPidOfProcess($moduleDirTmp.'/download_settings.json'); |
|
| 542 | 542 | if (empty($d_pid)) { |
| 543 | 543 | $res->data['d_status'] = 'DOWNLOAD_ERROR'; |
| 544 | - if (file_exists($moduleDirTmp . '/error')) { |
|
| 545 | - $res->messages[] = file_get_contents($moduleDirTmp . '/error'); |
|
| 544 | + if (file_exists($moduleDirTmp.'/error')) { |
|
| 545 | + $res->messages[] = file_get_contents($moduleDirTmp.'/error'); |
|
| 546 | 546 | } else { |
| 547 | 547 | $res->messages[] = "Download process interrupted at {$res->data['d_status_progress']}%"; |
| 548 | 548 | } |
@@ -573,13 +573,13 @@ discard block |
||
| 573 | 573 | $grepPath = Util::which('grep'); |
| 574 | 574 | $echoPath = Util::which('echo'); |
| 575 | 575 | $awkPath = Util::which('awk'); |
| 576 | - $cmd = 'f="' . $filePath . '"; p=`' . $sevenZaPath . ' l $f | ' . $grepPath . ' module.json`;if [ "$?" == "0" ]; then ' . $sevenZaPath . ' -so e -y -r $f `' . $echoPath . ' $p | ' . $awkPath . ' -F" " \'{print $6}\'`; fi'; |
|
| 576 | + $cmd = 'f="'.$filePath.'"; p=`'.$sevenZaPath.' l $f | '.$grepPath.' module.json`;if [ "$?" == "0" ]; then '.$sevenZaPath.' -so e -y -r $f `'.$echoPath.' $p | '.$awkPath.' -F" " \'{print $6}\'`; fi'; |
|
| 577 | 577 | |
| 578 | 578 | Util::mwExec($cmd, $out); |
| 579 | 579 | $settings = json_decode(implode("\n", $out), true); |
| 580 | 580 | |
| 581 | 581 | $moduleUniqueID = $settings['moduleUniqueID'] ?? null; |
| 582 | - if ( ! $moduleUniqueID) { |
|
| 582 | + if (!$moduleUniqueID) { |
|
| 583 | 583 | $res->messages[] = 'The" moduleUniqueID " in the module file is not described.the json or file does not exist.'; |
| 584 | 584 | |
| 585 | 585 | return $res; |
@@ -41,12 +41,12 @@ discard block |
||
| 41 | 41 | ini_set('memory_limit', '300M'); |
| 42 | 42 | |
| 43 | 43 | $temp_dir = dirname($this->settings['res_file']); |
| 44 | - $this->progress_file = $temp_dir . '/progress'; |
|
| 45 | - $this->error_file = $temp_dir . '/error'; |
|
| 44 | + $this->progress_file = $temp_dir.'/progress'; |
|
| 45 | + $this->error_file = $temp_dir.'/error'; |
|
| 46 | 46 | |
| 47 | 47 | $result = $this->getFile(); |
| 48 | 48 | $result = $result && $this->checkFile(); |
| 49 | - if ( ! $result) { |
|
| 49 | + if (!$result) { |
|
| 50 | 50 | Util::sysLogMsg(__CLASS__, 'Download error...'); |
| 51 | 51 | } |
| 52 | 52 | } |
@@ -62,7 +62,7 @@ discard block |
||
| 62 | 62 | if (file_exists($this->settings['res_file'])) { |
| 63 | 63 | unlink($this->settings['res_file']); |
| 64 | 64 | } |
| 65 | - if (isset($this->settings['size'])){ |
|
| 65 | + if (isset($this->settings['size'])) { |
|
| 66 | 66 | $this->file_size = $this->settings['size']; |
| 67 | 67 | } else { |
| 68 | 68 | $this->file_size = $this->remoteFileSize($this->settings['url']); |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | |
| 73 | 73 | $fp = fopen($this->settings['res_file'], 'w'); |
| 74 | 74 | $ch = curl_init(); |
| 75 | - if ( ! is_resource($ch)) { |
|
| 75 | + if (!is_resource($ch)) { |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | curl_setopt($ch, CURLOPT_FILE, $fp); |
@@ -122,7 +122,7 @@ discard block |
||
| 122 | 122 | */ |
| 123 | 123 | public function checkFile(): bool |
| 124 | 124 | { |
| 125 | - if ( ! file_exists($this->settings['res_file'])) { |
|
| 125 | + if (!file_exists($this->settings['res_file'])) { |
|
| 126 | 126 | file_put_contents($this->error_file, 'File did not upload', FILE_APPEND); |
| 127 | 127 | |
| 128 | 128 | return false; |
@@ -19,13 +19,13 @@ discard block |
||
| 19 | 19 | public function start($argv): void |
| 20 | 20 | { |
| 21 | 21 | $settings_file = trim($argv[1]); |
| 22 | - if ( ! file_exists($settings_file)) { |
|
| 22 | + if (!file_exists($settings_file)) { |
|
| 23 | 23 | Util::sysLogMsg(__CLASS__, 'File with settings not found'); |
| 24 | 24 | |
| 25 | 25 | return; |
| 26 | 26 | } |
| 27 | 27 | $settings = json_decode(file_get_contents($settings_file), true); |
| 28 | - $progress_file = $settings['tempDir'] . '/merging_progress'; |
|
| 28 | + $progress_file = $settings['tempDir'].'/merging_progress'; |
|
| 29 | 29 | $this->mergeFilesInDirectory( |
| 30 | 30 | $settings['tempDir'], |
| 31 | 31 | $settings['resumableFilename'], |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | |
| 37 | 37 | // Check filesize is equal uploaded size |
| 38 | 38 | $resultFileSize = filesize($settings['fullUploadedFileName']); |
| 39 | - if ((int)$settings['resumableTotalSize'] === $resultFileSize) { |
|
| 39 | + if ((int) $settings['resumableTotalSize'] === $resultFileSize) { |
|
| 40 | 40 | file_put_contents($progress_file, '100'); |
| 41 | 41 | } else { |
| 42 | 42 | Util::sysLogMsg( |
@@ -47,7 +47,7 @@ discard block |
||
| 47 | 47 | |
| 48 | 48 | // Delete uploaded file after 10 minutes |
| 49 | 49 | Util::mwExecBg( |
| 50 | - '/sbin/shell_functions.sh killprocesses ' . $settings['tempDir'] . ' -TERM 0;rm -rf ' . $settings['tempDir'], |
|
| 50 | + '/sbin/shell_functions.sh killprocesses '.$settings['tempDir'].' -TERM 0;rm -rf '.$settings['tempDir'], |
|
| 51 | 51 | '/dev/null', |
| 52 | 52 | 600 |
| 53 | 53 | ); |
@@ -73,7 +73,7 @@ discard block |
||
| 73 | 73 | // Restore original file from chunks |
| 74 | 74 | if (($fp = fopen($result_file, 'w')) !== false) { |
| 75 | 75 | for ($i = 1; $i <= $total_files; $i++) { |
| 76 | - $tmp_file = $tempDir . '/' . $fileName . '.part' . $i; |
|
| 76 | + $tmp_file = $tempDir.'/'.$fileName.'.part'.$i; |
|
| 77 | 77 | fwrite($fp, file_get_contents($tmp_file)); |
| 78 | 78 | unlink($tmp_file); |
| 79 | 79 | $currentProgress = round($i / $total_files * 100); |
@@ -82,11 +82,11 @@ discard block |
||
| 82 | 82 | } |
| 83 | 83 | fclose($fp); |
| 84 | 84 | } else { |
| 85 | - Util::sysLogMsg('UploadFile', 'cannot create the destination file - ' . $result_file); |
|
| 85 | + Util::sysLogMsg('UploadFile', 'cannot create the destination file - '.$result_file); |
|
| 86 | 86 | |
| 87 | 87 | return; |
| 88 | 88 | } |
| 89 | - Util::sysLogMsg('UploadFile', 'destination file - ' . $result_file); |
|
| 89 | + Util::sysLogMsg('UploadFile', 'destination file - '.$result_file); |
|
| 90 | 90 | } |
| 91 | 91 | } |
| 92 | 92 | |
@@ -41,7 +41,7 @@ |
||
| 41 | 41 | } else { |
| 42 | 42 | Util::sysLogMsg( |
| 43 | 43 | 'UploadFile', |
| 44 | - "File {$settings['fullUploadedFileName']} size {$resultFileSize} does not equal {$settings['resumableTotalSize']}" |
|
| 44 | + "file {$settings['fullUploadedFileName']} size {$resultFileSize} does not equal {$settings['resumableTotalSize']}" |
|
| 45 | 45 | ); |
| 46 | 46 | } |
| 47 | 47 | |
@@ -36,7 +36,7 @@ discard block |
||
| 36 | 36 | { |
| 37 | 37 | $activeProcesses = Util::getPidOfProcess(static::class, getmypid()); |
| 38 | 38 | if ($this->maxProc === 1) { |
| 39 | - if ( ! empty($activeProcesses)) { |
|
| 39 | + if (!empty($activeProcesses)) { |
|
| 40 | 40 | $killApp = Util::which('kill'); |
| 41 | 41 | // Завершаем старый процесс. |
| 42 | 42 | Util::mwExec("{$killApp} {$activeProcesses}"); |
@@ -56,7 +56,7 @@ discard block |
||
| 56 | 56 | $killApp = Util::which('kill'); |
| 57 | 57 | // Завершим лишние |
| 58 | 58 | while ($countProc >= 0) { |
| 59 | - if ( ! isset($processes[$countProc])) { |
|
| 59 | + if (!isset($processes[$countProc])) { |
|
| 60 | 60 | break; |
| 61 | 61 | } |
| 62 | 62 | // Завершаем старый процесс. |
@@ -104,7 +104,7 @@ discard block |
||
| 104 | 104 | */ |
| 105 | 105 | public function pingCallBack(BeanstalkClient $message): void |
| 106 | 106 | { |
| 107 | - $message->reply(json_encode($message->getBody() . ':pong')); |
|
| 107 | + $message->reply(json_encode($message->getBody().':pong')); |
|
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | /** |