@@ -113,7 +113,7 @@ |
||
| 113 | 113 | private function isParentFolderAllowed($parent_id, $user_accessible_folders, $user_is_admin, $user_can_create_root_folder) |
| 114 | 114 | { |
| 115 | 115 | if ($parent_id == 0 && $user_can_create_root_folder == true) |
| 116 | - return true; |
|
| 116 | + return true; |
|
| 117 | 117 | |
| 118 | 118 | if (in_array($parent_id, $user_accessible_folders) === false |
| 119 | 119 | && (int) $user_is_admin !== 1 |
@@ -112,8 +112,9 @@ discard block |
||
| 112 | 112 | */ |
| 113 | 113 | private function isParentFolderAllowed($parent_id, $user_accessible_folders, $user_is_admin, $user_can_create_root_folder) |
| 114 | 114 | { |
| 115 | - if ($parent_id == 0 && $user_can_create_root_folder == true) |
|
| 116 | - return true; |
|
| 115 | + if ($parent_id == 0 && $user_can_create_root_folder == true) { |
|
| 116 | + return true; |
|
| 117 | + } |
|
| 117 | 118 | |
| 118 | 119 | if (in_array($parent_id, $user_accessible_folders) === false |
| 119 | 120 | && (int) $user_is_admin !== 1 |
@@ -438,8 +439,9 @@ discard block |
||
| 438 | 439 | )['count']; |
| 439 | 440 | |
| 440 | 441 | // Don't insert duplicates |
| 441 | - if ($count > 0) |
|
| 442 | - continue; |
|
| 442 | + if ($count > 0) { |
|
| 443 | + continue; |
|
| 444 | + } |
|
| 443 | 445 | |
| 444 | 446 | // Insert new background task |
| 445 | 447 | DB::insert( |
@@ -91,7 +91,7 @@ discard block |
||
| 91 | 91 | |
| 92 | 92 | $parentComplexity = $this->checkComplexityLevel($parentFolderData, $complexity, $parent_id); |
| 93 | 93 | if (isset($parentComplexity['error']) && $parentComplexity['error'] === true) { |
| 94 | - return $this->errorResponse($this->lang->get('error_folder_complexity_lower_than_top_folder') . " [<b>{$this->settings['TP_PW_COMPLEXITY'][$parentComplexity['valeur']][1]}</b>]"); |
|
| 94 | + return $this->errorResponse($this->lang->get('error_folder_complexity_lower_than_top_folder')." [<b>{$this->settings['TP_PW_COMPLEXITY'][$parentComplexity['valeur']][1]}</b>]"); |
|
| 95 | 95 | } |
| 96 | 96 | |
| 97 | 97 | return $this->createFolder($params, array_merge($parentFolderData, $parentComplexity), $options); |
@@ -144,7 +144,7 @@ discard block |
||
| 144 | 144 | ) { |
| 145 | 145 | DB::query( |
| 146 | 146 | 'SELECT * |
| 147 | - FROM ' . prefixTable('nested_tree') . ' |
|
| 147 | + FROM ' . prefixTable('nested_tree').' |
|
| 148 | 148 | WHERE title = %s AND personal_folder = 0', |
| 149 | 149 | $title |
| 150 | 150 | ); |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | //check if parent folder is personal |
| 169 | 169 | $data = DB::queryFirstRow( |
| 170 | 170 | 'SELECT personal_folder, bloquer_creation, bloquer_modification |
| 171 | - FROM ' . prefixTable('nested_tree') . ' |
|
| 171 | + FROM ' . prefixTable('nested_tree').' |
|
| 172 | 172 | WHERE id = %i', |
| 173 | 173 | $parent_id |
| 174 | 174 | ); |
@@ -207,7 +207,7 @@ discard block |
||
| 207 | 207 | // get complexity level for this folder |
| 208 | 208 | $data = DB::queryFirstRow( |
| 209 | 209 | 'SELECT valeur |
| 210 | - FROM ' . prefixTable('misc') . ' |
|
| 210 | + FROM ' . prefixTable('misc').' |
|
| 211 | 211 | WHERE intitule = %i AND type = %s', |
| 212 | 212 | $parent_id, |
| 213 | 213 | 'complex' |
@@ -278,11 +278,11 @@ discard block |
||
| 278 | 278 | */ |
| 279 | 279 | private function canCreateFolder($isPersonal, $user_is_admin, $user_is_manager, $user_can_manage_all_users, $user_can_create_root_folder) |
| 280 | 280 | { |
| 281 | - return (int)$isPersonal === 1 || |
|
| 282 | - (int)$user_is_admin === 1 || |
|
| 283 | - ((int)$user_is_manager === 1 || (int)$user_can_manage_all_users === 1) || |
|
| 281 | + return (int) $isPersonal === 1 || |
|
| 282 | + (int) $user_is_admin === 1 || |
|
| 283 | + ((int) $user_is_manager === 1 || (int) $user_can_manage_all_users === 1) || |
|
| 284 | 284 | ($this->settings['enable_user_can_create_folders'] ?? false) || |
| 285 | - ((int)$user_can_create_root_folder === 1); |
|
| 285 | + ((int) $user_can_create_root_folder === 1); |
|
| 286 | 286 | } |
| 287 | 287 | |
| 288 | 288 | /** |
@@ -362,7 +362,7 @@ discard block |
||
| 362 | 362 | $path = ''; |
| 363 | 363 | $tree_path = $tree->getPath(0, false); |
| 364 | 364 | foreach ($tree_path as $fld) { |
| 365 | - $path .= empty($path) ? $fld->title : '/' . $fld->title; |
|
| 365 | + $path .= empty($path) ? $fld->title : '/'.$fld->title; |
|
| 366 | 366 | } |
| 367 | 367 | |
| 368 | 368 | $new_json = [ |
@@ -378,7 +378,7 @@ discard block |
||
| 378 | 378 | |
| 379 | 379 | $cache_tree = DB::queryFirstRow( |
| 380 | 380 | 'SELECT increment_id, folders, visible_folders |
| 381 | - FROM ' . prefixTable('cache_tree') . ' |
|
| 381 | + FROM ' . prefixTable('cache_tree').' |
|
| 382 | 382 | WHERE user_id = %i', |
| 383 | 383 | (int) $user_id |
| 384 | 384 | ); |
@@ -419,7 +419,7 @@ discard block |
||
| 419 | 419 | private function manageFolderPermissions($parent_id, $newId, $user_roles, $access_rights, $user_is_admin) |
| 420 | 420 | { |
| 421 | 421 | if ($parent_id !== 0 && $this->settings['subfolder_rights_as_parent'] ?? false) { |
| 422 | - $rows = DB::query('SELECT role_id, type FROM ' . prefixTable('roles_values') . ' WHERE folder_id = %i', $parent_id); |
|
| 422 | + $rows = DB::query('SELECT role_id, type FROM '.prefixTable('roles_values').' WHERE folder_id = %i', $parent_id); |
|
| 423 | 423 | foreach ($rows as $record) { |
| 424 | 424 | DB::insert(prefixTable('roles_values'), [ |
| 425 | 425 | 'role_id' => $record['role_id'], |
@@ -427,7 +427,7 @@ discard block |
||
| 427 | 427 | 'type' => $record['type'], |
| 428 | 428 | ]); |
| 429 | 429 | } |
| 430 | - } elseif ((int)$user_is_admin !== 1) { |
|
| 430 | + } elseif ((int) $user_is_admin !== 1) { |
|
| 431 | 431 | foreach (array_unique(explode(';', $user_roles)) as $role) { |
| 432 | 432 | if (!empty($role)) { |
| 433 | 433 | DB::insert(prefixTable('roles_values'), [ |
@@ -445,7 +445,7 @@ discard block |
||
| 445 | 445 | */ |
| 446 | 446 | private function copyCustomFieldsCategories($parent_id, $newId) |
| 447 | 447 | { |
| 448 | - $rows = DB::query('SELECT id_category FROM ' . prefixTable('categories_folders') . ' WHERE id_folder = %i', $parent_id); |
|
| 448 | + $rows = DB::query('SELECT id_category FROM '.prefixTable('categories_folders').' WHERE id_folder = %i', $parent_id); |
|
| 449 | 449 | foreach ($rows as $record) { |
| 450 | 450 | DB::insert(prefixTable('categories_folders'), [ |
| 451 | 451 | 'id_category' => $record['id_category'], |
@@ -470,7 +470,7 @@ discard block |
||
| 470 | 470 | // Search for existing job |
| 471 | 471 | $count = DB::queryFirstRow( |
| 472 | 472 | 'SELECT COUNT(*) AS count |
| 473 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 473 | + FROM ' . prefixTable('background_tasks').' |
|
| 474 | 474 | WHERE is_in_progress = %i AND process_type = %s AND arguments = %s', |
| 475 | 475 | 0, |
| 476 | 476 | 'user_build_cache_tree', |
@@ -504,7 +504,7 @@ discard block |
||
| 504 | 504 | return [ |
| 505 | 505 | 'error' => true, |
| 506 | 506 | 'message' => $message, |
| 507 | - 'newId' => '' . $newIdSuffix, |
|
| 507 | + 'newId' => ''.$newIdSuffix, |
|
| 508 | 508 | ]; |
| 509 | 509 | } |
| 510 | 510 | } |
@@ -1364,4 +1364,4 @@ |
||
| 1364 | 1364 | $string = str_replace("{%}", "?", $string); |
| 1365 | 1365 | // Trim and return. |
| 1366 | 1366 | return trim($string); |
| 1367 | - } |
|
| 1367 | + } |
|
@@ -79,7 +79,7 @@ discard block |
||
| 79 | 79 | ) { |
| 80 | 80 | // Not allowed page |
| 81 | 81 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 82 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 82 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 83 | 83 | exit; |
| 84 | 84 | } |
| 85 | 85 | |
@@ -167,7 +167,7 @@ discard block |
||
| 167 | 167 | ); |
| 168 | 168 | |
| 169 | 169 | // Initialisation |
| 170 | - $file = $SETTINGS['path_to_files_folder'] . '/' . $data['valeur']; |
|
| 170 | + $file = $SETTINGS['path_to_files_folder'].'/'.$data['valeur']; |
|
| 171 | 171 | $importation_possible = true; |
| 172 | 172 | $valuesToImport = []; |
| 173 | 173 | $items_number = 0; |
@@ -224,26 +224,26 @@ discard block |
||
| 224 | 224 | 'ISO-8859-1', |
| 225 | 225 | 'ISO-8859-15', |
| 226 | 226 | 'Windows-1252', |
| 227 | - 'Windows-1251', // Cyrillique |
|
| 228 | - 'CP1251', // Cyrillique alternatif |
|
| 229 | - 'KOI8-R', // Cyrillique russe |
|
| 230 | - 'Shift_JIS', // Japonais |
|
| 231 | - 'EUC-JP', // Japonais |
|
| 232 | - 'ISO-2022-JP', // Japonais |
|
| 233 | - 'TIS-620', // Thaï |
|
| 234 | - 'Windows-874', // Thaï Windows |
|
| 235 | - 'Big5', // Chinois traditionnel |
|
| 236 | - 'GB2312', // Chinois simplifié |
|
| 237 | - 'GBK', // Chinois simplifié étendu |
|
| 238 | - 'EUC-KR', // Coréen |
|
| 239 | - 'ISO-8859-2', // Europe centrale |
|
| 240 | - 'ISO-8859-5', // Cyrillique ISO |
|
| 241 | - 'ISO-8859-7', // Grec |
|
| 242 | - 'Windows-1250', // Europe centrale |
|
| 243 | - 'Windows-1253', // Grec |
|
| 244 | - 'Windows-1254', // Turc |
|
| 245 | - 'Windows-1255', // Hébreu |
|
| 246 | - 'Windows-1256', // Arabe |
|
| 227 | + 'Windows-1251', // Cyrillique |
|
| 228 | + 'CP1251', // Cyrillique alternatif |
|
| 229 | + 'KOI8-R', // Cyrillique russe |
|
| 230 | + 'Shift_JIS', // Japonais |
|
| 231 | + 'EUC-JP', // Japonais |
|
| 232 | + 'ISO-2022-JP', // Japonais |
|
| 233 | + 'TIS-620', // Thaï |
|
| 234 | + 'Windows-874', // Thaï Windows |
|
| 235 | + 'Big5', // Chinois traditionnel |
|
| 236 | + 'GB2312', // Chinois simplifié |
|
| 237 | + 'GBK', // Chinois simplifié étendu |
|
| 238 | + 'EUC-KR', // Coréen |
|
| 239 | + 'ISO-8859-2', // Europe centrale |
|
| 240 | + 'ISO-8859-5', // Cyrillique ISO |
|
| 241 | + 'ISO-8859-7', // Grec |
|
| 242 | + 'Windows-1250', // Europe centrale |
|
| 243 | + 'Windows-1253', // Grec |
|
| 244 | + 'Windows-1254', // Turc |
|
| 245 | + 'Windows-1255', // Hébreu |
|
| 246 | + 'Windows-1256', // Arabe |
|
| 247 | 247 | ]; |
| 248 | 248 | |
| 249 | 249 | // Get the list of encodings supported by the system |
@@ -286,7 +286,7 @@ discard block |
||
| 286 | 286 | |
| 287 | 287 | // Get the data and ensure columns are correctly mapped |
| 288 | 288 | $interpreter = new Interpreter(); |
| 289 | - $interpreter->addObserver(function (array $row) use (&$valuesToImport, $header) { |
|
| 289 | + $interpreter->addObserver(function(array $row) use (&$valuesToImport, $header) { |
|
| 290 | 290 | $rowData = array_combine($header, $row); |
| 291 | 291 | |
| 292 | 292 | if ($rowData !== false) { |
@@ -339,7 +339,7 @@ discard block |
||
| 339 | 339 | // Handle multiple lignes description |
| 340 | 340 | if (strpos($comments, '<br>') !== false || strpos($label, '<br>') !== false) { |
| 341 | 341 | $continue_on_next_line = true; |
| 342 | - $comment .= " " . $label . " " . $comments; |
|
| 342 | + $comment .= " ".$label." ".$comments; |
|
| 343 | 343 | } else { |
| 344 | 344 | // Insert previous line if changing line |
| 345 | 345 | if (!empty($label)) { |
@@ -348,7 +348,7 @@ discard block |
||
| 348 | 348 | // Insert in batch |
| 349 | 349 | $batchInsert[] = array( |
| 350 | 350 | 'label' => $label, |
| 351 | - 'description' => $comment . $comments, |
|
| 351 | + 'description' => $comment.$comments, |
|
| 352 | 352 | 'pwd' => $pwd, |
| 353 | 353 | 'url' => $url, |
| 354 | 354 | 'folder' => ((int) $session->get('user-admin') === 1 || (int) $session->get('user-manager') === 1 || (int) $session->get('user-can_manage_all_users') === 1) ? $folder : '', |
@@ -379,7 +379,7 @@ discard block |
||
| 379 | 379 | // Insert in batch |
| 380 | 380 | $batchInsert[] = array( |
| 381 | 381 | 'label' => $label, |
| 382 | - 'description' => $comment . $comments, |
|
| 382 | + 'description' => $comment.$comments, |
|
| 383 | 383 | 'pwd' => $pwd, |
| 384 | 384 | 'url' => $url, |
| 385 | 385 | 'folder' => ((int) $session->get('user-admin') === 1 || (int) $session->get('user-manager') === 1 || (int) $session->get('user-can_manage_all_users') === 1) ? $folder : '', |
@@ -403,10 +403,10 @@ discard block |
||
| 403 | 403 | $values = []; |
| 404 | 404 | |
| 405 | 405 | foreach ($batchInsert as $data) { |
| 406 | - $values[] = "('" . implode("','", array_map('addslashes', $data)) . "')"; |
|
| 406 | + $values[] = "('".implode("','", array_map('addslashes', $data))."')"; |
|
| 407 | 407 | } |
| 408 | 408 | |
| 409 | - $sql = "INSERT INTO `$tableName` (`label`, `description`, `pwd`, `url`, `folder`, `login`, `operation_id`) VALUES " . implode(',', $values); |
|
| 409 | + $sql = "INSERT INTO `$tableName` (`label`, `description`, `pwd`, `url`, `folder`, `login`, `operation_id`) VALUES ".implode(',', $values); |
|
| 410 | 410 | |
| 411 | 411 | DB::query($sql); |
| 412 | 412 | } |
@@ -489,7 +489,7 @@ discard block |
||
| 489 | 489 | $parentId = $dataReceived['folderId']; // Strating with provided folder |
| 490 | 490 | |
| 491 | 491 | foreach ($parts as $part) { |
| 492 | - $currentPath = trim($currentPath . "/" . $part, "/"); |
|
| 492 | + $currentPath = trim($currentPath."/".$part, "/"); |
|
| 493 | 493 | $currentFolder = $part; |
| 494 | 494 | |
| 495 | 495 | // Check if this folder has already been created |
@@ -550,7 +550,7 @@ discard block |
||
| 550 | 550 | // Get ID of existing folder |
| 551 | 551 | $ret = DB::queryFirstRow( |
| 552 | 552 | 'SELECT * |
| 553 | - FROM ' . prefixTable('nested_tree') . ' |
|
| 553 | + FROM ' . prefixTable('nested_tree').' |
|
| 554 | 554 | WHERE title = %s', |
| 555 | 555 | $currentFolder |
| 556 | 556 | ); |
@@ -760,9 +760,9 @@ discard block |
||
| 760 | 760 | ]; |
| 761 | 761 | |
| 762 | 762 | error_log( |
| 763 | - 'SQL Error during import | increment_id: ' . $item['increment_id'] . |
|
| 764 | - ' | Message: ' . $e->getMessage() . |
|
| 765 | - ' | StackTrace: ' . $e->getTraceAsString() |
|
| 763 | + 'SQL Error during import | increment_id: '.$item['increment_id']. |
|
| 764 | + ' | Message: '.$e->getMessage(). |
|
| 765 | + ' | StackTrace: '.$e->getTraceAsString() |
|
| 766 | 766 | ); |
| 767 | 767 | } |
| 768 | 768 | } |
@@ -1071,7 +1071,7 @@ discard block |
||
| 1071 | 1071 | ]; |
| 1072 | 1072 | $startPathLevel = 1; |
| 1073 | 1073 | |
| 1074 | - foreach($post_folders as $folder) { |
|
| 1074 | + foreach ($post_folders as $folder) { |
|
| 1075 | 1075 | // get parent id |
| 1076 | 1076 | if (!isset($arrFolders[$folder['parentFolderId']])) { |
| 1077 | 1077 | // If parent folder is not in the array, it means it is the destination folder |
@@ -1147,7 +1147,7 @@ discard block |
||
| 1147 | 1147 | DB::startTransaction(); |
| 1148 | 1148 | |
| 1149 | 1149 | // Import all items |
| 1150 | - foreach($post_items as $item) { |
|
| 1150 | + foreach ($post_items as $item) { |
|
| 1151 | 1151 | // get info about this folder |
| 1152 | 1152 | $destinationFolderMore = DB::queryFirstRow( |
| 1153 | 1153 | 'SELECT title FROM '.prefixTable('nested_tree').' WHERE id = %i', |
@@ -1178,7 +1178,7 @@ discard block |
||
| 1178 | 1178 | 'pw' => $cryptedStuff['encrypted'], |
| 1179 | 1179 | 'pw_iv' => '', |
| 1180 | 1180 | 'url' => substr($item['URL'], 0, 500), |
| 1181 | - 'id_tree' => isset($post_folders[$item['parentFolderId']]['id']) ? (int)$post_folders[$item['parentFolderId']]['id'] : 0, |
|
| 1181 | + 'id_tree' => isset($post_folders[$item['parentFolderId']]['id']) ? (int) $post_folders[$item['parentFolderId']]['id'] : 0, |
|
| 1182 | 1182 | 'login' => substr($item['UserName'], 0, 500), |
| 1183 | 1183 | 'anyone_can_modify' => $$inputData['editAll'], |
| 1184 | 1184 | 'encryption_type' => 'teampass_aes', |
@@ -1313,7 +1313,7 @@ discard block |
||
| 1313 | 1313 | |
| 1314 | 1314 | //For each role to which the user depends on, add the folder just created. |
| 1315 | 1315 | // (if not personal, otherwise, add to user-personal_folders) |
| 1316 | - if ( $isPersonalFolder ) { |
|
| 1316 | + if ($isPersonalFolder) { |
|
| 1317 | 1317 | SessionManager::addRemoveFromSessionArray('user-personal_folders', [$id], 'add'); |
| 1318 | 1318 | } else { |
| 1319 | 1319 | foreach ($session->get('system-array_roles') as $role) { |
@@ -1384,7 +1384,7 @@ discard block |
||
| 1384 | 1384 | ]; |
| 1385 | 1385 | } |
| 1386 | 1386 | |
| 1387 | -spl_autoload_register(function ($class) { |
|
| 1387 | +spl_autoload_register(function($class) { |
|
| 1388 | 1388 | $prefix = 'League\\Csv\\'; |
| 1389 | 1389 | $base_dir = __DIR__.'/src/'; |
| 1390 | 1390 | $len = strlen($prefix); |
@@ -29,7 +29,7 @@ discard block |
||
| 29 | 29 | trait ItemHandlerTrait { |
| 30 | 30 | |
| 31 | 31 | private function generateUserPasswordKeys($arguments) { |
| 32 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserPasswordKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 32 | + if (LOG_TASKS === true) $this->logger->log('Processing generateUserPasswordKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 33 | 33 | // Generate keys for user passwords |
| 34 | 34 | storeUsersShareKey( |
| 35 | 35 | prefixTable('sharekeys_items'), |
@@ -49,8 +49,8 @@ discard block |
||
| 49 | 49 | * @param array $taskData |
| 50 | 50 | */ |
| 51 | 51 | private function generateUserFileKeys($taskData) { |
| 52 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFileKeys : '.print_r($taskData, true), 'DEBUG'); |
|
| 53 | - foreach($taskData['files_keys'] as $file) { |
|
| 52 | + if (LOG_TASKS === true) $this->logger->log('Processing generateUserFileKeys : '.print_r($taskData, true), 'DEBUG'); |
|
| 53 | + foreach ($taskData['files_keys'] as $file) { |
|
| 54 | 54 | storeUsersShareKey( |
| 55 | 55 | prefixTable('sharekeys_files'), |
| 56 | 56 | 0, |
@@ -70,9 +70,9 @@ discard block |
||
| 70 | 70 | * @param array $arguments |
| 71 | 71 | */ |
| 72 | 72 | private function generateUserFieldKeys($arguments) { |
| 73 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFieldKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 74 | - foreach($arguments['fields_keys'] as $field) { |
|
| 75 | - $this->logger->log('Processing generateUserFieldKeys for: ' . $field['object_id'], 'DEBUG'); |
|
| 73 | + if (LOG_TASKS === true) $this->logger->log('Processing generateUserFieldKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 74 | + foreach ($arguments['fields_keys'] as $field) { |
|
| 75 | + $this->logger->log('Processing generateUserFieldKeys for: '.$field['object_id'], 'DEBUG'); |
|
| 76 | 76 | storeUsersShareKey( |
| 77 | 77 | prefixTable('sharekeys_fields'), |
| 78 | 78 | 0, |
@@ -29,7 +29,9 @@ discard block |
||
| 29 | 29 | trait ItemHandlerTrait { |
| 30 | 30 | |
| 31 | 31 | private function generateUserPasswordKeys($arguments) { |
| 32 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserPasswordKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 32 | + if (LOG_TASKS=== true) { |
|
| 33 | + $this->logger->log('Processing generateUserPasswordKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 34 | + } |
|
| 33 | 35 | // Generate keys for user passwords |
| 34 | 36 | storeUsersShareKey( |
| 35 | 37 | prefixTable('sharekeys_items'), |
@@ -49,7 +51,9 @@ discard block |
||
| 49 | 51 | * @param array $taskData |
| 50 | 52 | */ |
| 51 | 53 | private function generateUserFileKeys($taskData) { |
| 52 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFileKeys : '.print_r($taskData, true), 'DEBUG'); |
|
| 54 | + if (LOG_TASKS=== true) { |
|
| 55 | + $this->logger->log('Processing generateUserFileKeys : '.print_r($taskData, true), 'DEBUG'); |
|
| 56 | + } |
|
| 53 | 57 | foreach($taskData['files_keys'] as $file) { |
| 54 | 58 | storeUsersShareKey( |
| 55 | 59 | prefixTable('sharekeys_files'), |
@@ -70,7 +74,9 @@ discard block |
||
| 70 | 74 | * @param array $arguments |
| 71 | 75 | */ |
| 72 | 76 | private function generateUserFieldKeys($arguments) { |
| 73 | - if (LOG_TASKS=== true) $this->logger->log('Processing generateUserFieldKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 77 | + if (LOG_TASKS=== true) { |
|
| 78 | + $this->logger->log('Processing generateUserFieldKeys : '.print_r($arguments, true), 'DEBUG'); |
|
| 79 | + } |
|
| 74 | 80 | foreach($arguments['fields_keys'] as $field) { |
| 75 | 81 | $this->logger->log('Processing generateUserFieldKeys for: ' . $field['object_id'], 'DEBUG'); |
| 76 | 82 | storeUsersShareKey( |
@@ -80,7 +80,7 @@ discard block |
||
| 80 | 80 | //get through all users with enabled personnal folder. |
| 81 | 81 | $users = DB::query( |
| 82 | 82 | 'SELECT id, login, email |
| 83 | - FROM ' . prefixTable('users') . ' |
|
| 83 | + FROM ' . prefixTable('users').' |
|
| 84 | 84 | WHERE id NOT IN ('.OTV_USER_ID.', '.TP_USER_ID.', '.SSH_USER_ID.', '.API_USER_ID.') |
| 85 | 85 | AND personal_folder = 1 |
| 86 | 86 | ORDER BY login ASC' |
@@ -89,7 +89,7 @@ discard block |
||
| 89 | 89 | //if folder doesn't exist then create it |
| 90 | 90 | $data = DB::queryFirstRow( |
| 91 | 91 | 'SELECT id |
| 92 | - FROM ' . prefixTable('nested_tree') . ' |
|
| 92 | + FROM ' . prefixTable('nested_tree').' |
|
| 93 | 93 | WHERE title = %s AND parent_id = %i', |
| 94 | 94 | $user['id'], |
| 95 | 95 | 0 |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | // get count of Items in this folder |
| 73 | 73 | $get = DB::queryFirstRow( |
| 74 | 74 | 'SELECT count(*) as num_results |
| 75 | - FROM ' . prefixTable('items') . ' |
|
| 75 | + FROM ' . prefixTable('items').' |
|
| 76 | 76 | WHERE inactif = %i AND id_tree = %i', |
| 77 | 77 | 0, |
| 78 | 78 | $child->id |
@@ -81,14 +81,14 @@ discard block |
||
| 81 | 81 | $ret[$child->id]['id'] = $child->id; |
| 82 | 82 | |
| 83 | 83 | // get number of subfolders |
| 84 | - $nodeDescendants =$tree->getDescendants($child->id, false, false, true); |
|
| 84 | + $nodeDescendants = $tree->getDescendants($child->id, false, false, true); |
|
| 85 | 85 | $ret[$child->id]['subfoldersCount'] = count($nodeDescendants); |
| 86 | 86 | |
| 87 | 87 | // get items number in subfolders |
| 88 | 88 | if (count($nodeDescendants) > 0) { |
| 89 | 89 | $get = DB::queryFirstRow( |
| 90 | 90 | 'SELECT count(*) as num_results |
| 91 | - FROM ' . prefixTable('items') . ' |
|
| 91 | + FROM ' . prefixTable('items').' |
|
| 92 | 92 | WHERE inactif = %i AND id_tree IN (%l)', |
| 93 | 93 | 0, |
| 94 | 94 | implode(',', $nodeDescendants) |
@@ -139,7 +139,7 @@ discard block |
||
| 139 | 139 | // Get item key |
| 140 | 140 | $itemKey = DB::queryFirstRow( |
| 141 | 141 | 'SELECT share_key |
| 142 | - FROM ' . prefixTable('sharekeys_items') . ' |
|
| 142 | + FROM ' . prefixTable('sharekeys_items').' |
|
| 143 | 143 | WHERE user_id = %i AND object_id = %i', |
| 144 | 144 | TP_USER_ID, |
| 145 | 145 | $item['itemId'] |
@@ -76,7 +76,7 @@ discard block |
||
| 76 | 76 | ) { |
| 77 | 77 | // Not allowed page |
| 78 | 78 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 79 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 79 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 80 | 80 | exit; |
| 81 | 81 | } |
| 82 | 82 | |
@@ -168,7 +168,7 @@ discard block |
||
| 168 | 168 | |
| 169 | 169 | // Output |
| 170 | 170 | $sOutput = '{'; |
| 171 | - $sOutput .= '"sEcho": '. $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 171 | + $sOutput .= '"sEcho": '.$request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 172 | 172 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 173 | 173 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 174 | 174 | $sOutput .= '"aaData": '; |
@@ -241,7 +241,7 @@ discard block |
||
| 241 | 241 | |
| 242 | 242 | // Output |
| 243 | 243 | $sOutput = '{'; |
| 244 | - $sOutput .= '"sEcho": '. $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 244 | + $sOutput .= '"sEcho": '.$request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 245 | 245 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 246 | 246 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 247 | 247 | $sOutput .= '"aaData": '; |
@@ -314,7 +314,7 @@ discard block |
||
| 314 | 314 | |
| 315 | 315 | // Output |
| 316 | 316 | $sOutput = '{'; |
| 317 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 317 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 318 | 318 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 319 | 319 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 320 | 320 | $sOutput .= '"aaData": '; |
@@ -387,7 +387,7 @@ discard block |
||
| 387 | 387 | |
| 388 | 388 | // Output |
| 389 | 389 | $sOutput = '{'; |
| 390 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 390 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 391 | 391 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 392 | 392 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 393 | 393 | $sOutput .= '"aaData": [ '; |
@@ -490,7 +490,7 @@ discard block |
||
| 490 | 490 | |
| 491 | 491 | // Output |
| 492 | 492 | $sOutput = '{'; |
| 493 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 493 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 494 | 494 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 495 | 495 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 496 | 496 | $sOutput .= '"aaData": [ '; |
@@ -572,7 +572,7 @@ discard block |
||
| 572 | 572 | $iTotal = 0; |
| 573 | 573 | } |
| 574 | 574 | $sOutput = '{'; |
| 575 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 575 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 576 | 576 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 577 | 577 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 578 | 578 | $sOutput .= '"aaData": '; |
@@ -648,7 +648,7 @@ discard block |
||
| 648 | 648 | |
| 649 | 649 | // Output |
| 650 | 650 | $sOutput = '{'; |
| 651 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 651 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 652 | 652 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 653 | 653 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 654 | 654 | $sOutput .= '"aaData": '; |
@@ -717,7 +717,7 @@ discard block |
||
| 717 | 717 | |
| 718 | 718 | // Output |
| 719 | 719 | $sOutput = '{'; |
| 720 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 720 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 721 | 721 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 722 | 722 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 723 | 723 | $sOutput .= '"aaData": '; |
@@ -790,7 +790,7 @@ discard block |
||
| 790 | 790 | |
| 791 | 791 | // Output |
| 792 | 792 | $sOutput = '{'; |
| 793 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 793 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 794 | 794 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 795 | 795 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 796 | 796 | $sOutput .= '"aaData": '; |
@@ -867,7 +867,7 @@ discard block |
||
| 867 | 867 | FROM '.prefixTable('background_tasks').' AS p |
| 868 | 868 | LEFT JOIN '.prefixTable('users').' AS u ON %l |
| 869 | 869 | WHERE %l ORDER BY %l %l LIMIT %i, %i'; |
| 870 | - $params = ['u.id = json_extract(p.arguments, "$[0]")',$sWhere, $orderColumn, $orderDirection, $sLimitStart, $sLimitLength]; |
|
| 870 | + $params = ['u.id = json_extract(p.arguments, "$[0]")', $sWhere, $orderColumn, $orderDirection, $sLimitStart, $sLimitLength]; |
|
| 871 | 871 | |
| 872 | 872 | // Get the records |
| 873 | 873 | $rows = DB::query($sql, ...$params); |
@@ -875,7 +875,7 @@ discard block |
||
| 875 | 875 | |
| 876 | 876 | // Output |
| 877 | 877 | $sOutput = '{'; |
| 878 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 878 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 879 | 879 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 880 | 880 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 881 | 881 | $sOutput .= '"aaData": '; |
@@ -890,7 +890,7 @@ discard block |
||
| 890 | 890 | //col1 |
| 891 | 891 | $sOutput .= '"<span data-done=\"'.$record['is_in_progress'].'\" data-type=\"'.$record['process_type'].'\" data-process-id=\"'.$record['increment_id'].'\"></span>", '; |
| 892 | 892 | //col2 |
| 893 | - $sOutput .= '"'.date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['created_at']).'", '; |
|
| 893 | + $sOutput .= '"'.date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], (int) $record['created_at']).'", '; |
|
| 894 | 894 | //col3 |
| 895 | 895 | //$sOutput .= '"'.($record['updated_at'] === '' ? '-' : date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['updated_at'])).'", '; |
| 896 | 896 | $sOutput .= '"<div class=\"progress mt-2\"><div class=\"progress-bar\" style=\"width: '.$subtaskProgress.'\">'.$subtaskProgress.'</div></div>", '; |
@@ -900,7 +900,7 @@ discard block |
||
| 900 | 900 | // col5 |
| 901 | 901 | if (in_array($record['process_type'], array('create_user_keys', 'item_copy')) === true) { |
| 902 | 902 | $data_user = DB::queryFirstRow( |
| 903 | - 'SELECT name, lastname FROM ' . prefixTable('users') . ' |
|
| 903 | + 'SELECT name, lastname FROM '.prefixTable('users').' |
|
| 904 | 904 | WHERE id = %i', |
| 905 | 905 | json_decode($record['arguments'], true)['new_user_id'] |
| 906 | 906 | ); |
@@ -956,7 +956,7 @@ discard block |
||
| 956 | 956 | FROM '.prefixTable('background_tasks').' AS p |
| 957 | 957 | LEFT JOIN '.prefixTable('users').' AS u ON %l |
| 958 | 958 | WHERE %l ORDER BY %l %l LIMIT %i, %i'; |
| 959 | - $params = ['u.id = json_extract(p.arguments, "$[0]")',$sWhere, $orderColumn, $orderDirection, $sLimitStart, $sLimitLength]; |
|
| 959 | + $params = ['u.id = json_extract(p.arguments, "$[0]")', $sWhere, $orderColumn, $orderDirection, $sLimitStart, $sLimitLength]; |
|
| 960 | 960 | |
| 961 | 961 | // Get the records |
| 962 | 962 | $rows = DB::query($sql, ...$params); |
@@ -964,7 +964,7 @@ discard block |
||
| 964 | 964 | |
| 965 | 965 | // Output |
| 966 | 966 | $sOutput = '{'; |
| 967 | - $sOutput .= '"sEcho": '. (int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT) . ', '; |
|
| 967 | + $sOutput .= '"sEcho": '.(int) $request->query->filter('draw', FILTER_SANITIZE_NUMBER_INT).', '; |
|
| 968 | 968 | $sOutput .= '"iTotalRecords": '.$iTotal.', '; |
| 969 | 969 | $sOutput .= '"iTotalDisplayRecords": '.$iTotal.', '; |
| 970 | 970 | $sOutput .= '"aaData": '; |
@@ -980,13 +980,12 @@ discard block |
||
| 980 | 980 | //col1 |
| 981 | 981 | $sOutput .= '"'.(is_null($record['error_message']) ? '' : addslashes($record['error_message'])).'", '; |
| 982 | 982 | //col2 |
| 983 | - $sOutput .= '"'.date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['created_at']).'", '; |
|
| 983 | + $sOutput .= '"'.date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], (int) $record['created_at']).'", '; |
|
| 984 | 984 | //col3 |
| 985 | 985 | $sOutput .= is_null($record['started_at']) === false ? |
| 986 | - ('"'.date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['started_at']).'", ') : |
|
| 987 | - ('"'.date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['created_at']).'", '); |
|
| 986 | + ('"'.date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], (int) $record['started_at']).'", ') : ('"'.date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], (int) $record['created_at']).'", '); |
|
| 988 | 987 | //col4 |
| 989 | - $sOutput .= '"'.date($SETTINGS['date_format'] . ' ' . $SETTINGS['time_format'], (int) $record['finished_at']).'", '; |
|
| 988 | + $sOutput .= '"'.date($SETTINGS['date_format'].' '.$SETTINGS['time_format'], (int) $record['finished_at']).'", '; |
|
| 990 | 989 | // col7 |
| 991 | 990 | $sOutput .= '"'.gmdate('H:i:s', (int) $record['finished_at'] - (is_null($record['started_at']) === false ? (int) $record['started_at'] : (int) $record['created_at'])).'",'; |
| 992 | 991 | //col5 |
@@ -1009,11 +1008,10 @@ discard block |
||
| 1009 | 1008 | // col6 |
| 1010 | 1009 | $arguments = json_decode($record['arguments'], true); |
| 1011 | 1010 | $newUserId = array_key_exists('new_user_id', $arguments) ? |
| 1012 | - $arguments['new_user_id'] : |
|
| 1013 | - (array_key_exists('user_id', $arguments) ? $arguments['user_id'] : null); |
|
| 1011 | + $arguments['new_user_id'] : (array_key_exists('user_id', $arguments) ? $arguments['user_id'] : null); |
|
| 1014 | 1012 | if ($record['process_type'] === 'create_user_keys' && is_null($newUserId) === false && empty($newUserId) === false) { |
| 1015 | 1013 | $data_user = DB::queryFirstRow( |
| 1016 | - 'SELECT name, lastname, login FROM ' . prefixTable('users') . ' |
|
| 1014 | + 'SELECT name, lastname, login FROM '.prefixTable('users').' |
|
| 1017 | 1015 | WHERE id = %i', |
| 1018 | 1016 | $newUserId |
| 1019 | 1017 | ); |
@@ -1029,7 +1027,7 @@ discard block |
||
| 1029 | 1027 | } elseif ($record['process_type'] === 'user_build_cache_tree') { |
| 1030 | 1028 | $user = json_decode($record['arguments'], true)['user_id']; |
| 1031 | 1029 | $data_user = DB::queryFirstRow( |
| 1032 | - 'SELECT name, lastname, login FROM ' . prefixTable('users') . ' |
|
| 1030 | + 'SELECT name, lastname, login FROM '.prefixTable('users').' |
|
| 1033 | 1031 | WHERE id = %i', |
| 1034 | 1032 | $user |
| 1035 | 1033 | ); |
@@ -1063,7 +1061,7 @@ discard block |
||
| 1063 | 1061 | { |
| 1064 | 1062 | $subtasks = DB::query( |
| 1065 | 1063 | 'SELECT * |
| 1066 | - FROM ' . prefixTable('background_subtasks') . ' |
|
| 1064 | + FROM ' . prefixTable('background_subtasks').' |
|
| 1067 | 1065 | WHERE task_id = %i', |
| 1068 | 1066 | $id |
| 1069 | 1067 | ); |
@@ -1079,5 +1077,5 @@ discard block |
||
| 1079 | 1077 | $i++; |
| 1080 | 1078 | } |
| 1081 | 1079 | |
| 1082 | - return ($finished_nb !== 0 ? pourcentage($finished_nb, $nb, 100) : 0) .'%'; |
|
| 1080 | + return ($finished_nb !== 0 ? pourcentage($finished_nb, $nb, 100) : 0).'%'; |
|
| 1083 | 1081 | } |
| 1084 | 1082 | \ No newline at end of file |
@@ -47,8 +47,8 @@ |
||
| 47 | 47 | */ |
| 48 | 48 | public function log(string $message, string $level = 'INFO') { |
| 49 | 49 | if (!empty($this->settings['enable_tasks_log'])) { |
| 50 | - $formattedMessage = date($this->settings['date_format'] . ' ' . $this->settings['time_format']) . |
|
| 51 | - " - [$level] $message" . PHP_EOL; |
|
| 50 | + $formattedMessage = date($this->settings['date_format'].' '.$this->settings['time_format']). |
|
| 51 | + " - [$level] $message".PHP_EOL; |
|
| 52 | 52 | |
| 53 | 53 | if (!empty($this->logFile)) { |
| 54 | 54 | // WWrite to the specified log file |
@@ -55,7 +55,9 @@ discard block |
||
| 55 | 55 | public function processBackgroundTasks() { |
| 56 | 56 | // Prevent multiple concurrent executions |
| 57 | 57 | if (!$this->acquireProcessLock()) { |
| 58 | - if (LOG_TASKS=== true) $this->logger->log('Process already running', 'INFO'); |
|
| 58 | + if (LOG_TASKS=== true) { |
|
| 59 | + $this->logger->log('Process already running', 'INFO'); |
|
| 60 | + } |
|
| 59 | 61 | return false; |
| 60 | 62 | } |
| 61 | 63 | |
@@ -64,7 +66,9 @@ discard block |
||
| 64 | 66 | $this->processTaskBatches(); |
| 65 | 67 | $this->performMaintenanceTasks(); |
| 66 | 68 | } catch (Exception $e) { |
| 67 | - if (LOG_TASKS=== true) $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 69 | + if (LOG_TASKS=== true) { |
|
| 70 | + $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 71 | + } |
|
| 68 | 72 | } finally { |
| 69 | 73 | $this->releaseProcessLock(); |
| 70 | 74 | } |
@@ -131,7 +135,9 @@ discard block |
||
| 131 | 135 | |
| 132 | 136 | // Check if the maximum number of parallel tasks is reached |
| 133 | 137 | if ($runningTasks >= $this->maxParallelTasks) { |
| 134 | - if (LOG_TASKS=== true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 138 | + if (LOG_TASKS=== true) { |
|
| 139 | + $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 140 | + } |
|
| 135 | 141 | return; |
| 136 | 142 | } |
| 137 | 143 | |
@@ -149,7 +155,9 @@ discard block |
||
| 149 | 155 | ); |
| 150 | 156 | |
| 151 | 157 | foreach ($tasks as $task) { |
| 152 | - if (LOG_TASKS=== true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 158 | + if (LOG_TASKS=== true) { |
|
| 159 | + $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 160 | + } |
|
| 153 | 161 | $this->processIndividualTask($task); |
| 154 | 162 | } |
| 155 | 163 | } |
@@ -160,7 +168,9 @@ discard block |
||
| 160 | 168 | * @param array $task The task to process. |
| 161 | 169 | */ |
| 162 | 170 | private function processIndividualTask(array $task) { |
| 163 | - if (LOG_TASKS=== true) $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 171 | + if (LOG_TASKS=== true) { |
|
| 172 | + $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 173 | + } |
|
| 164 | 174 | |
| 165 | 175 | // Store progress in the database |
| 166 | 176 | DB::update( |
@@ -188,7 +198,9 @@ discard block |
||
| 188 | 198 | $process->mustRun(); |
| 189 | 199 | |
| 190 | 200 | } catch (Exception $e) { |
| 191 | - if (LOG_TASKS=== true) $this->logger->log('Error launching task: ' . $e->getMessage(), 'ERROR'); |
|
| 201 | + if (LOG_TASKS=== true) { |
|
| 202 | + $this->logger->log('Error launching task: ' . $e->getMessage(), 'ERROR'); |
|
| 203 | + } |
|
| 192 | 204 | DB::update( |
| 193 | 205 | prefixTable('background_tasks'), |
| 194 | 206 | [ |
@@ -290,7 +302,9 @@ discard block |
||
| 290 | 302 | $taskIds |
| 291 | 303 | ); |
| 292 | 304 | |
| 293 | - if (LOG_TASKS=== true) $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 305 | + if (LOG_TASKS=== true) { |
|
| 306 | + $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 307 | + } |
|
| 294 | 308 | } |
| 295 | 309 | } |
| 296 | 310 | |
@@ -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; |
@@ -55,7 +55,7 @@ discard block |
||
| 55 | 55 | public function processBackgroundTasks() { |
| 56 | 56 | // Prevent multiple concurrent executions |
| 57 | 57 | if (!$this->acquireProcessLock()) { |
| 58 | - if (LOG_TASKS=== true) $this->logger->log('Process already running', 'INFO'); |
|
| 58 | + if (LOG_TASKS === true) $this->logger->log('Process already running', 'INFO'); |
|
| 59 | 59 | return false; |
| 60 | 60 | } |
| 61 | 61 | |
@@ -64,7 +64,7 @@ discard block |
||
| 64 | 64 | $this->processTaskBatches(); |
| 65 | 65 | $this->performMaintenanceTasks(); |
| 66 | 66 | } catch (Exception $e) { |
| 67 | - if (LOG_TASKS=== true) $this->logger->log('Task processing error: ' . $e->getMessage(), 'ERROR'); |
|
| 67 | + if (LOG_TASKS === true) $this->logger->log('Task processing error: '.$e->getMessage(), 'ERROR'); |
|
| 68 | 68 | } finally { |
| 69 | 69 | $this->releaseProcessLock(); |
| 70 | 70 | } |
@@ -83,7 +83,7 @@ discard block |
||
| 83 | 83 | return false; |
| 84 | 84 | } |
| 85 | 85 | |
| 86 | - fwrite($fp, (string)getmypid()); |
|
| 86 | + fwrite($fp, (string) getmypid()); |
|
| 87 | 87 | return true; |
| 88 | 88 | } |
| 89 | 89 | |
@@ -101,7 +101,7 @@ discard block |
||
| 101 | 101 | private function cleanupStaleTasks() { |
| 102 | 102 | // Mark tasks as failed if they've been running too long |
| 103 | 103 | DB::query( |
| 104 | - 'UPDATE ' . prefixTable('background_tasks') . ' |
|
| 104 | + 'UPDATE '.prefixTable('background_tasks').' |
|
| 105 | 105 | SET is_in_progress = -1, |
| 106 | 106 | finished_at = %i, |
| 107 | 107 | status = "failed", |
@@ -114,8 +114,8 @@ discard block |
||
| 114 | 114 | |
| 115 | 115 | // Remove very old failed tasks |
| 116 | 116 | DB::query( |
| 117 | - 'DELETE t, st FROM ' . prefixTable('background_tasks') . ' t |
|
| 118 | - INNER JOIN ' . prefixTable('background_subtasks') . ' st ON (t.increment_id = st.task_id) |
|
| 117 | + 'DELETE t, st FROM '.prefixTable('background_tasks').' t |
|
| 118 | + INNER JOIN ' . prefixTable('background_subtasks').' st ON (t.increment_id = st.task_id) |
|
| 119 | 119 | WHERE t.finished_at < %i |
| 120 | 120 | AND t.status = %s', |
| 121 | 121 | time() - $this->maxTimeBeforeRemoval, |
@@ -132,7 +132,7 @@ discard block |
||
| 132 | 132 | |
| 133 | 133 | // Check if the maximum number of parallel tasks is reached |
| 134 | 134 | if ($runningTasks >= $this->maxParallelTasks) { |
| 135 | - if (LOG_TASKS=== true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 135 | + if (LOG_TASKS === true) $this->logger->log('Wait ... '.$runningTasks.' out of '.$this->maxParallelTasks.' are already running ', 'INFO'); |
|
| 136 | 136 | return; |
| 137 | 137 | } |
| 138 | 138 | |
@@ -141,7 +141,7 @@ discard block |
||
| 141 | 141 | // Fetch next batch of tasks |
| 142 | 142 | $tasks = DB::query( |
| 143 | 143 | 'SELECT increment_id, process_type, arguments |
| 144 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 144 | + FROM ' . prefixTable('background_tasks').' |
|
| 145 | 145 | WHERE is_in_progress = 0 |
| 146 | 146 | AND (finished_at IS NULL OR finished_at = "") |
| 147 | 147 | ORDER BY increment_id ASC |
@@ -150,7 +150,7 @@ discard block |
||
| 150 | 150 | ); |
| 151 | 151 | |
| 152 | 152 | foreach ($tasks as $task) { |
| 153 | - if (LOG_TASKS=== true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 153 | + if (LOG_TASKS === true) $this->logger->log('Launching '.$task['increment_id'], 'INFO'); |
|
| 154 | 154 | $this->processIndividualTask($task); |
| 155 | 155 | } |
| 156 | 156 | } |
@@ -161,7 +161,7 @@ discard block |
||
| 161 | 161 | * @param array $task The task to process. |
| 162 | 162 | */ |
| 163 | 163 | private function processIndividualTask(array $task) { |
| 164 | - if (LOG_TASKS=== true) $this->logger->log('Starting task: ' . print_r($task, true), 'INFO'); |
|
| 164 | + if (LOG_TASKS === true) $this->logger->log('Starting task: '.print_r($task, true), 'INFO'); |
|
| 165 | 165 | |
| 166 | 166 | // Store progress in the database |
| 167 | 167 | DB::update( |
@@ -179,19 +179,19 @@ discard block |
||
| 179 | 179 | // Prepare process |
| 180 | 180 | $process = new Process([ |
| 181 | 181 | PHP_BINARY, |
| 182 | - __DIR__ . '/background_tasks___worker.php', |
|
| 182 | + __DIR__.'/background_tasks___worker.php', |
|
| 183 | 183 | $task['increment_id'], |
| 184 | 184 | $task['process_type'], |
| 185 | 185 | $task['arguments'] |
| 186 | 186 | ]); |
| 187 | 187 | |
| 188 | 188 | // Launch process |
| 189 | - try{ |
|
| 189 | + try { |
|
| 190 | 190 | $process->setTimeout($this->maxExecutionTime); |
| 191 | 191 | $process->mustRun(); |
| 192 | 192 | |
| 193 | 193 | } catch (Exception $e) { |
| 194 | - if (LOG_TASKS=== true) $this->logger->log('Error launching task: ' . $e->getMessage(), 'ERROR'); |
|
| 194 | + if (LOG_TASKS === true) $this->logger->log('Error launching task: '.$e->getMessage(), 'ERROR'); |
|
| 195 | 195 | DB::update( |
| 196 | 196 | prefixTable('background_tasks'), |
| 197 | 197 | [ |
@@ -213,7 +213,7 @@ discard block |
||
| 213 | 213 | private function countRunningTasks(): int { |
| 214 | 214 | return DB::queryFirstField( |
| 215 | 215 | 'SELECT COUNT(*) |
| 216 | - FROM ' . prefixTable('background_tasks') . ' |
|
| 216 | + FROM ' . prefixTable('background_tasks').' |
|
| 217 | 217 | WHERE is_in_progress = 1' |
| 218 | 218 | ); |
| 219 | 219 | } |
@@ -234,10 +234,10 @@ discard block |
||
| 234 | 234 | */ |
| 235 | 235 | private function cleanMultipleItemsEdition() { |
| 236 | 236 | DB::query( |
| 237 | - 'DELETE i1 FROM ' . prefixTable('items_edition') . ' i1 |
|
| 237 | + 'DELETE i1 FROM '.prefixTable('items_edition').' i1 |
|
| 238 | 238 | JOIN ( |
| 239 | 239 | SELECT user_id, item_id, MIN(timestamp) AS oldest_timestamp |
| 240 | - FROM ' . prefixTable('items_edition') . ' |
|
| 240 | + FROM ' . prefixTable('items_edition').' |
|
| 241 | 241 | GROUP BY user_id, item_id |
| 242 | 242 | ) i2 ON i1.user_id = i2.user_id AND i1.item_id = i2.item_id |
| 243 | 243 | WHERE i1.timestamp > i2.oldest_timestamp' |
@@ -250,7 +250,7 @@ discard block |
||
| 250 | 250 | */ |
| 251 | 251 | private function handleItemTokensExpiration() { |
| 252 | 252 | DB::query( |
| 253 | - 'DELETE FROM ' . prefixTable('items_edition') . ' |
|
| 253 | + 'DELETE FROM '.prefixTable('items_edition').' |
|
| 254 | 254 | WHERE timestamp < %i', |
| 255 | 255 | time() - ($this->settings['delay_item_edition'] * 60 ?: EDITION_LOCK_PERIOD) |
| 256 | 256 | ); |
@@ -267,7 +267,7 @@ discard block |
||
| 267 | 267 | // 1. Get all finished tasks older than the cutoff timestamp |
| 268 | 268 | // and that are not in progress |
| 269 | 269 | $tasks = DB::query( |
| 270 | - 'SELECT increment_id FROM ' . prefixTable('background_tasks') . ' |
|
| 270 | + 'SELECT increment_id FROM '.prefixTable('background_tasks').' |
|
| 271 | 271 | WHERE status = %s AND is_in_progress = %i AND finished_at < %s', |
| 272 | 272 | 'completed', |
| 273 | 273 | -1, |
@@ -282,19 +282,19 @@ discard block |
||
| 282 | 282 | |
| 283 | 283 | // 2. Delete all subtasks related to these tasks |
| 284 | 284 | DB::query( |
| 285 | - 'DELETE FROM ' . prefixTable('background_subtasks') . ' |
|
| 285 | + 'DELETE FROM '.prefixTable('background_subtasks').' |
|
| 286 | 286 | WHERE task_id IN %ls', |
| 287 | 287 | $taskIds |
| 288 | 288 | ); |
| 289 | 289 | |
| 290 | 290 | // 3. Delete the tasks themselves |
| 291 | 291 | DB::query( |
| 292 | - 'DELETE FROM ' . prefixTable('background_tasks') . ' |
|
| 292 | + 'DELETE FROM '.prefixTable('background_tasks').' |
|
| 293 | 293 | WHERE increment_id IN %ls', |
| 294 | 294 | $taskIds |
| 295 | 295 | ); |
| 296 | 296 | |
| 297 | - if (LOG_TASKS=== true) $this->logger->log('Old finished tasks cleaned: ' . count($taskIds), 'INFO'); |
|
| 297 | + if (LOG_TASKS === true) $this->logger->log('Old finished tasks cleaned: '.count($taskIds), 'INFO'); |
|
| 298 | 298 | } |
| 299 | 299 | } |
| 300 | 300 | |
@@ -308,5 +308,5 @@ discard block |
||
| 308 | 308 | $tasksHandler = new BackgroundTasksHandler($settings); |
| 309 | 309 | $tasksHandler->processBackgroundTasks(); |
| 310 | 310 | } catch (Exception $e) { |
| 311 | - error_log('Teampass Background Tasks Error: ' . $e->getMessage()); |
|
| 311 | + error_log('Teampass Background Tasks Error: '.$e->getMessage()); |
|
| 312 | 312 | } |
| 313 | 313 | \ No newline at end of file |
@@ -72,7 +72,7 @@ discard block |
||
| 72 | 72 | || (isset($session_user_admin) && (int) $session_user_admin === 1)) { |
| 73 | 73 | // Not allowed page |
| 74 | 74 | $session->set('system-error_code', ERR_NOT_ALLOWED); |
| 75 | - include $SETTINGS['cpassman_dir'] . '/error.php'; |
|
| 75 | + include $SETTINGS['cpassman_dir'].'/error.php'; |
|
| 76 | 76 | exit; |
| 77 | 77 | } |
| 78 | 78 | |
@@ -125,12 +125,12 @@ discard block |
||
| 125 | 125 | if (empty($fav) === false) { |
| 126 | 126 | $data = DB::queryFirstRow( |
| 127 | 127 | 'SELECT i.label, i.description, i.id, i.id_tree, t.title |
| 128 | - FROM ' . prefixTable('items') . ' as i |
|
| 129 | - INNER JOIN ' . prefixTable('nested_tree') . ' as t ON (t.id = i.id_tree) |
|
| 128 | + FROM ' . prefixTable('items').' as i |
|
| 129 | + INNER JOIN ' . prefixTable('nested_tree').' as t ON (t.id = i.id_tree) |
|
| 130 | 130 | WHERE i.id = %i', |
| 131 | 131 | $fav |
| 132 | 132 | ); |
| 133 | - if (! empty($data['label'])) { |
|
| 133 | + if (!empty($data['label'])) { |
|
| 134 | 134 | ?> |
| 135 | 135 | <tr> |
| 136 | 136 | <td> |