@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | function tpCreateDatabaseBackup(array $SETTINGS, string $encryptionKey = '', array $options = []): array |
| 56 | 56 | { |
| 57 | 57 | // Ensure required dependencies are loaded |
| 58 | - $mainFunctionsPath = __DIR__ . '/main.functions.php'; |
|
| 58 | + $mainFunctionsPath = __DIR__.'/main.functions.php'; |
|
| 59 | 59 | if (!function_exists('GenerateCryptKey') && is_file($mainFunctionsPath)) { |
| 60 | 60 | require_once $mainFunctionsPath; |
| 61 | 61 | } |
@@ -64,9 +64,9 @@ discard block |
||
| 64 | 64 | } |
| 65 | 65 | |
| 66 | 66 | $outputDir = $options['output_dir'] ?? ($SETTINGS['path_to_files_folder'] ?? ''); |
| 67 | - $prefix = (string)($options['filename_prefix'] ?? ''); |
|
| 68 | - $chunkRows = (int)($options['chunk_rows'] ?? 1000); |
|
| 69 | - $flushEvery = (int)($options['flush_every_inserts'] ?? 200); |
|
| 67 | + $prefix = (string) ($options['filename_prefix'] ?? ''); |
|
| 68 | + $chunkRows = (int) ($options['chunk_rows'] ?? 1000); |
|
| 69 | + $flushEvery = (int) ($options['flush_every_inserts'] ?? 200); |
|
| 70 | 70 | $includeTables = $options['include_tables'] ?? []; |
| 71 | 71 | $excludeTables = $options['exclude_tables'] ?? []; |
| 72 | 72 | |
@@ -77,7 +77,7 @@ discard block |
||
| 77 | 77 | 'filepath' => '', |
| 78 | 78 | 'encrypted' => false, |
| 79 | 79 | 'size_bytes' => 0, |
| 80 | - 'message' => 'Backup folder is not writable or not found: ' . $outputDir, |
|
| 80 | + 'message' => 'Backup folder is not writable or not found: '.$outputDir, |
|
| 81 | 81 | ]; |
| 82 | 82 | } |
| 83 | 83 | |
@@ -86,8 +86,8 @@ discard block |
||
| 86 | 86 | ? GenerateCryptKey(20, false, true, true, false, true) |
| 87 | 87 | : bin2hex(random_bytes(10)); |
| 88 | 88 | |
| 89 | - $filename = $prefix . time() . '-' . $token . '.sql'; |
|
| 90 | - $filepath = rtrim($outputDir, '/') . '/' . $filename; |
|
| 89 | + $filename = $prefix.time().'-'.$token.'.sql'; |
|
| 90 | + $filepath = rtrim($outputDir, '/').'/'.$filename; |
|
| 91 | 91 | |
| 92 | 92 | $handle = @fopen($filepath, 'w+'); |
| 93 | 93 | if ($handle === false) { |
@@ -97,7 +97,7 @@ discard block |
||
| 97 | 97 | 'filepath' => $filepath, |
| 98 | 98 | 'encrypted' => false, |
| 99 | 99 | 'size_bytes' => 0, |
| 100 | - 'message' => 'Could not create backup file: ' . $filepath, |
|
| 100 | + 'message' => 'Could not create backup file: '.$filepath, |
|
| 101 | 101 | ]; |
| 102 | 102 | } |
| 103 | 103 | |
@@ -130,22 +130,22 @@ discard block |
||
| 130 | 130 | } |
| 131 | 131 | |
| 132 | 132 | // Write drop and creation |
| 133 | - fwrite($handle, 'DROP TABLE IF EXISTS `' . $tableName . "`;\n"); |
|
| 133 | + fwrite($handle, 'DROP TABLE IF EXISTS `'.$tableName."`;\n"); |
|
| 134 | 134 | |
| 135 | - $row2 = DB::queryFirstRow('SHOW CREATE TABLE `' . $tableName . '`'); |
|
| 135 | + $row2 = DB::queryFirstRow('SHOW CREATE TABLE `'.$tableName.'`'); |
|
| 136 | 136 | if (!is_array($row2) || empty($row2['Create Table'])) { |
| 137 | 137 | // Skip table if structure cannot be fetched |
| 138 | 138 | fwrite($handle, "\n"); |
| 139 | 139 | continue; |
| 140 | 140 | } |
| 141 | 141 | |
| 142 | - fwrite($handle, $row2['Create Table'] . ";\n\n"); |
|
| 142 | + fwrite($handle, $row2['Create Table'].";\n\n"); |
|
| 143 | 143 | |
| 144 | 144 | // Process table data in chunks to reduce memory usage |
| 145 | 145 | $offset = 0; |
| 146 | 146 | while (true) { |
| 147 | 147 | $rows = DB::query( |
| 148 | - 'SELECT * FROM `' . $tableName . '` LIMIT %i OFFSET %i', |
|
| 148 | + 'SELECT * FROM `'.$tableName.'` LIMIT %i OFFSET %i', |
|
| 149 | 149 | $chunkRows, |
| 150 | 150 | $offset |
| 151 | 151 | ); |
@@ -174,10 +174,10 @@ discard block |
||
| 174 | 174 | |
| 175 | 175 | // Escape and keep newlines |
| 176 | 176 | $value = addslashes(preg_replace("/\n/", '\\n', $value)); |
| 177 | - $values[] = '"' . $value . '"'; |
|
| 177 | + $values[] = '"'.$value.'"'; |
|
| 178 | 178 | } |
| 179 | 179 | |
| 180 | - $insertQuery = 'INSERT INTO `' . $tableName . '` VALUES(' . implode(',', $values) . ");\n"; |
|
| 180 | + $insertQuery = 'INSERT INTO `'.$tableName.'` VALUES('.implode(',', $values).");\n"; |
|
| 181 | 181 | fwrite($handle, $insertQuery); |
| 182 | 182 | |
| 183 | 183 | $insertCount++; |
@@ -203,7 +203,7 @@ discard block |
||
| 203 | 203 | 'filepath' => $filepath, |
| 204 | 204 | 'encrypted' => false, |
| 205 | 205 | 'size_bytes' => 0, |
| 206 | - 'message' => 'Backup failed: ' . $e->getMessage(), |
|
| 206 | + 'message' => 'Backup failed: '.$e->getMessage(), |
|
| 207 | 207 | ]; |
| 208 | 208 | } |
| 209 | 209 | |
@@ -212,7 +212,7 @@ discard block |
||
| 212 | 212 | // Encrypt the file if key provided |
| 213 | 213 | $encrypted = false; |
| 214 | 214 | if ($encryptionKey !== '') { |
| 215 | - $tmpPath = rtrim($outputDir, '/') . '/defuse_temp_' . $filename; |
|
| 215 | + $tmpPath = rtrim($outputDir, '/').'/defuse_temp_'.$filename; |
|
| 216 | 216 | |
| 217 | 217 | if (!function_exists('prepareFileWithDefuse')) { |
| 218 | 218 | @unlink($filepath); |
@@ -238,7 +238,7 @@ discard block |
||
| 238 | 238 | 'filepath' => $filepath, |
| 239 | 239 | 'encrypted' => false, |
| 240 | 240 | 'size_bytes' => 0, |
| 241 | - 'message' => 'Encryption failed: ' . (is_string($ret) ? $ret : 'unknown error'), |
|
| 241 | + 'message' => 'Encryption failed: '.(is_string($ret) ? $ret : 'unknown error'), |
|
| 242 | 242 | ]; |
| 243 | 243 | } |
| 244 | 244 | |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | |
| 308 | 308 | if ($isUtf8 === false) { |
| 309 | 309 | // ASCII safe fallback |
| 310 | - return '[hex]' . bin2hex($str); |
|
| 310 | + return '[hex]'.bin2hex($str); |
|
| 311 | 311 | } |
| 312 | 312 | |
| 313 | 313 | // Strip ASCII control chars |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | |
| 347 | 347 | if (is_array($ret)) { |
| 348 | 348 | $hasError = !empty($ret['error']); |
| 349 | - $msg = tpSafeUtf8String((string)($ret['message'] ?? $ret['details'] ?? $ret['error'] ?? '')); |
|
| 349 | + $msg = tpSafeUtf8String((string) ($ret['message'] ?? $ret['details'] ?? $ret['error'] ?? '')); |
|
| 350 | 350 | return ['success' => !$hasError, 'message' => $msg]; |
| 351 | 351 | } |
| 352 | 352 | |
@@ -376,7 +376,7 @@ discard block |
||
| 376 | 376 | ): array { |
| 377 | 377 | $lastMsg = ''; |
| 378 | 378 | foreach ($candidateKeys as $k) { |
| 379 | - $k = (string)$k; |
|
| 379 | + $k = (string) $k; |
|
| 380 | 380 | if ($k === '') { |
| 381 | 381 | continue; |
| 382 | 382 | } |
@@ -390,7 +390,7 @@ discard block |
||
| 390 | 390 | if (!empty($r['success'])) { |
| 391 | 391 | return ['success' => true, 'message' => '', 'key_used' => $k]; |
| 392 | 392 | } |
| 393 | - $lastMsg = tpSafeUtf8String((string)($r['message'] ?? '')); |
|
| 393 | + $lastMsg = tpSafeUtf8String((string) ($r['message'] ?? '')); |
|
| 394 | 394 | } |
| 395 | 395 | |
| 396 | 396 | return ['success' => false, 'message' => ($lastMsg !== '' ? $lastMsg : 'Unable to decrypt')]; |
@@ -40,7 +40,7 @@ discard block |
||
| 40 | 40 | |
| 41 | 41 | // Load functions |
| 42 | 42 | require_once 'main.functions.php'; |
| 43 | -require_once __DIR__ . '/backup.functions.php'; |
|
| 43 | +require_once __DIR__.'/backup.functions.php'; |
|
| 44 | 44 | $session = SessionManager::getSession(); |
| 45 | 45 | |
| 46 | 46 | |
@@ -105,7 +105,7 @@ discard block |
||
| 105 | 105 | ) { |
| 106 | 106 | // Not allowed page |
| 107 | 107 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 108 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 108 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 109 | 109 | exit; |
| 110 | 110 | } |
| 111 | 111 | } |
@@ -145,7 +145,7 @@ discard block |
||
| 145 | 145 | function tpGetSettingsValue(string $key, string $default = ''): string |
| 146 | 146 | { |
| 147 | 147 | $val = DB::queryFirstField( |
| 148 | - 'SELECT valeur FROM ' . prefixTable('misc') . ' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 148 | + 'SELECT valeur FROM '.prefixTable('misc').' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 149 | 149 | 'settings', |
| 150 | 150 | $key |
| 151 | 151 | ); |
@@ -159,12 +159,12 @@ discard block |
||
| 159 | 159 | function tpUpsertSettingsValue(string $key, string $value): void |
| 160 | 160 | { |
| 161 | 161 | $exists = DB::queryFirstField( |
| 162 | - 'SELECT 1 FROM ' . prefixTable('misc') . ' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 162 | + 'SELECT 1 FROM '.prefixTable('misc').' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 163 | 163 | 'settings', |
| 164 | 164 | $key |
| 165 | 165 | ); |
| 166 | 166 | |
| 167 | - if ((int)$exists === 1) { |
|
| 167 | + if ((int) $exists === 1) { |
|
| 168 | 168 | DB::update( |
| 169 | 169 | prefixTable('misc'), |
| 170 | 170 | ['valeur' => $value], |
@@ -186,7 +186,7 @@ discard block |
||
| 186 | 186 | function tpGetAdminTimezoneName(): string |
| 187 | 187 | { |
| 188 | 188 | $tz = DB::queryFirstField( |
| 189 | - 'SELECT valeur FROM ' . prefixTable('misc') . ' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 189 | + 'SELECT valeur FROM '.prefixTable('misc').' WHERE type=%s AND intitule=%s LIMIT 1', |
|
| 190 | 190 | 'admin', |
| 191 | 191 | 'timezone' |
| 192 | 192 | ); |
@@ -233,14 +233,14 @@ discard block |
||
| 233 | 233 | exit; |
| 234 | 234 | } |
| 235 | 235 | |
| 236 | - $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 237 | - $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/') . '/backups'); |
|
| 238 | - $fp = rtrim($dir, '/') . '/' . $get_file; |
|
| 236 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 237 | + $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/').'/backups'); |
|
| 238 | + $fp = rtrim($dir, '/').'/'.$get_file; |
|
| 239 | 239 | |
| 240 | 240 | $dirReal = realpath($dir); |
| 241 | 241 | $fpReal = realpath($fp); |
| 242 | 242 | |
| 243 | - if ($dirReal === false || $fpReal === false || strpos($fpReal, $dirReal . DIRECTORY_SEPARATOR) !== 0 || is_file($fpReal) === false) { |
|
| 243 | + if ($dirReal === false || $fpReal === false || strpos($fpReal, $dirReal.DIRECTORY_SEPARATOR) !== 0 || is_file($fpReal) === false) { |
|
| 244 | 244 | header('HTTP/1.1 404 Not Found'); |
| 245 | 245 | exit; |
| 246 | 246 | } |
@@ -256,13 +256,13 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | header('Content-Description: File Transfer'); |
| 258 | 258 | header('Content-Type: application/octet-stream'); |
| 259 | - header('Content-Disposition: attachment; filename="' . $get_file . '"'); |
|
| 259 | + header('Content-Disposition: attachment; filename="'.$get_file.'"'); |
|
| 260 | 260 | header('Content-Transfer-Encoding: binary'); |
| 261 | 261 | header('Expires: 0'); |
| 262 | 262 | header('Cache-Control: private, must-revalidate'); |
| 263 | 263 | header('Pragma: public'); |
| 264 | 264 | if ($size > 0) { |
| 265 | - header('Content-Length: ' . $size); |
|
| 265 | + header('Content-Length: '.$size); |
|
| 266 | 266 | } |
| 267 | 267 | |
| 268 | 268 | readfile($fpReal); |
@@ -300,7 +300,7 @@ discard block |
||
| 300 | 300 | // Prepare variables |
| 301 | 301 | $encryptionKey = filter_var($dataReceived['encryptionKey'] ?? '', FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 302 | 302 | |
| 303 | - require_once __DIR__ . '/backup.functions.php'; |
|
| 303 | + require_once __DIR__.'/backup.functions.php'; |
|
| 304 | 304 | |
| 305 | 305 | $backupResult = tpCreateDatabaseBackup($SETTINGS, $encryptionKey); |
| 306 | 306 | |
@@ -334,9 +334,9 @@ discard block |
||
| 334 | 334 | array( |
| 335 | 335 | 'error' => false, |
| 336 | 336 | 'message' => '', |
| 337 | - 'download' => 'sources/downloadFile.php?name=' . urlencode($filename) . |
|
| 338 | - '&action=backup&file=' . $filename . '&type=sql&key=' . $session->get('key') . '&key_tmp=' . |
|
| 339 | - $session->get('user-key_tmp') . '&pathIsFiles=1', |
|
| 337 | + 'download' => 'sources/downloadFile.php?name='.urlencode($filename). |
|
| 338 | + '&action=backup&file='.$filename.'&type=sql&key='.$session->get('key').'&key_tmp='. |
|
| 339 | + $session->get('user-key_tmp').'&pathIsFiles=1', |
|
| 340 | 340 | ), |
| 341 | 341 | 'encode' |
| 342 | 342 | ); |
@@ -346,7 +346,7 @@ discard block |
||
| 346 | 346 | * ============================================================ */ |
| 347 | 347 | |
| 348 | 348 | case 'scheduled_get_settings': |
| 349 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 349 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 350 | 350 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 351 | 351 | break; |
| 352 | 352 | } |
@@ -377,12 +377,12 @@ discard block |
||
| 377 | 377 | |
| 378 | 378 | case 'disk_usage': |
| 379 | 379 | // Provide disk usage information for the storage containing the <files> directory |
| 380 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 380 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 381 | 381 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 382 | 382 | break; |
| 383 | 383 | } |
| 384 | 384 | |
| 385 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 385 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 386 | 386 | $dirReal = realpath($baseFilesDir); |
| 387 | 387 | |
| 388 | 388 | if ($dirReal === false) { |
@@ -393,21 +393,21 @@ discard block |
||
| 393 | 393 | $total = @disk_total_space($dirReal); |
| 394 | 394 | $free = @disk_free_space($dirReal); |
| 395 | 395 | |
| 396 | - if ($total === false || $free === false || (float)$total <= 0) { |
|
| 396 | + if ($total === false || $free === false || (float) $total <= 0) { |
|
| 397 | 397 | echo prepareExchangedData(['error' => true, 'message' => 'Unable to read disk usage'], 'encode'); |
| 398 | 398 | break; |
| 399 | 399 | } |
| 400 | 400 | |
| 401 | - $used = max(0.0, (float)$total - (float)$free); |
|
| 402 | - $pct = round(($used / (float)$total) * 100, 1); |
|
| 401 | + $used = max(0.0, (float) $total - (float) $free); |
|
| 402 | + $pct = round(($used / (float) $total) * 100, 1); |
|
| 403 | 403 | |
| 404 | - $label = tpFormatBytes($used) . ' / ' . tpFormatBytes((float)$total); |
|
| 404 | + $label = tpFormatBytes($used).' / '.tpFormatBytes((float) $total); |
|
| 405 | 405 | $tooltip = sprintf( |
| 406 | 406 | $lang->get('bck_storage_usage_tooltip'), |
| 407 | 407 | tpFormatBytes($used), |
| 408 | - tpFormatBytes((float)$total), |
|
| 409 | - (string)$pct, |
|
| 410 | - tpFormatBytes((float)$free), |
|
| 408 | + tpFormatBytes((float) $total), |
|
| 409 | + (string) $pct, |
|
| 410 | + tpFormatBytes((float) $free), |
|
| 411 | 411 | $dirReal |
| 412 | 412 | ); |
| 413 | 413 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | break; |
| 460 | 460 | |
| 461 | 461 | case 'scheduled_save_settings': |
| 462 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 462 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 463 | 463 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 464 | 464 | break; |
| 465 | 465 | } |
@@ -467,15 +467,15 @@ discard block |
||
| 467 | 467 | $dataReceived = prepareExchangedData($post_data, 'decode'); |
| 468 | 468 | if (!is_array($dataReceived)) $dataReceived = []; |
| 469 | 469 | |
| 470 | - $enabled = (int)($dataReceived['enabled'] ?? 0); |
|
| 470 | + $enabled = (int) ($dataReceived['enabled'] ?? 0); |
|
| 471 | 471 | $enabled = ($enabled === 1) ? 1 : 0; |
| 472 | 472 | |
| 473 | - $frequency = (string)($dataReceived['frequency'] ?? 'daily'); |
|
| 473 | + $frequency = (string) ($dataReceived['frequency'] ?? 'daily'); |
|
| 474 | 474 | if (!in_array($frequency, ['daily', 'weekly', 'monthly'], true)) { |
| 475 | 475 | $frequency = 'daily'; |
| 476 | 476 | } |
| 477 | 477 | |
| 478 | - $timeStr = (string)($dataReceived['time'] ?? '02:00'); |
|
| 478 | + $timeStr = (string) ($dataReceived['time'] ?? '02:00'); |
|
| 479 | 479 | if (!preg_match('/^\d{2}:\d{2}$/', $timeStr)) { |
| 480 | 480 | $timeStr = '02:00'; |
| 481 | 481 | } else { |
@@ -485,22 +485,22 @@ discard block |
||
| 485 | 485 | } |
| 486 | 486 | } |
| 487 | 487 | |
| 488 | - $dow = (int)($dataReceived['dow'] ?? 1); |
|
| 488 | + $dow = (int) ($dataReceived['dow'] ?? 1); |
|
| 489 | 489 | if ($dow < 1 || $dow > 7) $dow = 1; |
| 490 | 490 | |
| 491 | - $dom = (int)($dataReceived['dom'] ?? 1); |
|
| 491 | + $dom = (int) ($dataReceived['dom'] ?? 1); |
|
| 492 | 492 | if ($dom < 1) $dom = 1; |
| 493 | 493 | if ($dom > 31) $dom = 31; |
| 494 | 494 | |
| 495 | - $retentionDays = (int)($dataReceived['retention_days'] ?? 30); |
|
| 495 | + $retentionDays = (int) ($dataReceived['retention_days'] ?? 30); |
|
| 496 | 496 | if ($retentionDays < 1) $retentionDays = 1; |
| 497 | 497 | if ($retentionDays > 3650) $retentionDays = 3650; |
| 498 | 498 | |
| 499 | 499 | // Output dir: default to <files>/backups |
| 500 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 501 | - $defaultDir = rtrim($baseFilesDir, '/') . '/backups'; |
|
| 500 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 501 | + $defaultDir = rtrim($baseFilesDir, '/').'/backups'; |
|
| 502 | 502 | |
| 503 | - $outputDir = trim((string)($dataReceived['output_dir'] ?? '')); |
|
| 503 | + $outputDir = trim((string) ($dataReceived['output_dir'] ?? '')); |
|
| 504 | 504 | if ($outputDir === '') $outputDir = $defaultDir; |
| 505 | 505 | |
| 506 | 506 | // Safety: prevent path traversal / outside files folder |
@@ -513,13 +513,13 @@ discard block |
||
| 513 | 513 | break; |
| 514 | 514 | } |
| 515 | 515 | |
| 516 | - tpUpsertSettingsValue('bck_scheduled_enabled', (string)$enabled); |
|
| 516 | + tpUpsertSettingsValue('bck_scheduled_enabled', (string) $enabled); |
|
| 517 | 517 | tpUpsertSettingsValue('bck_scheduled_frequency', $frequency); |
| 518 | 518 | tpUpsertSettingsValue('bck_scheduled_time', $timeStr); |
| 519 | - tpUpsertSettingsValue('bck_scheduled_dow', (string)$dow); |
|
| 520 | - tpUpsertSettingsValue('bck_scheduled_dom', (string)$dom); |
|
| 519 | + tpUpsertSettingsValue('bck_scheduled_dow', (string) $dow); |
|
| 520 | + tpUpsertSettingsValue('bck_scheduled_dom', (string) $dom); |
|
| 521 | 521 | tpUpsertSettingsValue('bck_scheduled_output_dir', $dirReal); |
| 522 | - tpUpsertSettingsValue('bck_scheduled_retention_days', (string)$retentionDays); |
|
| 522 | + tpUpsertSettingsValue('bck_scheduled_retention_days', (string) $retentionDays); |
|
| 523 | 523 | |
| 524 | 524 | // Force re-init of next_run_at so handler recomputes cleanly |
| 525 | 525 | tpUpsertSettingsValue('bck_scheduled_next_run_at', '0'); |
@@ -528,13 +528,13 @@ discard block |
||
| 528 | 528 | break; |
| 529 | 529 | |
| 530 | 530 | case 'scheduled_list_backups': |
| 531 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 531 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 532 | 532 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 533 | 533 | break; |
| 534 | 534 | } |
| 535 | 535 | |
| 536 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 537 | - $dir = (string)tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/') . '/backups'); |
|
| 536 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 537 | + $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/').'/backups'); |
|
| 538 | 538 | @mkdir($dir, 0770, true); |
| 539 | 539 | // Build a relative path from files/ root (output_dir can be a subfolder) |
| 540 | 540 | $filesRoot = realpath($baseFilesDir); |
@@ -554,15 +554,15 @@ discard block |
||
| 554 | 554 | |
| 555 | 555 | |
| 556 | 556 | $files = []; |
| 557 | - foreach (glob(rtrim($dir, '/') . '/scheduled-*.sql') ?: [] as $fp) { |
|
| 557 | + foreach (glob(rtrim($dir, '/').'/scheduled-*.sql') ?: [] as $fp) { |
|
| 558 | 558 | $bn = basename($fp); |
| 559 | 559 | $files[] = [ |
| 560 | 560 | 'name' => $bn, |
| 561 | - 'size_bytes' => (int)@filesize($fp), |
|
| 562 | - 'mtime' => (int)@filemtime($fp), |
|
| 563 | - 'download' => 'sources/backups.queries.php?type=scheduled_download_backup&file=' . urlencode($bn) |
|
| 564 | - . '&key=' . urlencode((string) $session->get('key')) |
|
| 565 | - . '&key_tmp=' . urlencode($keyTmp), |
|
| 561 | + 'size_bytes' => (int) @filesize($fp), |
|
| 562 | + 'mtime' => (int) @filemtime($fp), |
|
| 563 | + 'download' => 'sources/backups.queries.php?type=scheduled_download_backup&file='.urlencode($bn) |
|
| 564 | + . '&key='.urlencode((string) $session->get('key')) |
|
| 565 | + . '&key_tmp='.urlencode($keyTmp), |
|
| 566 | 566 | ]; |
| 567 | 567 | } |
| 568 | 568 | |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | break; |
| 573 | 573 | |
| 574 | 574 | case 'scheduled_delete_backup': |
| 575 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 575 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 576 | 576 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 577 | 577 | break; |
| 578 | 578 | } |
@@ -580,7 +580,7 @@ discard block |
||
| 580 | 580 | $dataReceived = prepareExchangedData($post_data, 'decode'); |
| 581 | 581 | if (!is_array($dataReceived)) $dataReceived = []; |
| 582 | 582 | |
| 583 | - $file = (string)($dataReceived['file'] ?? ''); |
|
| 583 | + $file = (string) ($dataReceived['file'] ?? ''); |
|
| 584 | 584 | $file = basename($file); |
| 585 | 585 | |
| 586 | 586 | if ($file === '' || strpos($file, 'scheduled-') !== 0 || !str_ends_with($file, '.sql')) { |
@@ -588,9 +588,9 @@ discard block |
||
| 588 | 588 | break; |
| 589 | 589 | } |
| 590 | 590 | |
| 591 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 592 | - $dir = (string)tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/') . '/backups'); |
|
| 593 | - $fp = rtrim($dir, '/') . '/' . $file; |
|
| 591 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 592 | + $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/').'/backups'); |
|
| 593 | + $fp = rtrim($dir, '/').'/'.$file; |
|
| 594 | 594 | |
| 595 | 595 | if (is_file($fp)) { |
| 596 | 596 | @unlink($fp); |
@@ -600,19 +600,19 @@ discard block |
||
| 600 | 600 | break; |
| 601 | 601 | |
| 602 | 602 | case 'scheduled_run_now': |
| 603 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 603 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 604 | 604 | echo prepareExchangedData(['error' => true, 'message' => 'Not allowed'], 'encode'); |
| 605 | 605 | break; |
| 606 | 606 | } |
| 607 | 607 | |
| 608 | 608 | $now = time(); |
| 609 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 610 | - $dir = (string)tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/') . '/backups'); |
|
| 609 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 610 | + $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/').'/backups'); |
|
| 611 | 611 | @mkdir($dir, 0770, true); |
| 612 | 612 | |
| 613 | 613 | // avoid duplicates |
| 614 | - $pending = (int)DB::queryFirstField( |
|
| 615 | - 'SELECT COUNT(*) FROM ' . prefixTable('background_tasks') . ' |
|
| 614 | + $pending = (int) DB::queryFirstField( |
|
| 615 | + 'SELECT COUNT(*) FROM '.prefixTable('background_tasks').' |
|
| 616 | 616 | WHERE process_type=%s AND is_in_progress IN (0,1) |
| 617 | 617 | AND (finished_at IS NULL OR finished_at = "" OR finished_at = 0)', |
| 618 | 618 | 'database_backup' |
@@ -625,7 +625,7 @@ discard block |
||
| 625 | 625 | DB::insert( |
| 626 | 626 | prefixTable('background_tasks'), |
| 627 | 627 | [ |
| 628 | - 'created_at' => (string)$now, |
|
| 628 | + 'created_at' => (string) $now, |
|
| 629 | 629 | 'process_type' => 'database_backup', |
| 630 | 630 | 'arguments' => json_encode(['output_dir' => $dir, 'source' => 'scheduler'], JSON_UNESCAPED_SLASHES), |
| 631 | 631 | 'is_in_progress' => 0, |
@@ -633,7 +633,7 @@ discard block |
||
| 633 | 633 | ] |
| 634 | 634 | ); |
| 635 | 635 | |
| 636 | - tpUpsertSettingsValue('bck_scheduled_last_run_at', (string)$now); |
|
| 636 | + tpUpsertSettingsValue('bck_scheduled_last_run_at', (string) $now); |
|
| 637 | 637 | tpUpsertSettingsValue('bck_scheduled_last_status', 'queued'); |
| 638 | 638 | tpUpsertSettingsValue('bck_scheduled_last_message', 'Task enqueued by UI'); |
| 639 | 639 | |
@@ -642,7 +642,7 @@ discard block |
||
| 642 | 642 | |
| 643 | 643 | case 'onthefly_delete_backup': |
| 644 | 644 | // Delete an on-the-fly backup file stored in <files> directory |
| 645 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 645 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 646 | 646 | echo prepareExchangedData( |
| 647 | 647 | array( |
| 648 | 648 | 'error' => true, |
@@ -654,7 +654,7 @@ discard block |
||
| 654 | 654 | } |
| 655 | 655 | |
| 656 | 656 | $dataReceived = prepareExchangedData($post_data, 'decode'); |
| 657 | - $fileToDelete = isset($dataReceived['file']) === true ? (string)$dataReceived['file'] : ''; |
|
| 657 | + $fileToDelete = isset($dataReceived['file']) === true ? (string) $dataReceived['file'] : ''; |
|
| 658 | 658 | $bn = basename($fileToDelete); |
| 659 | 659 | |
| 660 | 660 | // Safety checks |
@@ -681,9 +681,9 @@ discard block |
||
| 681 | 681 | break; |
| 682 | 682 | } |
| 683 | 683 | |
| 684 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 684 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 685 | 685 | $dir = rtrim($baseFilesDir, '/'); |
| 686 | - $fullPath = $dir . '/' . $bn; |
|
| 686 | + $fullPath = $dir.'/'.$bn; |
|
| 687 | 687 | |
| 688 | 688 | if (file_exists($fullPath) === false) { |
| 689 | 689 | echo prepareExchangedData( |
@@ -722,7 +722,7 @@ discard block |
||
| 722 | 722 | |
| 723 | 723 | case 'onthefly_list_backups': |
| 724 | 724 | // List on-the-fly backup files stored directly in <files> directory (not in /backups for scheduled) |
| 725 | - if ($post_key !== $session->get('key') || (int)$session->get('user-admin') !== 1) { |
|
| 725 | + if ($post_key !== $session->get('key') || (int) $session->get('user-admin') !== 1) { |
|
| 726 | 726 | echo prepareExchangedData( |
| 727 | 727 | array( |
| 728 | 728 | 'error' => true, |
@@ -733,11 +733,11 @@ discard block |
||
| 733 | 733 | break; |
| 734 | 734 | } |
| 735 | 735 | |
| 736 | - $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 736 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 737 | 737 | $dir = rtrim($baseFilesDir, '/'); |
| 738 | 738 | |
| 739 | 739 | $files = array(); |
| 740 | - $paths = glob($dir . '/*.sql'); |
|
| 740 | + $paths = glob($dir.'/*.sql'); |
|
| 741 | 741 | if ($paths === false) { |
| 742 | 742 | $paths = array(); |
| 743 | 743 | } |
@@ -762,17 +762,17 @@ discard block |
||
| 762 | 762 | |
| 763 | 763 | $files[] = array( |
| 764 | 764 | 'name' => $bn, |
| 765 | - 'size_bytes' => (int)@filesize($fp), |
|
| 766 | - 'mtime' => (int)@filemtime($fp), |
|
| 767 | - 'download' => 'sources/downloadFile.php?name=' . urlencode($bn) . |
|
| 768 | - '&action=backup&file=' . urlencode($bn) . |
|
| 769 | - '&type=sql&key=' . $session->get('key') . |
|
| 770 | - '&key_tmp=' . $session->get('user-key_tmp') . |
|
| 765 | + 'size_bytes' => (int) @filesize($fp), |
|
| 766 | + 'mtime' => (int) @filemtime($fp), |
|
| 767 | + 'download' => 'sources/downloadFile.php?name='.urlencode($bn). |
|
| 768 | + '&action=backup&file='.urlencode($bn). |
|
| 769 | + '&type=sql&key='.$session->get('key'). |
|
| 770 | + '&key_tmp='.$session->get('user-key_tmp'). |
|
| 771 | 771 | '&pathIsFiles=1', |
| 772 | 772 | ); |
| 773 | 773 | } |
| 774 | 774 | |
| 775 | - usort($files, static function ($a, $b) { |
|
| 775 | + usort($files, static function($a, $b) { |
|
| 776 | 776 | return ($b['mtime'] ?? 0) <=> ($a['mtime'] ?? 0); |
| 777 | 777 | }); |
| 778 | 778 | |
@@ -825,7 +825,7 @@ discard block |
||
| 825 | 825 | $post_clearFilename = filter_var(($dataReceived['clearFilename'] ?? ''), FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 826 | 826 | |
| 827 | 827 | $post_serverScope = filter_var(($dataReceived['serverScope'] ?? ''), FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
| 828 | - $post_serverFile = filter_var(($dataReceived['serverFile'] ?? ''), FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
| 828 | + $post_serverFile = filter_var(($dataReceived['serverFile'] ?? ''), FILTER_SANITIZE_FULL_SPECIAL_CHARS); |
|
| 829 | 829 | |
| 830 | 830 | // Scheduled backups must always be decrypted with the instance key (server-side). |
| 831 | 831 | // Ignore any key coming from the UI to avoid mismatches. |
@@ -834,7 +834,7 @@ discard block |
||
| 834 | 834 | } |
| 835 | 835 | // Ensure all strings we send back through prepareExchangedData() are JSON-safe. |
| 836 | 836 | // This avoids PHP "malformed UTF-8" warnings when restore errors contain binary/latin1 bytes. |
| 837 | - $tpSafeJsonString = static function ($value): string { |
|
| 837 | + $tpSafeJsonString = static function($value): string { |
|
| 838 | 838 | if ($value === null) { |
| 839 | 839 | return ''; |
| 840 | 840 | } |
@@ -854,7 +854,7 @@ discard block |
||
| 854 | 854 | $isUtf8 = (@preg_match('//u', $str) === 1); |
| 855 | 855 | } |
| 856 | 856 | if ($isUtf8 === false) { |
| 857 | - return '[hex]' . bin2hex($str); |
|
| 857 | + return '[hex]'.bin2hex($str); |
|
| 858 | 858 | } |
| 859 | 859 | |
| 860 | 860 | // Strip ASCII control chars that could pollute JSON. |
@@ -869,7 +869,7 @@ discard block |
||
| 869 | 869 | // Restore session + concurrency lock management. |
| 870 | 870 | // - We keep a token in session to allow chunked restore even while DB is being replaced. |
| 871 | 871 | // - We also block starting a second restore in the same session (double click / 2 tabs). |
| 872 | -$clearRestoreState = static function ($session): void { |
|
| 872 | +$clearRestoreState = static function($session): void { |
|
| 873 | 873 | $tmp = (string) ($session->get('restore-temp-file') ?? ''); |
| 874 | 874 | if ($tmp !== '' && file_exists($tmp) === true && strpos(basename($tmp), 'defuse_temp_restore_') === 0) { |
| 875 | 875 | @unlink($tmp); |
@@ -966,9 +966,9 @@ discard block |
||
| 966 | 966 | error_log('DEBUG: Offset -> '.$post_offset.'/'.$post_totalSize.' | File -> '.$post_clearFilename); |
| 967 | 967 | } |
| 968 | 968 | |
| 969 | - include_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php'; |
|
| 969 | + include_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php'; |
|
| 970 | 970 | |
| 971 | - include_once $SETTINGS['cpassman_dir'] . '/sources/main.functions.php'; |
|
| 971 | + include_once $SETTINGS['cpassman_dir'].'/sources/main.functions.php'; |
|
| 972 | 972 | |
| 973 | 973 | /* |
| 974 | 974 | * Restore workflow |
@@ -1005,12 +1005,12 @@ discard block |
||
| 1005 | 1005 | |
| 1006 | 1006 | // Scheduled backups are stored in configured output directory |
| 1007 | 1007 | if ($post_serverScope === 'scheduled') { |
| 1008 | - $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 1009 | - $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/') . '/backups'); |
|
| 1008 | + $baseFilesDir = (string) ($SETTINGS['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 1009 | + $dir = (string) tpGetSettingsValue('bck_scheduled_output_dir', rtrim($baseFilesDir, '/').'/backups'); |
|
| 1010 | 1010 | $baseDir = rtrim($dir, '/'); |
| 1011 | 1011 | } |
| 1012 | 1012 | |
| 1013 | - $serverPath = $baseDir . '/' . $bn; |
|
| 1013 | + $serverPath = $baseDir.'/'.$bn; |
|
| 1014 | 1014 | |
| 1015 | 1015 | if (file_exists($serverPath) === false) { |
| 1016 | 1016 | try { |
@@ -1045,7 +1045,7 @@ discard block |
||
| 1045 | 1045 | ); |
| 1046 | 1046 | |
| 1047 | 1047 | try { |
| 1048 | - $msg = 'dataBase restore started (scope=' . $post_serverScope . ', file=' . $bn . ')'; |
|
| 1048 | + $msg = 'dataBase restore started (scope='.$post_serverScope.', file='.$bn.')'; |
|
| 1049 | 1049 | logEvents( |
| 1050 | 1050 | $SETTINGS, |
| 1051 | 1051 | 'admin_action', |
@@ -1072,7 +1072,7 @@ discard block |
||
| 1072 | 1072 | |
| 1073 | 1073 | // Find filename from DB (misc) |
| 1074 | 1074 | $data = DB::queryFirstRow( |
| 1075 | - 'SELECT valeur FROM ' . prefixTable('misc') . ' WHERE increment_id = %i LIMIT 1', |
|
| 1075 | + 'SELECT valeur FROM '.prefixTable('misc').' WHERE increment_id = %i LIMIT 1', |
|
| 1076 | 1076 | $legacyOperationId |
| 1077 | 1077 | ); |
| 1078 | 1078 | |
@@ -1097,7 +1097,7 @@ discard block |
||
| 1097 | 1097 | } |
| 1098 | 1098 | |
| 1099 | 1099 | $bn = safeString($data['valeur']); |
| 1100 | - $serverPath = rtrim((string) $SETTINGS['path_to_files_folder'], '/') . '/' . $bn; |
|
| 1100 | + $serverPath = rtrim((string) $SETTINGS['path_to_files_folder'], '/').'/'.$bn; |
|
| 1101 | 1101 | |
| 1102 | 1102 | if (file_exists($serverPath) === false) { |
| 1103 | 1103 | try { |
@@ -1131,7 +1131,7 @@ discard block |
||
| 1131 | 1131 | |
| 1132 | 1132 | // Decrypt to a dedicated temp file (unique) |
| 1133 | 1133 | $tmpDecrypted = rtrim((string) $SETTINGS['path_to_files_folder'], '/') |
| 1134 | - . '/defuse_temp_restore_' . (int) $session->get('user-id') . '_' . time() . '_' . $bn; |
|
| 1134 | + . '/defuse_temp_restore_'.(int) $session->get('user-id').'_'.time().'_'.$bn; |
|
| 1135 | 1135 | |
| 1136 | 1136 | // Build the list of keys we can try to decrypt with. |
| 1137 | 1137 | // - on-the-fly: uses the key provided by the UI |
@@ -1190,7 +1190,7 @@ discard block |
||
| 1190 | 1190 | array( |
| 1191 | 1191 | 'error' => true, |
| 1192 | 1192 | 'error_code' => 'DECRYPT_FAILED', |
| 1193 | - 'message' => 'Unable to decrypt backup: ' . $tpSafeJsonString((string) ($decRet['message'] ?? 'unknown error')), |
|
| 1193 | + 'message' => 'Unable to decrypt backup: '.$tpSafeJsonString((string) ($decRet['message'] ?? 'unknown error')), |
|
| 1194 | 1194 | ), |
| 1195 | 1195 | 'encode' |
| 1196 | 1196 | ); |
@@ -1344,7 +1344,7 @@ discard block |
||
| 1344 | 1344 | } catch (Exception $e) { |
| 1345 | 1345 | $snippet = substr($query, 0, 120); |
| 1346 | 1346 | $snippet = $tpSafeJsonString($snippet); |
| 1347 | - $errors[] = 'Error executing query: ' . $tpSafeJsonString($e->getMessage()) . ' - Query: ' . $snippet . '...'; |
|
| 1347 | + $errors[] = 'Error executing query: '.$tpSafeJsonString($e->getMessage()).' - Query: '.$snippet.'...'; |
|
| 1348 | 1348 | } |
| 1349 | 1349 | $query = ''; |
| 1350 | 1350 | } |
@@ -1370,7 +1370,7 @@ discard block |
||
| 1370 | 1370 | } |
| 1371 | 1371 | // Rollback transaction on any exception |
| 1372 | 1372 | DB::rollback(); |
| 1373 | - $errors[] = 'Transaction failed: ' . $tpSafeJsonString($e->getMessage()); |
|
| 1373 | + $errors[] = 'Transaction failed: '.$tpSafeJsonString($e->getMessage()); |
|
| 1374 | 1374 | } |
| 1375 | 1375 | |
| 1376 | 1376 | // Calculate the new offset |
@@ -1397,7 +1397,7 @@ discard block |
||
| 1397 | 1397 | logEvents( |
| 1398 | 1398 | $SETTINGS, |
| 1399 | 1399 | 'admin_action', |
| 1400 | - 'dataBase restore failed' . ($scope !== '' ? ' (scope=' . $scope . ')' : ''), |
|
| 1400 | + 'dataBase restore failed'.($scope !== '' ? ' (scope='.$scope.')' : ''), |
|
| 1401 | 1401 | (string) $session->get('user-id'), |
| 1402 | 1402 | $session->get('user-login') |
| 1403 | 1403 | ); |
@@ -1410,7 +1410,7 @@ discard block |
||
| 1410 | 1410 | echo prepareExchangedData( |
| 1411 | 1411 | array( |
| 1412 | 1412 | 'error' => true, |
| 1413 | - 'message' => 'Errors occurred during import: ' . implode('; ', ($post_serverScope === 'scheduled' ? array_map($tpSafeJsonString, $errors) : $errors)), |
|
| 1413 | + 'message' => 'Errors occurred during import: '.implode('; ', ($post_serverScope === 'scheduled' ? array_map($tpSafeJsonString, $errors) : $errors)), |
|
| 1414 | 1414 | 'newOffset' => $newOffset, |
| 1415 | 1415 | 'totalSize' => $post_totalSize, |
| 1416 | 1416 | 'clearFilename' => $post_backupFile, |
@@ -1461,15 +1461,15 @@ discard block |
||
| 1461 | 1461 | if ($scope !== '' || $fileLabel !== '' || $duration > 0) { |
| 1462 | 1462 | $parts = array(); |
| 1463 | 1463 | if ($scope !== '') { |
| 1464 | - $parts[] = 'scope=' . $scope; |
|
| 1464 | + $parts[] = 'scope='.$scope; |
|
| 1465 | 1465 | } |
| 1466 | 1466 | if ($fileLabel !== '') { |
| 1467 | - $parts[] = 'file=' . $fileLabel; |
|
| 1467 | + $parts[] = 'file='.$fileLabel; |
|
| 1468 | 1468 | } |
| 1469 | 1469 | if ($duration > 0) { |
| 1470 | - $parts[] = 'duration=' . $duration . 's'; |
|
| 1470 | + $parts[] = 'duration='.$duration.'s'; |
|
| 1471 | 1471 | } |
| 1472 | - $msg .= ' (' . implode(', ', $parts) . ')'; |
|
| 1472 | + $msg .= ' ('.implode(', ', $parts).')'; |
|
| 1473 | 1473 | } |
| 1474 | 1474 | |
| 1475 | 1475 | logEvents( |
@@ -465,7 +465,9 @@ discard block |
||
| 465 | 465 | } |
| 466 | 466 | |
| 467 | 467 | $dataReceived = prepareExchangedData($post_data, 'decode'); |
| 468 | - if (!is_array($dataReceived)) $dataReceived = []; |
|
| 468 | + if (!is_array($dataReceived)) { |
|
| 469 | + $dataReceived = []; |
|
| 470 | + } |
|
| 469 | 471 | |
| 470 | 472 | $enabled = (int)($dataReceived['enabled'] ?? 0); |
| 471 | 473 | $enabled = ($enabled === 1) ? 1 : 0; |
@@ -486,22 +488,34 @@ discard block |
||
| 486 | 488 | } |
| 487 | 489 | |
| 488 | 490 | $dow = (int)($dataReceived['dow'] ?? 1); |
| 489 | - if ($dow < 1 || $dow > 7) $dow = 1; |
|
| 491 | + if ($dow < 1 || $dow > 7) { |
|
| 492 | + $dow = 1; |
|
| 493 | + } |
|
| 490 | 494 | |
| 491 | 495 | $dom = (int)($dataReceived['dom'] ?? 1); |
| 492 | - if ($dom < 1) $dom = 1; |
|
| 493 | - if ($dom > 31) $dom = 31; |
|
| 496 | + if ($dom < 1) { |
|
| 497 | + $dom = 1; |
|
| 498 | + } |
|
| 499 | + if ($dom > 31) { |
|
| 500 | + $dom = 31; |
|
| 501 | + } |
|
| 494 | 502 | |
| 495 | 503 | $retentionDays = (int)($dataReceived['retention_days'] ?? 30); |
| 496 | - if ($retentionDays < 1) $retentionDays = 1; |
|
| 497 | - if ($retentionDays > 3650) $retentionDays = 3650; |
|
| 504 | + if ($retentionDays < 1) { |
|
| 505 | + $retentionDays = 1; |
|
| 506 | + } |
|
| 507 | + if ($retentionDays > 3650) { |
|
| 508 | + $retentionDays = 3650; |
|
| 509 | + } |
|
| 498 | 510 | |
| 499 | 511 | // Output dir: default to <files>/backups |
| 500 | 512 | $baseFilesDir = (string)($SETTINGS['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
| 501 | 513 | $defaultDir = rtrim($baseFilesDir, '/') . '/backups'; |
| 502 | 514 | |
| 503 | 515 | $outputDir = trim((string)($dataReceived['output_dir'] ?? '')); |
| 504 | - if ($outputDir === '') $outputDir = $defaultDir; |
|
| 516 | + if ($outputDir === '') { |
|
| 517 | + $outputDir = $defaultDir; |
|
| 518 | + } |
|
| 505 | 519 | |
| 506 | 520 | // Safety: prevent path traversal / outside files folder |
| 507 | 521 | @mkdir($outputDir, 0770, true); |
@@ -578,7 +592,9 @@ discard block |
||
| 578 | 592 | } |
| 579 | 593 | |
| 580 | 594 | $dataReceived = prepareExchangedData($post_data, 'decode'); |
| 581 | - if (!is_array($dataReceived)) $dataReceived = []; |
|
| 595 | + if (!is_array($dataReceived)) { |
|
| 596 | + $dataReceived = []; |
|
| 597 | + } |
|
| 582 | 598 | |
| 583 | 599 | $file = (string)($dataReceived['file'] ?? ''); |
| 584 | 600 | $file = basename($file); |
@@ -30,7 +30,7 @@ discard block |
||
| 30 | 30 | use TeampassClasses\ConfigManager\ConfigManager; |
| 31 | 31 | |
| 32 | 32 | require_once __DIR__.'/../sources/main.functions.php'; |
| 33 | -require_once __DIR__ . '/taskLogger.php'; |
|
| 33 | +require_once __DIR__.'/taskLogger.php'; |
|
| 34 | 34 | |
| 35 | 35 | class BackgroundTasksHandler { |
| 36 | 36 | private $settings; |
@@ -72,17 +72,17 @@ discard block |
||
| 72 | 72 | public function processBackgroundTasks() { |
| 73 | 73 | // Prevent multiple concurrent executions |
| 74 | 74 | if (!$this->acquireProcessLock()) { |
| 75 | - if (LOG_TASKS=== true) $this->logger->log('Process already running', 'INFO'); |
|
| 75 | + if (LOG_TASKS === true) $this->logger->log('Process already running', 'INFO'); |
|
| 76 | 76 | return false; |
| 77 | 77 | } |
| 78 | 78 | |
| 79 | 79 | try { |
| 80 | 80 | $this->cleanupStaleTasks(); |
| 81 | - $this->handleScheduledDatabaseBackup(); // <--- NEW |
|
| 81 | + $this->handleScheduledDatabaseBackup(); // <--- NEW |
|
| 82 | 82 | $this->processTaskBatches(); |
| 83 | 83 | $this->performMaintenanceTasks(); |
| 84 | 84 | } catch (Exception $e) { |
| 85 | - if (LOG_TASKS=== true) $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 85 | + if (LOG_TASKS === true) $this->logger->log('Task processing error: '.$e->getMessage(), 'ERROR'); |
|
| 86 | 86 | } finally { |
| 87 | 87 | $this->releaseProcessLock(); |
| 88 | 88 | } |
@@ -92,7 +92,7 @@ discard block |
||
| 92 | 92 | */ |
| 93 | 93 | private function handleScheduledDatabaseBackup(): void |
| 94 | 94 | { |
| 95 | - $enabled = (int)$this->getSettingValue('bck_scheduled_enabled', '0'); |
|
| 95 | + $enabled = (int) $this->getSettingValue('bck_scheduled_enabled', '0'); |
|
| 96 | 96 | if ($enabled !== 1) { |
| 97 | 97 | return; |
| 98 | 98 | } |
@@ -100,19 +100,19 @@ discard block |
||
| 100 | 100 | $now = time(); |
| 101 | 101 | |
| 102 | 102 | // Output dir |
| 103 | - $outputDir = (string)$this->getSettingValue('bck_scheduled_output_dir', ''); |
|
| 103 | + $outputDir = (string) $this->getSettingValue('bck_scheduled_output_dir', ''); |
|
| 104 | 104 | if ($outputDir === '') { |
| 105 | - $baseFilesDir = (string)($this->settings['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 106 | - $outputDir = rtrim($baseFilesDir, '/') . '/backups'; |
|
| 105 | + $baseFilesDir = (string) ($this->settings['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 106 | + $outputDir = rtrim($baseFilesDir, '/').'/backups'; |
|
| 107 | 107 | $this->upsertSettingValue('bck_scheduled_output_dir', $outputDir); |
| 108 | 108 | } |
| 109 | 109 | |
| 110 | 110 | // next_run_at |
| 111 | - $nextRunAt = (int)$this->getSettingValue('bck_scheduled_next_run_at', '0'); |
|
| 111 | + $nextRunAt = (int) $this->getSettingValue('bck_scheduled_next_run_at', '0'); |
|
| 112 | 112 | if ($nextRunAt <= 0) { |
| 113 | 113 | $nextRunAt = $this->computeNextBackupRunAt($now); |
| 114 | - $this->upsertSettingValue('bck_scheduled_next_run_at', (string)$nextRunAt); |
|
| 115 | - if (LOG_TASKS === true) $this->logger->log('backup scheduler initialized next_run_at=' . $nextRunAt, 'INFO'); |
|
| 114 | + $this->upsertSettingValue('bck_scheduled_next_run_at', (string) $nextRunAt); |
|
| 115 | + if (LOG_TASKS === true) $this->logger->log('backup scheduler initialized next_run_at='.$nextRunAt, 'INFO'); |
|
| 116 | 116 | return; |
| 117 | 117 | } |
| 118 | 118 | |
@@ -121,9 +121,9 @@ discard block |
||
| 121 | 121 | } |
| 122 | 122 | |
| 123 | 123 | // Avoid duplicates: if a database_backup task is already pending or running, skip. |
| 124 | - $pending = (int)DB::queryFirstField( |
|
| 124 | + $pending = (int) DB::queryFirstField( |
|
| 125 | 125 | 'SELECT COUNT(*) |
| 126 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 126 | + FROM ' . prefixTable('background_tasks').' |
|
| 127 | 127 | WHERE process_type = %s |
| 128 | 128 | AND is_in_progress IN (0,1) |
| 129 | 129 | AND (finished_at IS NULL OR finished_at = "" OR finished_at = 0)', |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | DB::insert( |
| 140 | 140 | prefixTable('background_tasks'), |
| 141 | 141 | [ |
| 142 | - 'created_at' => (string)$now, |
|
| 142 | + 'created_at' => (string) $now, |
|
| 143 | 143 | 'process_type' => 'database_backup', |
| 144 | 144 | 'arguments' => json_encode( |
| 145 | 145 | [ |
@@ -153,15 +153,15 @@ discard block |
||
| 153 | 153 | ] |
| 154 | 154 | ); |
| 155 | 155 | |
| 156 | - $this->upsertSettingValue('bck_scheduled_last_run_at', (string)$now); |
|
| 156 | + $this->upsertSettingValue('bck_scheduled_last_run_at', (string) $now); |
|
| 157 | 157 | $this->upsertSettingValue('bck_scheduled_last_status', 'queued'); |
| 158 | 158 | $this->upsertSettingValue('bck_scheduled_last_message', 'Task enqueued by scheduler'); |
| 159 | 159 | |
| 160 | 160 | // Compute next run |
| 161 | 161 | $newNext = $this->computeNextBackupRunAt($now + 60); |
| 162 | - $this->upsertSettingValue('bck_scheduled_next_run_at', (string)$newNext); |
|
| 162 | + $this->upsertSettingValue('bck_scheduled_next_run_at', (string) $newNext); |
|
| 163 | 163 | |
| 164 | - if (LOG_TASKS === true) $this->logger->log('backup scheduler: enqueued database_backup, next_run_at=' . $newNext, 'INFO'); |
|
| 164 | + if (LOG_TASKS === true) $this->logger->log('backup scheduler: enqueued database_backup, next_run_at='.$newNext, 'INFO'); |
|
| 165 | 165 | } |
| 166 | 166 | |
| 167 | 167 | /** |
@@ -176,7 +176,7 @@ discard block |
||
| 176 | 176 | { |
| 177 | 177 | // TeamPass stores timezone in teampass_misc: type='admin', intitule='timezone' |
| 178 | 178 | $tz = DB::queryFirstField( |
| 179 | - 'SELECT valeur FROM ' . prefixTable('misc') . ' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 179 | + 'SELECT valeur FROM '.prefixTable('misc').' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 180 | 180 | 'admin', |
| 181 | 181 | 'timezone' |
| 182 | 182 | ); |
@@ -194,44 +194,44 @@ discard block |
||
| 194 | 194 | $tz = new DateTimeZone('UTC'); |
| 195 | 195 | } |
| 196 | 196 | |
| 197 | - $freq = (string)$this->getSettingValue('bck_scheduled_frequency', 'daily'); |
|
| 198 | - $timeStr = (string)$this->getSettingValue('bck_scheduled_time', '02:00'); |
|
| 197 | + $freq = (string) $this->getSettingValue('bck_scheduled_frequency', 'daily'); |
|
| 198 | + $timeStr = (string) $this->getSettingValue('bck_scheduled_time', '02:00'); |
|
| 199 | 199 | |
| 200 | 200 | if (!preg_match('/^\d{2}:\d{2}$/', $timeStr)) { |
| 201 | 201 | $timeStr = '02:00'; |
| 202 | 202 | } |
| 203 | 203 | [$hh, $mm] = array_map('intval', explode(':', $timeStr)); |
| 204 | 204 | |
| 205 | - $now = (new DateTimeImmutable('@' . $fromTs))->setTimezone($tz); |
|
| 205 | + $now = (new DateTimeImmutable('@'.$fromTs))->setTimezone($tz); |
|
| 206 | 206 | $candidate = $now->setTime($hh, $mm, 0); |
| 207 | 207 | |
| 208 | 208 | if ($freq === 'weekly') { |
| 209 | - $targetDow = (int)$this->getSettingValue('bck_scheduled_dow', '1'); // ISO 1..7 |
|
| 209 | + $targetDow = (int) $this->getSettingValue('bck_scheduled_dow', '1'); // ISO 1..7 |
|
| 210 | 210 | if ($targetDow < 1 || $targetDow > 7) $targetDow = 1; |
| 211 | 211 | |
| 212 | - $currentDow = (int)$candidate->format('N'); |
|
| 212 | + $currentDow = (int) $candidate->format('N'); |
|
| 213 | 213 | $delta = ($targetDow - $currentDow + 7) % 7; |
| 214 | 214 | if ($delta === 0 && $candidate <= $now) { |
| 215 | 215 | $delta = 7; |
| 216 | 216 | } |
| 217 | - $candidate = $candidate->modify('+' . $delta . ' days'); |
|
| 217 | + $candidate = $candidate->modify('+'.$delta.' days'); |
|
| 218 | 218 | |
| 219 | 219 | } elseif ($freq === 'monthly') { |
| 220 | - $dom = (int)$this->getSettingValue('bck_scheduled_dom', '1'); |
|
| 220 | + $dom = (int) $this->getSettingValue('bck_scheduled_dom', '1'); |
|
| 221 | 221 | if ($dom < 1) $dom = 1; |
| 222 | 222 | if ($dom > 31) $dom = 31; |
| 223 | 223 | |
| 224 | - $year = (int)$now->format('Y'); |
|
| 225 | - $month = (int)$now->format('m'); |
|
| 226 | - $daysInMonth = (int)$now->format('t'); |
|
| 224 | + $year = (int) $now->format('Y'); |
|
| 225 | + $month = (int) $now->format('m'); |
|
| 226 | + $daysInMonth = (int) $now->format('t'); |
|
| 227 | 227 | $day = min($dom, $daysInMonth); |
| 228 | 228 | |
| 229 | 229 | $candidate = $now->setDate($year, $month, $day)->setTime($hh, $mm, 0); |
| 230 | 230 | if ($candidate <= $now) { |
| 231 | 231 | $nextMonth = $now->modify('first day of next month'); |
| 232 | - $year2 = (int)$nextMonth->format('Y'); |
|
| 233 | - $month2 = (int)$nextMonth->format('m'); |
|
| 234 | - $daysInMonth2 = (int)$nextMonth->format('t'); |
|
| 232 | + $year2 = (int) $nextMonth->format('Y'); |
|
| 233 | + $month2 = (int) $nextMonth->format('m'); |
|
| 234 | + $daysInMonth2 = (int) $nextMonth->format('t'); |
|
| 235 | 235 | $day2 = min($dom, $daysInMonth2); |
| 236 | 236 | |
| 237 | 237 | $candidate = $nextMonth->setDate($year2, $month2, $day2)->setTime($hh, $mm, 0); |
@@ -256,7 +256,7 @@ discard block |
||
| 256 | 256 | |
| 257 | 257 | // Schéma TeamPass classique: misc(type, intitule, valeur) |
| 258 | 258 | $val = DB::queryFirstField( |
| 259 | - 'SELECT valeur FROM ' . $table . ' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 259 | + 'SELECT valeur FROM '.$table.' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 260 | 260 | 'settings', |
| 261 | 261 | $key |
| 262 | 262 | ); |
@@ -265,7 +265,7 @@ discard block |
||
| 265 | 265 | return $default; |
| 266 | 266 | } |
| 267 | 267 | |
| 268 | - return (string)$val; |
|
| 268 | + return (string) $val; |
|
| 269 | 269 | } |
| 270 | 270 | |
| 271 | 271 | /** |
@@ -275,8 +275,8 @@ discard block |
||
| 275 | 275 | { |
| 276 | 276 | $table = prefixTable('misc'); |
| 277 | 277 | |
| 278 | - $exists = (int)DB::queryFirstField( |
|
| 279 | - 'SELECT COUNT(*) FROM ' . $table . ' WHERE type = %s AND intitule = %s', |
|
| 278 | + $exists = (int) DB::queryFirstField( |
|
| 279 | + 'SELECT COUNT(*) FROM '.$table.' WHERE type = %s AND intitule = %s', |
|
| 280 | 280 | 'settings', |
| 281 | 281 | $key |
| 282 | 282 | ); |
@@ -304,7 +304,7 @@ discard block |
||
| 304 | 304 | return false; |
| 305 | 305 | } |
| 306 | 306 | |
| 307 | - fwrite($fp, (string)getmypid()); |
|
| 307 | + fwrite($fp, (string) getmypid()); |
|
| 308 | 308 | return true; |
| 309 | 309 | } |
| 310 | 310 | |
@@ -324,7 +324,7 @@ discard block |
||
| 324 | 324 | private function cleanupStaleTasks() { |
| 325 | 325 | // Mark tasks as failed if they've been running too long |
| 326 | 326 | DB::query( |
| 327 | - 'UPDATE ' . prefixTable('background_tasks') . ' |
|
| 327 | + 'UPDATE '.prefixTable('background_tasks').' |
|
| 328 | 328 | SET is_in_progress = -1, |
| 329 | 329 | finished_at = %i, |
| 330 | 330 | status = "failed", |
@@ -337,8 +337,8 @@ discard block |
||
| 337 | 337 | |
| 338 | 338 | // Remove very old failed tasks |
| 339 | 339 | DB::query( |
| 340 | - 'DELETE t, st FROM ' . prefixTable('background_tasks') . ' t |
|
| 341 | - INNER JOIN ' . prefixTable('background_subtasks') . ' st ON (t.increment_id = st.task_id) |
|
| 340 | + 'DELETE t, st FROM '.prefixTable('background_tasks').' t |
|
| 341 | + INNER JOIN ' . prefixTable('background_subtasks').' st ON (t.increment_id = st.task_id) |
|
| 342 | 342 | WHERE t.finished_at > 0 |
| 343 | 343 | AND t.finished_at < %i |
| 344 | 344 | AND t.status = %s', |
@@ -356,7 +356,7 @@ discard block |
||
| 356 | 356 | |
| 357 | 357 | // Check if the maximum number of parallel tasks is reached |
| 358 | 358 | if ($runningTasks >= $this->maxParallelTasks) { |
| 359 | - if (LOG_TASKS=== true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 359 | + if (LOG_TASKS === true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 360 | 360 | return; |
| 361 | 361 | } |
| 362 | 362 | |
@@ -365,7 +365,7 @@ discard block |
||
| 365 | 365 | // Fetch next batch of tasks |
| 366 | 366 | $tasks = DB::query( |
| 367 | 367 | 'SELECT increment_id, process_type, arguments |
| 368 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 368 | + FROM ' . prefixTable('background_tasks').' |
|
| 369 | 369 | WHERE is_in_progress = 0 |
| 370 | 370 | AND (finished_at IS NULL OR finished_at = "") |
| 371 | 371 | ORDER BY increment_id ASC |
@@ -374,7 +374,7 @@ discard block |
||
| 374 | 374 | ); |
| 375 | 375 | |
| 376 | 376 | foreach ($tasks as $task) { |
| 377 | - if (LOG_TASKS=== true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 377 | + if (LOG_TASKS === true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 378 | 378 | $this->processIndividualTask($task); |
| 379 | 379 | } |
| 380 | 380 | } |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | * @param array $task The task to process. |
| 386 | 386 | */ |
| 387 | 387 | private function processIndividualTask(array $task) { |
| 388 | - if (LOG_TASKS=== true) $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 388 | + if (LOG_TASKS === true) $this->logger->log('Starting task: '.print_r($task, true), 'INFO'); |
|
| 389 | 389 | |
| 390 | 390 | // Store progress in the database |
| 391 | 391 | DB::update( |
@@ -404,7 +404,7 @@ discard block |
||
| 404 | 404 | $cmd = sprintf( |
| 405 | 405 | '%s %s %d %s %s', |
| 406 | 406 | escapeshellarg(PHP_BINARY), |
| 407 | - escapeshellarg(__DIR__ . '/background_tasks___worker.php'), |
|
| 407 | + escapeshellarg(__DIR__.'/background_tasks___worker.php'), |
|
| 408 | 408 | (int) $task['increment_id'], |
| 409 | 409 | escapeshellarg((string) $task['process_type']), |
| 410 | 410 | escapeshellarg((string) $task['arguments']) |
@@ -422,7 +422,7 @@ discard block |
||
| 422 | 422 | $msg = $e->getMessage(); |
| 423 | 423 | $last = error_get_last(); |
| 424 | 424 | if (is_array($last)) { |
| 425 | - $msg .= ' | last_error=' . json_encode($last); |
|
| 425 | + $msg .= ' | last_error='.json_encode($last); |
|
| 426 | 426 | } |
| 427 | 427 | |
| 428 | 428 | if (strpos($msg, 'Unable to launch a new process') !== false) { |
@@ -430,18 +430,18 @@ discard block |
||
| 430 | 430 | $rc = 0; |
| 431 | 431 | |
| 432 | 432 | // fallback run (blocking) |
| 433 | - exec($cmd . ' 2>&1', $out, $rc); |
|
| 433 | + exec($cmd.' 2>&1', $out, $rc); |
|
| 434 | 434 | |
| 435 | 435 | if ($rc === 0) { |
| 436 | 436 | // Worker ran successfully and updated the DB itself |
| 437 | - if (LOG_TASKS === true) $this->logger->log('Fallback exec succeeded for task ' . $task['increment_id'], 'INFO'); |
|
| 437 | + if (LOG_TASKS === true) $this->logger->log('Fallback exec succeeded for task '.$task['increment_id'], 'INFO'); |
|
| 438 | 438 | return; |
| 439 | 439 | } |
| 440 | 440 | |
| 441 | - $msg .= ' | fallback_exit=' . $rc . ' | fallback_out=' . implode("\n", array_slice($out, -30)); |
|
| 441 | + $msg .= ' | fallback_exit='.$rc.' | fallback_out='.implode("\n", array_slice($out, -30)); |
|
| 442 | 442 | } |
| 443 | 443 | |
| 444 | - if (LOG_TASKS=== true) $this->logger->log('Error launching task: ' . $msg, 'ERROR'); |
|
| 444 | + if (LOG_TASKS === true) $this->logger->log('Error launching task: '.$msg, 'ERROR'); |
|
| 445 | 445 | |
| 446 | 446 | DB::update( |
| 447 | 447 | prefixTable('background_tasks'), |
@@ -464,7 +464,7 @@ discard block |
||
| 464 | 464 | private function countRunningTasks(): int { |
| 465 | 465 | return DB::queryFirstField( |
| 466 | 466 | 'SELECT COUNT(*) |
| 467 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 467 | + FROM ' . prefixTable('background_tasks').' |
|
| 468 | 468 | WHERE is_in_progress = 1' |
| 469 | 469 | ); |
| 470 | 470 | } |
@@ -485,10 +485,10 @@ discard block |
||
| 485 | 485 | */ |
| 486 | 486 | private function cleanMultipleItemsEdition() { |
| 487 | 487 | DB::query( |
| 488 | - 'DELETE i1 FROM ' . prefixTable('items_edition') . ' i1 |
|
| 488 | + 'DELETE i1 FROM '.prefixTable('items_edition').' i1 |
|
| 489 | 489 | JOIN ( |
| 490 | 490 | SELECT user_id, item_id, MIN(timestamp) AS oldest_timestamp |
| 491 | - FROM ' . prefixTable('items_edition') . ' |
|
| 491 | + FROM ' . prefixTable('items_edition').' |
|
| 492 | 492 | GROUP BY user_id, item_id |
| 493 | 493 | ) i2 ON i1.user_id = i2.user_id AND i1.item_id = i2.item_id |
| 494 | 494 | WHERE i1.timestamp > i2.oldest_timestamp' |
@@ -501,7 +501,7 @@ discard block |
||
| 501 | 501 | */ |
| 502 | 502 | private function handleItemTokensExpiration() { |
| 503 | 503 | DB::query( |
| 504 | - 'DELETE FROM ' . prefixTable('items_edition') . ' |
|
| 504 | + 'DELETE FROM '.prefixTable('items_edition').' |
|
| 505 | 505 | WHERE timestamp < %i', |
| 506 | 506 | time() - ($this->settings['delay_item_edition'] * 60 ?: EDITION_LOCK_PERIOD) |
| 507 | 507 | ); |
@@ -518,7 +518,7 @@ discard block |
||
| 518 | 518 | // 1. Get all finished tasks older than the cutoff timestamp |
| 519 | 519 | // and that are not in progress |
| 520 | 520 | $tasks = DB::query( |
| 521 | - 'SELECT increment_id FROM ' . prefixTable('background_tasks') . ' |
|
| 521 | + 'SELECT increment_id FROM '.prefixTable('background_tasks').' |
|
| 522 | 522 | WHERE status = %s AND is_in_progress = %i AND finished_at < %i', |
| 523 | 523 | 'completed', |
| 524 | 524 | -1, |
@@ -533,19 +533,19 @@ discard block |
||
| 533 | 533 | |
| 534 | 534 | // 2. Delete all subtasks related to these tasks |
| 535 | 535 | DB::query( |
| 536 | - 'DELETE FROM ' . prefixTable('background_subtasks') . ' |
|
| 536 | + 'DELETE FROM '.prefixTable('background_subtasks').' |
|
| 537 | 537 | WHERE task_id IN %ls', |
| 538 | 538 | $taskIds |
| 539 | 539 | ); |
| 540 | 540 | |
| 541 | 541 | // 3. Delete the tasks themselves |
| 542 | 542 | DB::query( |
| 543 | - 'DELETE FROM ' . prefixTable('background_tasks') . ' |
|
| 543 | + 'DELETE FROM '.prefixTable('background_tasks').' |
|
| 544 | 544 | WHERE increment_id IN %ls', |
| 545 | 545 | $taskIds |
| 546 | 546 | ); |
| 547 | 547 | |
| 548 | - if (LOG_TASKS=== true) $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 548 | + if (LOG_TASKS === true) $this->logger->log('Old finished tasks cleaned: '.count($taskIds), 'INFO'); |
|
| 549 | 549 | } |
| 550 | 550 | } |
| 551 | 551 | |
@@ -559,5 +559,5 @@ discard block |
||
| 559 | 559 | $tasksHandler = new BackgroundTasksHandler($settings); |
| 560 | 560 | $tasksHandler->processBackgroundTasks(); |
| 561 | 561 | } catch (Exception $e) { |
| 562 | - error_log('Teampass Background Tasks Error: ' . $e->getMessage()); |
|
| 562 | + error_log('Teampass Background Tasks Error: '.$e->getMessage()); |
|
| 563 | 563 | } |
@@ -72,7 +72,9 @@ discard block |
||
| 72 | 72 | public function processBackgroundTasks() { |
| 73 | 73 | // Prevent multiple concurrent executions |
| 74 | 74 | if (!$this->acquireProcessLock()) { |
| 75 | - if (LOG_TASKS=== true) $this->logger->log('Process already running', 'INFO'); |
|
| 75 | + if (LOG_TASKS=== true) { |
|
| 76 | + $this->logger->log('Process already running', 'INFO'); |
|
| 77 | + } |
|
| 76 | 78 | return false; |
| 77 | 79 | } |
| 78 | 80 | |
@@ -82,7 +84,9 @@ discard block |
||
| 82 | 84 | $this->processTaskBatches(); |
| 83 | 85 | $this->performMaintenanceTasks(); |
| 84 | 86 | } catch (Exception $e) { |
| 85 | - if (LOG_TASKS=== true) $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 87 | + if (LOG_TASKS=== true) { |
|
| 88 | + $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 89 | + } |
|
| 86 | 90 | } finally { |
| 87 | 91 | $this->releaseProcessLock(); |
| 88 | 92 | } |
@@ -112,7 +116,9 @@ discard block |
||
| 112 | 116 | if ($nextRunAt <= 0) { |
| 113 | 117 | $nextRunAt = $this->computeNextBackupRunAt($now); |
| 114 | 118 | $this->upsertSettingValue('bck_scheduled_next_run_at', (string)$nextRunAt); |
| 115 | - if (LOG_TASKS === true) $this->logger->log('backup scheduler initialized next_run_at=' . $nextRunAt, 'INFO'); |
|
| 119 | + if (LOG_TASKS === true) { |
|
| 120 | + $this->logger->log('backup scheduler initialized next_run_at=' . $nextRunAt, 'INFO'); |
|
| 121 | + } |
|
| 116 | 122 | return; |
| 117 | 123 | } |
| 118 | 124 | |
@@ -131,7 +137,9 @@ discard block |
||
| 131 | 137 | ); |
| 132 | 138 | |
| 133 | 139 | if ($pending > 0) { |
| 134 | - if (LOG_TASKS === true) $this->logger->log('backup scheduler: a database_backup task is already pending/running', 'INFO'); |
|
| 140 | + if (LOG_TASKS === true) { |
|
| 141 | + $this->logger->log('backup scheduler: a database_backup task is already pending/running', 'INFO'); |
|
| 142 | + } |
|
| 135 | 143 | return; |
| 136 | 144 | } |
| 137 | 145 | |
@@ -161,7 +169,9 @@ discard block |
||
| 161 | 169 | $newNext = $this->computeNextBackupRunAt($now + 60); |
| 162 | 170 | $this->upsertSettingValue('bck_scheduled_next_run_at', (string)$newNext); |
| 163 | 171 | |
| 164 | - if (LOG_TASKS === true) $this->logger->log('backup scheduler: enqueued database_backup, next_run_at=' . $newNext, 'INFO'); |
|
| 172 | + if (LOG_TASKS === true) { |
|
| 173 | + $this->logger->log('backup scheduler: enqueued database_backup, next_run_at=' . $newNext, 'INFO'); |
|
| 174 | + } |
|
| 165 | 175 | } |
| 166 | 176 | |
| 167 | 177 | /** |
@@ -207,7 +217,9 @@ discard block |
||
| 207 | 217 | |
| 208 | 218 | if ($freq === 'weekly') { |
| 209 | 219 | $targetDow = (int)$this->getSettingValue('bck_scheduled_dow', '1'); // ISO 1..7 |
| 210 | - if ($targetDow < 1 || $targetDow > 7) $targetDow = 1; |
|
| 220 | + if ($targetDow < 1 || $targetDow > 7) { |
|
| 221 | + $targetDow = 1; |
|
| 222 | + } |
|
| 211 | 223 | |
| 212 | 224 | $currentDow = (int)$candidate->format('N'); |
| 213 | 225 | $delta = ($targetDow - $currentDow + 7) % 7; |
@@ -218,8 +230,12 @@ discard block |
||
| 218 | 230 | |
| 219 | 231 | } elseif ($freq === 'monthly') { |
| 220 | 232 | $dom = (int)$this->getSettingValue('bck_scheduled_dom', '1'); |
| 221 | - if ($dom < 1) $dom = 1; |
|
| 222 | - if ($dom > 31) $dom = 31; |
|
| 233 | + if ($dom < 1) { |
|
| 234 | + $dom = 1; |
|
| 235 | + } |
|
| 236 | + if ($dom > 31) { |
|
| 237 | + $dom = 31; |
|
| 238 | + } |
|
| 223 | 239 | |
| 224 | 240 | $year = (int)$now->format('Y'); |
| 225 | 241 | $month = (int)$now->format('m'); |
@@ -356,7 +372,9 @@ discard block |
||
| 356 | 372 | |
| 357 | 373 | // Check if the maximum number of parallel tasks is reached |
| 358 | 374 | if ($runningTasks >= $this->maxParallelTasks) { |
| 359 | - if (LOG_TASKS=== true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 375 | + if (LOG_TASKS=== true) { |
|
| 376 | + $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 377 | + } |
|
| 360 | 378 | return; |
| 361 | 379 | } |
| 362 | 380 | |
@@ -374,7 +392,9 @@ discard block |
||
| 374 | 392 | ); |
| 375 | 393 | |
| 376 | 394 | foreach ($tasks as $task) { |
| 377 | - if (LOG_TASKS=== true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 395 | + if (LOG_TASKS=== true) { |
|
| 396 | + $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 397 | + } |
|
| 378 | 398 | $this->processIndividualTask($task); |
| 379 | 399 | } |
| 380 | 400 | } |
@@ -385,7 +405,9 @@ discard block |
||
| 385 | 405 | * @param array $task The task to process. |
| 386 | 406 | */ |
| 387 | 407 | private function processIndividualTask(array $task) { |
| 388 | - if (LOG_TASKS=== true) $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 408 | + if (LOG_TASKS=== true) { |
|
| 409 | + $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 410 | + } |
|
| 389 | 411 | |
| 390 | 412 | // Store progress in the database |
| 391 | 413 | DB::update( |
@@ -434,14 +456,18 @@ discard block |
||
| 434 | 456 | |
| 435 | 457 | if ($rc === 0) { |
| 436 | 458 | // Worker ran successfully and updated the DB itself |
| 437 | - if (LOG_TASKS === true) $this->logger->log('Fallback exec succeeded for task ' . $task['increment_id'], 'INFO'); |
|
| 459 | + if (LOG_TASKS === true) { |
|
| 460 | + $this->logger->log('Fallback exec succeeded for task ' . $task['increment_id'], 'INFO'); |
|
| 461 | + } |
|
| 438 | 462 | return; |
| 439 | 463 | } |
| 440 | 464 | |
| 441 | 465 | $msg .= ' | fallback_exit=' . $rc . ' | fallback_out=' . implode("\n", array_slice($out, -30)); |
| 442 | 466 | } |
| 443 | 467 | |
| 444 | - if (LOG_TASKS=== true) $this->logger->log('Error launching task: ' . $msg, 'ERROR'); |
|
| 468 | + if (LOG_TASKS=== true) { |
|
| 469 | + $this->logger->log('Error launching task: ' . $msg, 'ERROR'); |
|
| 470 | + } |
|
| 445 | 471 | |
| 446 | 472 | DB::update( |
| 447 | 473 | prefixTable('background_tasks'), |
@@ -545,7 +571,9 @@ discard block |
||
| 545 | 571 | $taskIds |
| 546 | 572 | ); |
| 547 | 573 | |
| 548 | - if (LOG_TASKS=== true) $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 574 | + if (LOG_TASKS=== true) { |
|
| 575 | + $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 576 | + } |
|
| 549 | 577 | } |
| 550 | 578 | } |
| 551 | 579 | |
@@ -33,7 +33,7 @@ discard block |
||
| 33 | 33 | require_once __DIR__.'/traits/UserHandlerTrait.php'; |
| 34 | 34 | require_once __DIR__.'/traits/EmailTrait.php'; |
| 35 | 35 | require_once __DIR__.'/traits/MigrateUserHandlerTrait.php'; |
| 36 | -require_once __DIR__ . '/taskLogger.php'; |
|
| 36 | +require_once __DIR__.'/taskLogger.php'; |
|
| 37 | 37 | |
| 38 | 38 | class TaskWorker { |
| 39 | 39 | use ItemHandlerTrait; |
@@ -66,7 +66,7 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function execute() { |
| 68 | 68 | try { |
| 69 | - if (LOG_TASKS=== true) $this->logger->log('Processing task: ' . print_r($this->taskData, true), 'DEBUG'); |
|
| 69 | + if (LOG_TASKS === true) $this->logger->log('Processing task: '.print_r($this->taskData, true), 'DEBUG'); |
|
| 70 | 70 | // Dispatch selon le type de processus |
| 71 | 71 | switch ($this->processType) { |
| 72 | 72 | case 'item_copy': |
@@ -114,11 +114,11 @@ discard block |
||
| 114 | 114 | */ |
| 115 | 115 | private function handleDatabaseBackup(array $taskData): void |
| 116 | 116 | { |
| 117 | - require_once __DIR__ . '/../sources/backup.functions.php'; |
|
| 117 | + require_once __DIR__.'/../sources/backup.functions.php'; |
|
| 118 | 118 | |
| 119 | 119 | // Default target dir: <path_to_files_folder>/backups |
| 120 | - $baseFilesDir = (string)($this->settings['path_to_files_folder'] ?? (__DIR__ . '/../files')); |
|
| 121 | - $targetDir = rtrim($baseFilesDir, '/') . '/backups'; |
|
| 120 | + $baseFilesDir = (string) ($this->settings['path_to_files_folder'] ?? (__DIR__.'/../files')); |
|
| 121 | + $targetDir = rtrim($baseFilesDir, '/').'/backups'; |
|
| 122 | 122 | |
| 123 | 123 | // Allow override via task arguments (optional) |
| 124 | 124 | if (!empty($taskData['output_dir']) && is_string($taskData['output_dir'])) { |
@@ -127,15 +127,15 @@ discard block |
||
| 127 | 127 | |
| 128 | 128 | if (!is_dir($targetDir)) { |
| 129 | 129 | if (!@mkdir($targetDir, 0770, true) && !is_dir($targetDir)) { |
| 130 | - throw new Exception('Cannot create backup target dir: ' . $targetDir); |
|
| 130 | + throw new Exception('Cannot create backup target dir: '.$targetDir); |
|
| 131 | 131 | } |
| 132 | 132 | } |
| 133 | 133 | if (!is_writable($targetDir)) { |
| 134 | - throw new Exception('Backup target dir is not writable: ' . $targetDir); |
|
| 134 | + throw new Exception('Backup target dir is not writable: '.$targetDir); |
|
| 135 | 135 | } |
| 136 | 136 | |
| 137 | 137 | // Use stored encryption key (same as UI) |
| 138 | - $encryptionKey = (string)($this->settings['bck_script_passkey'] ?? ''); |
|
| 138 | + $encryptionKey = (string) ($this->settings['bck_script_passkey'] ?? ''); |
|
| 139 | 139 | if ($encryptionKey === '') { |
| 140 | 140 | throw new Exception('Missing encryption key (bck_script_passkey).'); |
| 141 | 141 | } |
@@ -151,25 +151,25 @@ discard block |
||
| 151 | 151 | |
| 152 | 152 | // Store a tiny summary for the task completion "arguments" field (no secrets) |
| 153 | 153 | $this->taskData['backup_file'] = $res['filename'] ?? ''; |
| 154 | - $this->taskData['backup_size_bytes'] = (int)($res['size_bytes'] ?? 0); |
|
| 155 | - $this->taskData['backup_encrypted'] = (bool)($res['encrypted'] ?? false); |
|
| 154 | + $this->taskData['backup_size_bytes'] = (int) ($res['size_bytes'] ?? 0); |
|
| 155 | + $this->taskData['backup_encrypted'] = (bool) ($res['encrypted'] ?? false); |
|
| 156 | 156 | |
| 157 | 157 | // Retention purge (scheduled backups only) |
| 158 | - $backupSource = (string)($taskData['source'] ?? ''); |
|
| 159 | - $backupDir = (string)($taskData['output_dir'] ?? ''); // from task arguments (reliable) |
|
| 158 | + $backupSource = (string) ($taskData['source'] ?? ''); |
|
| 159 | + $backupDir = (string) ($taskData['output_dir'] ?? ''); // from task arguments (reliable) |
|
| 160 | 160 | if ($backupDir === '') { |
| 161 | - $backupDir = (string)($targetDir ?? ''); // fallback if you have it |
|
| 161 | + $backupDir = (string) ($targetDir ?? ''); // fallback if you have it |
|
| 162 | 162 | } |
| 163 | 163 | |
| 164 | 164 | // keep for debug/trace |
| 165 | 165 | $this->taskData['output_dir'] = $backupDir; |
| 166 | 166 | |
| 167 | 167 | if ($backupSource === 'scheduler' && $backupDir !== '') { |
| 168 | - $days = (int)$this->getMiscSetting('bck_scheduled_retention_days', '30'); |
|
| 168 | + $days = (int) $this->getMiscSetting('bck_scheduled_retention_days', '30'); |
|
| 169 | 169 | $deleted = $this->purgeOldScheduledBackups($backupDir, $days); |
| 170 | 170 | |
| 171 | - $this->upsertMiscSetting('bck_scheduled_last_purge_at', (string)time()); |
|
| 172 | - $this->upsertMiscSetting('bck_scheduled_last_purge_deleted', (string)$deleted); |
|
| 171 | + $this->upsertMiscSetting('bck_scheduled_last_purge_at', (string) time()); |
|
| 172 | + $this->upsertMiscSetting('bck_scheduled_last_purge_deleted', (string) $deleted); |
|
| 173 | 173 | |
| 174 | 174 | if (LOG_TASKS === true) { |
| 175 | 175 | $this->logger->log("database_backup: purge retention={$days}d dir={$backupDir} deleted={$deleted}", 'INFO'); |
@@ -178,12 +178,12 @@ discard block |
||
| 178 | 178 | |
| 179 | 179 | // If launched by scheduler, update scheduler status in teampass_misc |
| 180 | 180 | if (!empty($taskData['source']) && $taskData['source'] === 'scheduler') { |
| 181 | - $this->updateSchedulerState('completed', 'Backup created: ' . ($this->taskData['backup_file'] ?? '')); |
|
| 181 | + $this->updateSchedulerState('completed', 'Backup created: '.($this->taskData['backup_file'] ?? '')); |
|
| 182 | 182 | } |
| 183 | 183 | |
| 184 | 184 | if (LOG_TASKS === true) { |
| 185 | 185 | $this->logger->log( |
| 186 | - 'database_backup: created ' . ($this->taskData['backup_file'] ?? '') . ' (' . $this->taskData['backup_size_bytes'] . ' bytes)', |
|
| 186 | + 'database_backup: created '.($this->taskData['backup_file'] ?? '').' ('.$this->taskData['backup_size_bytes'].' bytes)', |
|
| 187 | 187 | 'INFO' |
| 188 | 188 | ); |
| 189 | 189 | } |
@@ -199,15 +199,15 @@ discard block |
||
| 199 | 199 | { |
| 200 | 200 | $this->upsertMiscSetting('bck_scheduled_last_status', $status); |
| 201 | 201 | $this->upsertMiscSetting('bck_scheduled_last_message', mb_substr($message, 0, 500)); |
| 202 | - $this->upsertMiscSetting('bck_scheduled_last_completed_at', (string)time()); |
|
| 202 | + $this->upsertMiscSetting('bck_scheduled_last_completed_at', (string) time()); |
|
| 203 | 203 | } |
| 204 | 204 | |
| 205 | 205 | private function upsertMiscSetting(string $key, string $value): void |
| 206 | 206 | { |
| 207 | 207 | $table = prefixTable('misc'); |
| 208 | 208 | |
| 209 | - $exists = (int)DB::queryFirstField( |
|
| 210 | - 'SELECT COUNT(*) FROM ' . $table . ' WHERE type = %s AND intitule = %s', |
|
| 209 | + $exists = (int) DB::queryFirstField( |
|
| 210 | + 'SELECT COUNT(*) FROM '.$table.' WHERE type = %s AND intitule = %s', |
|
| 211 | 211 | 'settings', |
| 212 | 212 | $key |
| 213 | 213 | ); |
@@ -224,7 +224,7 @@ discard block |
||
| 224 | 224 | $table = prefixTable('misc'); |
| 225 | 225 | |
| 226 | 226 | $val = DB::queryFirstField( |
| 227 | - 'SELECT valeur FROM ' . $table . ' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 227 | + 'SELECT valeur FROM '.$table.' WHERE type = %s AND intitule = %s LIMIT 1', |
|
| 228 | 228 | 'settings', |
| 229 | 229 | $key |
| 230 | 230 | ); |
@@ -249,7 +249,7 @@ discard block |
||
| 249 | 249 | $cutoff = time() - ($retentionDays * 86400); |
| 250 | 250 | $deleted = 0; |
| 251 | 251 | |
| 252 | - foreach (glob(rtrim($dir, '/') . '/scheduled-*.sql') as $file) { |
|
| 252 | + foreach (glob(rtrim($dir, '/').'/scheduled-*.sql') as $file) { |
|
| 253 | 253 | if (!is_file($file)) { |
| 254 | 254 | continue; |
| 255 | 255 | } |
@@ -271,7 +271,7 @@ discard block |
||
| 271 | 271 | 'is_in_progress' => -1, |
| 272 | 272 | 'finished_at' => time(), |
| 273 | 273 | 'status' => 'completed', |
| 274 | - 'error_message' => null, // <-- on efface toute erreur précédente |
|
| 274 | + 'error_message' => null, // <-- on efface toute erreur précédente |
|
| 275 | 275 | ]; |
| 276 | 276 | |
| 277 | 277 | // Prepare anonimzation of arguments |
@@ -307,7 +307,7 @@ discard block |
||
| 307 | 307 | $arguments = ''; |
| 308 | 308 | } |
| 309 | 309 | |
| 310 | - if (LOG_TASKS=== true) $this->logger->log('Process: '.$this->processType.' -- '.print_r($arguments, true), 'DEBUG'); |
|
| 310 | + if (LOG_TASKS === true) $this->logger->log('Process: '.$this->processType.' -- '.print_r($arguments, true), 'DEBUG'); |
|
| 311 | 311 | |
| 312 | 312 | // Add 'arguments' only if not empty |
| 313 | 313 | if (!empty($arguments)) { |
@@ -322,7 +322,7 @@ discard block |
||
| 322 | 322 | $this->taskId |
| 323 | 323 | ); |
| 324 | 324 | |
| 325 | - if (LOG_TASKS=== true) $this->logger->log('Finishing task: ' . $this->taskId, 'DEBUG'); |
|
| 325 | + if (LOG_TASKS === true) $this->logger->log('Finishing task: '.$this->taskId, 'DEBUG'); |
|
| 326 | 326 | } |
| 327 | 327 | |
| 328 | 328 | /** |
@@ -345,15 +345,15 @@ discard block |
||
| 345 | 345 | 'increment_id = %i', |
| 346 | 346 | $this->taskId |
| 347 | 347 | ); |
| 348 | - $this->logger->log('Task failure: ' . $e->getMessage(), 'ERROR'); |
|
| 348 | + $this->logger->log('Task failure: '.$e->getMessage(), 'ERROR'); |
|
| 349 | 349 | // Purge retention even on failure (safe: only scheduled-*.sql) |
| 350 | - $backupDir = (string)($this->taskData['output_dir'] ?? ''); |
|
| 350 | + $backupDir = (string) ($this->taskData['output_dir'] ?? ''); |
|
| 351 | 351 | if ($backupDir !== '' && is_dir($backupDir)) { |
| 352 | - $days = (int)$this->getMiscSetting('bck_scheduled_retention_days', '30'); |
|
| 352 | + $days = (int) $this->getMiscSetting('bck_scheduled_retention_days', '30'); |
|
| 353 | 353 | $deleted = $this->purgeOldScheduledBackups($backupDir, $days); |
| 354 | 354 | |
| 355 | - $this->upsertMiscSetting('bck_scheduled_last_purge_at', (string)time()); |
|
| 356 | - $this->upsertMiscSetting('bck_scheduled_last_purge_deleted', (string)$deleted); |
|
| 355 | + $this->upsertMiscSetting('bck_scheduled_last_purge_at', (string) time()); |
|
| 356 | + $this->upsertMiscSetting('bck_scheduled_last_purge_deleted', (string) $deleted); |
|
| 357 | 357 | } |
| 358 | 358 | } |
| 359 | 359 | |
@@ -366,16 +366,16 @@ discard block |
||
| 366 | 366 | * @return void |
| 367 | 367 | */ |
| 368 | 368 | private function processSubTasks($arguments) { |
| 369 | - if (LOG_TASKS=== true) $this->logger->log('processSubTasks: '.print_r($arguments, true), 'DEBUG'); |
|
| 369 | + if (LOG_TASKS === true) $this->logger->log('processSubTasks: '.print_r($arguments, true), 'DEBUG'); |
|
| 370 | 370 | // Get all subtasks related to this task |
| 371 | 371 | $subtasks = DB::query( |
| 372 | - 'SELECT * FROM ' . prefixTable('background_subtasks') . ' WHERE task_id = %i AND is_in_progress = 0 ORDER BY `task` ASC', |
|
| 372 | + 'SELECT * FROM '.prefixTable('background_subtasks').' WHERE task_id = %i AND is_in_progress = 0 ORDER BY `task` ASC', |
|
| 373 | 373 | $this->taskId |
| 374 | 374 | ); |
| 375 | 375 | |
| 376 | 376 | // Check if there are any subtasks to process |
| 377 | 377 | if (empty($subtasks)) { |
| 378 | - if (LOG_TASKS=== true) $this->logger->log('No subtask was found for task: ' . $this->taskId, 'DEBUG'); |
|
| 378 | + if (LOG_TASKS === true) $this->logger->log('No subtask was found for task: '.$this->taskId, 'DEBUG'); |
|
| 379 | 379 | return; |
| 380 | 380 | } |
| 381 | 381 | |
@@ -385,7 +385,7 @@ discard block |
||
| 385 | 385 | // Get the subtask data |
| 386 | 386 | $subtaskData = json_decode($subtask['task'], true); |
| 387 | 387 | |
| 388 | - if (LOG_TASKS=== true) $this->logger->log('Processing subtask: ' . $subtaskData['step'], 'DEBUG'); |
|
| 388 | + if (LOG_TASKS === true) $this->logger->log('Processing subtask: '.$subtaskData['step'], 'DEBUG'); |
|
| 389 | 389 | |
| 390 | 390 | // Mark subtask as in progress |
| 391 | 391 | DB::update( |
@@ -437,13 +437,13 @@ discard block |
||
| 437 | 437 | $subtask['increment_id'] |
| 438 | 438 | ); |
| 439 | 439 | |
| 440 | - $this->logger->log('processSubTasks : ' . $e->getMessage(), 'ERROR'); |
|
| 440 | + $this->logger->log('processSubTasks : '.$e->getMessage(), 'ERROR'); |
|
| 441 | 441 | } |
| 442 | 442 | } |
| 443 | 443 | |
| 444 | 444 | // Are all subtasks completed? |
| 445 | 445 | $remainingSubtasks = DB::queryFirstField( |
| 446 | - 'SELECT COUNT(*) FROM ' . prefixTable('background_subtasks') . ' WHERE task_id = %i AND is_in_progress = 0', |
|
| 446 | + 'SELECT COUNT(*) FROM '.prefixTable('background_subtasks').' WHERE task_id = %i AND is_in_progress = 0', |
|
| 447 | 447 | $this->taskId |
| 448 | 448 | ); |
| 449 | 449 | |
@@ -459,7 +459,7 @@ discard block |
||
| 459 | 459 | error_log("Usage: php background_tasks___worker.php <task_id> <process_type> [<task_data>]"); |
| 460 | 460 | exit(1); |
| 461 | 461 | } |
| 462 | -$taskId = (int)$argv[1]; |
|
| 462 | +$taskId = (int) $argv[1]; |
|
| 463 | 463 | $processType = $argv[2]; |
| 464 | 464 | $taskData = $argv[3] ?? null; |
| 465 | 465 | if ($taskData) { |
@@ -66,7 +66,9 @@ discard block |
||
| 66 | 66 | */ |
| 67 | 67 | public function execute() { |
| 68 | 68 | try { |
| 69 | - if (LOG_TASKS=== true) $this->logger->log('Processing task: ' . print_r($this->taskData, true), 'DEBUG'); |
|
| 69 | + if (LOG_TASKS=== true) { |
|
| 70 | + $this->logger->log('Processing task: ' . print_r($this->taskData, true), 'DEBUG'); |
|
| 71 | + } |
|
| 70 | 72 | // Dispatch selon le type de processus |
| 71 | 73 | switch ($this->processType) { |
| 72 | 74 | case 'item_copy': |
@@ -307,7 +309,9 @@ discard block |
||
| 307 | 309 | $arguments = ''; |
| 308 | 310 | } |
| 309 | 311 | |
| 310 | - if (LOG_TASKS=== true) $this->logger->log('Process: '.$this->processType.' -- '.print_r($arguments, true), 'DEBUG'); |
|
| 312 | + if (LOG_TASKS=== true) { |
|
| 313 | + $this->logger->log('Process: '.$this->processType.' -- '.print_r($arguments, true), 'DEBUG'); |
|
| 314 | + } |
|
| 311 | 315 | |
| 312 | 316 | // Add 'arguments' only if not empty |
| 313 | 317 | if (!empty($arguments)) { |
@@ -322,7 +326,9 @@ discard block |
||
| 322 | 326 | $this->taskId |
| 323 | 327 | ); |
| 324 | 328 | |
| 325 | - if (LOG_TASKS=== true) $this->logger->log('Finishing task: ' . $this->taskId, 'DEBUG'); |
|
| 329 | + if (LOG_TASKS=== true) { |
|
| 330 | + $this->logger->log('Finishing task: ' . $this->taskId, 'DEBUG'); |
|
| 331 | + } |
|
| 326 | 332 | } |
| 327 | 333 | |
| 328 | 334 | /** |
@@ -366,7 +372,9 @@ discard block |
||
| 366 | 372 | * @return void |
| 367 | 373 | */ |
| 368 | 374 | private function processSubTasks($arguments) { |
| 369 | - if (LOG_TASKS=== true) $this->logger->log('processSubTasks: '.print_r($arguments, true), 'DEBUG'); |
|
| 375 | + if (LOG_TASKS=== true) { |
|
| 376 | + $this->logger->log('processSubTasks: '.print_r($arguments, true), 'DEBUG'); |
|
| 377 | + } |
|
| 370 | 378 | // Get all subtasks related to this task |
| 371 | 379 | $subtasks = DB::query( |
| 372 | 380 | 'SELECT * FROM ' . prefixTable('background_subtasks') . ' WHERE task_id = %i AND is_in_progress = 0 ORDER BY `task` ASC', |
@@ -375,7 +383,9 @@ discard block |
||
| 375 | 383 | |
| 376 | 384 | // Check if there are any subtasks to process |
| 377 | 385 | if (empty($subtasks)) { |
| 378 | - if (LOG_TASKS=== true) $this->logger->log('No subtask was found for task: ' . $this->taskId, 'DEBUG'); |
|
| 386 | + if (LOG_TASKS=== true) { |
|
| 387 | + $this->logger->log('No subtask was found for task: ' . $this->taskId, 'DEBUG'); |
|
| 388 | + } |
|
| 379 | 389 | return; |
| 380 | 390 | } |
| 381 | 391 | |
@@ -385,7 +395,9 @@ discard block |
||
| 385 | 395 | // Get the subtask data |
| 386 | 396 | $subtaskData = json_decode($subtask['task'], true); |
| 387 | 397 | |
| 388 | - if (LOG_TASKS=== true) $this->logger->log('Processing subtask: ' . $subtaskData['step'], 'DEBUG'); |
|
| 398 | + if (LOG_TASKS=== true) { |
|
| 399 | + $this->logger->log('Processing subtask: ' . $subtaskData['step'], 'DEBUG'); |
|
| 400 | + } |
|
| 389 | 401 | |
| 390 | 402 | // Mark subtask as in progress |
| 391 | 403 | DB::update( |
@@ -69,7 +69,7 @@ discard block |
||
| 69 | 69 | if ($checkUserAccess->checkSession() === false || $checkUserAccess->userAccessPage('backups') === false) { |
| 70 | 70 | // Not allowed page |
| 71 | 71 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 72 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 72 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 73 | 73 | exit; |
| 74 | 74 | } |
| 75 | 75 | |
@@ -196,7 +196,7 @@ discard block |
||
| 196 | 196 | </div> |
| 197 | 197 | <div class="alert alert-info ml-2 mt-3 mr-2 hidden" id="onthefly-restore-progress"> |
| 198 | 198 | <h5><i class="icon fa fa-info mr-2"></i><?php echo $lang->get('in_progress'); ?></h5> |
| 199 | - <i class="mr-2 fas fa-rocket"></i><?php echo $lang->get('restore_in_progress');?> <b><span id="onthefly-restore-progress-text">0</span>%</b> |
|
| 199 | + <i class="mr-2 fas fa-rocket"></i><?php echo $lang->get('restore_in_progress'); ?> <b><span id="onthefly-restore-progress-text">0</span>%</b> |
|
| 200 | 200 | </div> |
| 201 | 201 | <div class="row mt-3 hidden" id="onthefly-restore-finished"></div> |
| 202 | 202 | <div class="row mt-3"> |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | <div class="tab-pane fade" id="scheduled" role="tabpanel" aria-labelledby="scheduled-tab"> |
| 242 | 242 | <div class="alert alert-info mt-3" id="scheduled-restore-info" style="display:none;"> |
| 243 | 243 | <i class="fas fa-info-circle"></i> |
| 244 | - <?php echo sprintf($lang->get('bck_restore_scheduled_info'), '<b>' . $lang->get('on_the_fly') . '</b>', '<b>' . $lang->get('bck_instance_encryption_key') . '</b>'); ?> |
|
| 244 | + <?php echo sprintf($lang->get('bck_restore_scheduled_info'), '<b>'.$lang->get('on_the_fly').'</b>', '<b>'.$lang->get('bck_instance_encryption_key').'</b>'); ?> |
|
| 245 | 245 | </div> |
| 246 | 246 | <div class="row"> |
| 247 | 247 | <div class="col-12 col-lg-6"> |
@@ -337,7 +337,7 @@ discard block |
||
| 337 | 337 | <div class="alert alert-info py-2 px-3 mb-3"> |
| 338 | 338 | <button type="button" class="btn btn-link p-0 tp-copy-instance-key" data-toggle="tooltip" title="<?php echo $lang->get('bck_instance_key_copy_tooltip'); ?>" aria-label="<?php echo $lang->get('bck_instance_key_copy_tooltip'); ?>"><i class="fas fa-info-circle"></i></button> |
| 339 | 339 | <?php |
| 340 | - echo $lang->get('bck_scheduled_note_encrypted');?> |
|
| 340 | + echo $lang->get('bck_scheduled_note_encrypted'); ?> |
|
| 341 | 341 | </div> |
| 342 | 342 | |
| 343 | 343 | <div class="table-responsive"> |
@@ -71,7 +71,7 @@ discard block |
||
| 71 | 71 | if ($checkUserAccess->checkSession() === false || $checkUserAccess->userAccessPage('backups') === false) { |
| 72 | 72 | // Not allowed page |
| 73 | 73 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 74 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 74 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 75 | 75 | exit; |
| 76 | 76 | } |
| 77 | 77 | ?> |
@@ -566,7 +566,7 @@ discard block |
||
| 566 | 566 | tpProgressToast.hide(); |
| 567 | 567 | toastr.remove(); |
| 568 | 568 | toastr.error( |
| 569 | - '<?php echo addslashes($lang->get('server_answer_error') . '<br />' . $lang->get('server_returned_data') . ':<br />'); ?>' + data.error, |
|
| 569 | + '<?php echo addslashes($lang->get('server_answer_error').'<br />'.$lang->get('server_returned_data').':<br />'); ?>' + data.error, |
|
| 570 | 570 | '<?php echo addslashes($lang->get('error')); ?>', { |
| 571 | 571 | timeOut: 5000, |
| 572 | 572 | progressBar: true |
@@ -944,7 +944,7 @@ discard block |
||
| 944 | 944 | // PREPARE UPLOADER with plupload |
| 945 | 945 | <?php |
| 946 | 946 | $maxFileSize = (strrpos($SETTINGS['upload_maxfilesize'], 'mb') === false) |
| 947 | - ? $SETTINGS['upload_maxfilesize'] . 'mb' |
|
| 947 | + ? $SETTINGS['upload_maxfilesize'].'mb' |
|
| 948 | 948 | : $SETTINGS['upload_maxfilesize']; |
| 949 | 949 | ?> |
| 950 | 950 | |