Passed
Pull Request — master (#5017)
by
unknown
06:15
created
sources/backups.queries.php 1 patch
Braces   +24 added lines, -8 removed lines patch added patch discarded remove patch
@@ -465,7 +465,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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);
Please login to merge, or discard this patch.
scripts/background_tasks___handler.php 1 patch
Braces   +42 added lines, -14 removed lines patch added patch discarded remove patch
@@ -72,7 +72,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 
Please login to merge, or discard this patch.
scripts/background_tasks___worker.php 1 patch
Braces   +18 added lines, -6 removed lines patch added patch discarded remove patch
@@ -66,7 +66,9 @@  discard block
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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
 block discarded – undo
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(
Please login to merge, or discard this patch.