@@ -108,8 +108,8 @@ discard block |
||
| 108 | 108 | // Delete subtasks linked to old finished tasks (avoid orphans) |
| 109 | 109 | DB::query( |
| 110 | 110 | 'DELETE s |
| 111 | - FROM ' . prefixTable('background_subtasks') . ' s |
|
| 112 | - INNER JOIN ' . prefixTable('background_tasks') . ' t ON t.increment_id = s.task_id |
|
| 111 | + FROM ' . prefixTable('background_subtasks').' s |
|
| 112 | + INNER JOIN ' . prefixTable('background_tasks').' t ON t.increment_id = s.task_id |
|
| 113 | 113 | WHERE t.finished_at > 0 |
| 114 | 114 | AND t.finished_at < %i', |
| 115 | 115 | $threshold |
@@ -145,11 +145,11 @@ discard block |
||
| 145 | 145 | function provideLog(string $message, array $SETTINGS) |
| 146 | 146 | { |
| 147 | 147 | if (defined('LOG_TO_SERVER') && LOG_TO_SERVER === true) { |
| 148 | - error_log((string) date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], time()) . ' - '.$message); |
|
| 148 | + error_log((string) date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], time()).' - '.$message); |
|
| 149 | 149 | } |
| 150 | 150 | } |
| 151 | 151 | |
| 152 | -function performVisibleFoldersHtmlUpdate (int $user_id) |
|
| 152 | +function performVisibleFoldersHtmlUpdate(int $user_id) |
|
| 153 | 153 | { |
| 154 | 154 | $html = []; |
| 155 | 155 | |
@@ -159,7 +159,7 @@ discard block |
||
| 159 | 159 | |
| 160 | 160 | // get current folders visible for user |
| 161 | 161 | $cache_tree = DB::queryFirstRow( |
| 162 | - 'SELECT increment_id, data FROM ' . prefixTable('cache_tree') . ' WHERE user_id = %i', |
|
| 162 | + 'SELECT increment_id, data FROM '.prefixTable('cache_tree').' WHERE user_id = %i', |
|
| 163 | 163 | $user_id |
| 164 | 164 | ); |
| 165 | 165 | $folders = json_decode($cache_tree['data'], true); |
@@ -175,7 +175,7 @@ discard block |
||
| 175 | 175 | |
| 176 | 176 | // get folder info |
| 177 | 177 | $folder = DB::queryFirstRow( |
| 178 | - 'SELECT title, parent_id, personal_folder FROM ' . prefixTable('nested_tree') . ' WHERE id = %i', |
|
| 178 | + 'SELECT title, parent_id, personal_folder FROM '.prefixTable('nested_tree').' WHERE id = %i', |
|
| 179 | 179 | $idFolder |
| 180 | 180 | ); |
| 181 | 181 | |
@@ -210,7 +210,7 @@ discard block |
||
| 210 | 210 | function subTaskStatus($taskId) |
| 211 | 211 | { |
| 212 | 212 | $subTasks = DB::query( |
| 213 | - 'SELECT * FROM ' . prefixTable('background_subtasks') . ' WHERE task_id = %i', |
|
| 213 | + 'SELECT * FROM '.prefixTable('background_subtasks').' WHERE task_id = %i', |
|
| 214 | 214 | $taskId |
| 215 | 215 | ); |
| 216 | 216 | |
@@ -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,7 +72,7 @@ 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 | |
@@ -81,7 +81,7 @@ discard block |
||
| 81 | 81 | $this->processTaskBatches(); |
| 82 | 82 | $this->performMaintenanceTasks(); |
| 83 | 83 | } catch (Exception $e) { |
| 84 | - if (LOG_TASKS=== true) $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 84 | + if (LOG_TASKS === true) $this->logger->log('Task processing error: '.$e->getMessage(), 'ERROR'); |
|
| 85 | 85 | } finally { |
| 86 | 86 | $this->releaseProcessLock(); |
| 87 | 87 | } |
@@ -100,7 +100,7 @@ discard block |
||
| 100 | 100 | return false; |
| 101 | 101 | } |
| 102 | 102 | |
| 103 | - fwrite($fp, (string)getmypid()); |
|
| 103 | + fwrite($fp, (string) getmypid()); |
|
| 104 | 104 | return true; |
| 105 | 105 | } |
| 106 | 106 | |
@@ -120,7 +120,7 @@ discard block |
||
| 120 | 120 | private function cleanupStaleTasks() { |
| 121 | 121 | // Mark tasks as failed if they've been running too long |
| 122 | 122 | DB::query( |
| 123 | - 'UPDATE ' . prefixTable('background_tasks') . ' |
|
| 123 | + 'UPDATE '.prefixTable('background_tasks').' |
|
| 124 | 124 | SET is_in_progress = -1, |
| 125 | 125 | finished_at = %i, |
| 126 | 126 | status = "failed", |
@@ -133,8 +133,8 @@ discard block |
||
| 133 | 133 | |
| 134 | 134 | // Remove very old failed tasks |
| 135 | 135 | DB::query( |
| 136 | - 'DELETE t, st FROM ' . prefixTable('background_tasks') . ' t |
|
| 137 | - INNER JOIN ' . prefixTable('background_subtasks') . ' st ON (t.increment_id = st.task_id) |
|
| 136 | + 'DELETE t, st FROM '.prefixTable('background_tasks').' t |
|
| 137 | + INNER JOIN ' . prefixTable('background_subtasks').' st ON (t.increment_id = st.task_id) |
|
| 138 | 138 | WHERE t.finished_at > 0 |
| 139 | 139 | AND t.finished_at < %i |
| 140 | 140 | AND t.status = %s', |
@@ -152,7 +152,7 @@ discard block |
||
| 152 | 152 | |
| 153 | 153 | // Check if the maximum number of parallel tasks is reached |
| 154 | 154 | if ($runningTasks >= $this->maxParallelTasks) { |
| 155 | - if (LOG_TASKS=== true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 155 | + if (LOG_TASKS === true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 156 | 156 | return; |
| 157 | 157 | } |
| 158 | 158 | |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | // Fetch next batch of tasks |
| 162 | 162 | $tasks = DB::query( |
| 163 | 163 | 'SELECT increment_id, process_type, arguments |
| 164 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 164 | + FROM ' . prefixTable('background_tasks').' |
|
| 165 | 165 | WHERE is_in_progress = 0 |
| 166 | 166 | AND (finished_at IS NULL OR finished_at = "") |
| 167 | 167 | ORDER BY increment_id ASC |
@@ -170,7 +170,7 @@ discard block |
||
| 170 | 170 | ); |
| 171 | 171 | |
| 172 | 172 | foreach ($tasks as $task) { |
| 173 | - if (LOG_TASKS=== true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 173 | + if (LOG_TASKS === true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 174 | 174 | $this->processIndividualTask($task); |
| 175 | 175 | } |
| 176 | 176 | } |
@@ -181,7 +181,7 @@ discard block |
||
| 181 | 181 | * @param array $task The task to process. |
| 182 | 182 | */ |
| 183 | 183 | private function processIndividualTask(array $task) { |
| 184 | - if (LOG_TASKS=== true) $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 184 | + if (LOG_TASKS === true) $this->logger->log('Starting task: '.print_r($task, true), 'INFO'); |
|
| 185 | 185 | |
| 186 | 186 | // Store progress in the database |
| 187 | 187 | DB::update( |
@@ -199,19 +199,19 @@ discard block |
||
| 199 | 199 | // Prepare process |
| 200 | 200 | $process = new Process([ |
| 201 | 201 | PHP_BINARY, |
| 202 | - __DIR__ . '/background_tasks___worker.php', |
|
| 202 | + __DIR__.'/background_tasks___worker.php', |
|
| 203 | 203 | $task['increment_id'], |
| 204 | 204 | $task['process_type'], |
| 205 | 205 | $task['arguments'] |
| 206 | 206 | ]); |
| 207 | 207 | |
| 208 | 208 | // Launch process |
| 209 | - try{ |
|
| 209 | + try { |
|
| 210 | 210 | $process->setTimeout($this->maxExecutionTime); |
| 211 | 211 | $process->mustRun(); |
| 212 | 212 | |
| 213 | 213 | } catch (Exception $e) { |
| 214 | - if (LOG_TASKS=== true) $this->logger->log('Error launching task: ' . $e->getMessage(), 'ERROR'); |
|
| 214 | + if (LOG_TASKS === true) $this->logger->log('Error launching task: '.$e->getMessage(), 'ERROR'); |
|
| 215 | 215 | DB::update( |
| 216 | 216 | prefixTable('background_tasks'), |
| 217 | 217 | [ |
@@ -233,7 +233,7 @@ discard block |
||
| 233 | 233 | private function countRunningTasks(): int { |
| 234 | 234 | return DB::queryFirstField( |
| 235 | 235 | 'SELECT COUNT(*) |
| 236 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 236 | + FROM ' . prefixTable('background_tasks').' |
|
| 237 | 237 | WHERE is_in_progress = 1' |
| 238 | 238 | ); |
| 239 | 239 | } |
@@ -254,10 +254,10 @@ discard block |
||
| 254 | 254 | */ |
| 255 | 255 | private function cleanMultipleItemsEdition() { |
| 256 | 256 | DB::query( |
| 257 | - 'DELETE i1 FROM ' . prefixTable('items_edition') . ' i1 |
|
| 257 | + 'DELETE i1 FROM '.prefixTable('items_edition').' i1 |
|
| 258 | 258 | JOIN ( |
| 259 | 259 | SELECT user_id, item_id, MIN(timestamp) AS oldest_timestamp |
| 260 | - FROM ' . prefixTable('items_edition') . ' |
|
| 260 | + FROM ' . prefixTable('items_edition').' |
|
| 261 | 261 | GROUP BY user_id, item_id |
| 262 | 262 | ) i2 ON i1.user_id = i2.user_id AND i1.item_id = i2.item_id |
| 263 | 263 | WHERE i1.timestamp > i2.oldest_timestamp' |
@@ -270,7 +270,7 @@ discard block |
||
| 270 | 270 | */ |
| 271 | 271 | private function handleItemTokensExpiration() { |
| 272 | 272 | DB::query( |
| 273 | - 'DELETE FROM ' . prefixTable('items_edition') . ' |
|
| 273 | + 'DELETE FROM '.prefixTable('items_edition').' |
|
| 274 | 274 | WHERE timestamp < %i', |
| 275 | 275 | time() - ($this->settings['delay_item_edition'] * 60 ?: EDITION_LOCK_PERIOD) |
| 276 | 276 | ); |
@@ -287,7 +287,7 @@ discard block |
||
| 287 | 287 | // 1. Get all finished tasks older than the cutoff timestamp |
| 288 | 288 | // and that are not in progress |
| 289 | 289 | $tasks = DB::query( |
| 290 | - 'SELECT increment_id FROM ' . prefixTable('background_tasks') . ' |
|
| 290 | + 'SELECT increment_id FROM '.prefixTable('background_tasks').' |
|
| 291 | 291 | WHERE status = %s AND is_in_progress = %i AND finished_at < %i', |
| 292 | 292 | 'completed', |
| 293 | 293 | -1, |
@@ -302,19 +302,19 @@ discard block |
||
| 302 | 302 | |
| 303 | 303 | // 2. Delete all subtasks related to these tasks |
| 304 | 304 | DB::query( |
| 305 | - 'DELETE FROM ' . prefixTable('background_subtasks') . ' |
|
| 305 | + 'DELETE FROM '.prefixTable('background_subtasks').' |
|
| 306 | 306 | WHERE task_id IN %ls', |
| 307 | 307 | $taskIds |
| 308 | 308 | ); |
| 309 | 309 | |
| 310 | 310 | // 3. Delete the tasks themselves |
| 311 | 311 | DB::query( |
| 312 | - 'DELETE FROM ' . prefixTable('background_tasks') . ' |
|
| 312 | + 'DELETE FROM '.prefixTable('background_tasks').' |
|
| 313 | 313 | WHERE increment_id IN %ls', |
| 314 | 314 | $taskIds |
| 315 | 315 | ); |
| 316 | 316 | |
| 317 | - if (LOG_TASKS=== true) $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 317 | + if (LOG_TASKS === true) $this->logger->log('Old finished tasks cleaned: '.count($taskIds), 'INFO'); |
|
| 318 | 318 | } |
| 319 | 319 | } |
| 320 | 320 | |
@@ -328,5 +328,5 @@ discard block |
||
| 328 | 328 | $tasksHandler = new BackgroundTasksHandler($settings); |
| 329 | 329 | $tasksHandler->processBackgroundTasks(); |
| 330 | 330 | } catch (Exception $e) { |
| 331 | - error_log('Teampass Background Tasks Error: ' . $e->getMessage()); |
|
| 331 | + error_log('Teampass Background Tasks Error: '.$e->getMessage()); |
|
| 332 | 332 | } |