From 4296d602287d816d7d974f75cccdebc56767de17 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Tue, 10 Dec 2024 14:06:06 -0500 Subject: [PATCH 01/10] Leaf 4486 - adding disabled_ts --- LEAF_Nexus/sources/Employee.php | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 9e344253a..12a5613fa 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -344,7 +344,8 @@ private function disableEmployees(array $deleted_employees): array { if (!empty($deleted_employees)) { $sql = "UPDATE `employee` - SET `deleted` = UNIX_TIMESTAMP(NOW()) + SET `deleted` = UNIX_TIMESTAMP(NOW()), + `userName` = concat('disabled_', `deleted`, '_', `userName`) WHERE `userName` IN (" . implode(",", array_fill(1, count($deleted_employees), '?')) . ")"; $result = $this->db->prepared_query($sql, array_values($deleted_employees)); @@ -449,7 +450,8 @@ private function getAllEmployees(Db $db): array { $vars = array(); $sql = 'SELECT LOWER(`userName`) AS `userName` - FROM `employee`'; + FROM `employee` + WHERE `userName` NOT LIKE "disabled_%"'; $result = $db->prepared_query($sql, $vars); @@ -1442,7 +1444,7 @@ public function search($input, $indicatorID = '') if (count($searchResult) > 0) { - + $empUID_list = ''; foreach ($searchResult as $employee) { @@ -1477,7 +1479,7 @@ public function search($input, $indicatorID = '') } $finalResult[$currEmpUID]['data'] = $this->getAllData($currEmpUID); } - + // attach all the assigned positions foreach ($result as $employeeData){ $finalResult[$employeeData['empUID']]['positionData'][] = $employeeData; From f6e3f67595c574b7290ad4f1c3caecc6632ba61f Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Fri, 13 Dec 2024 11:45:29 -0500 Subject: [PATCH 02/10] Leaf 4486 - continue updating for disabled users --- LEAF_Nexus/sources/Employee.php | 126 ++++++++++++++++++++++++++++++++ 1 file changed, 126 insertions(+) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 12a5613fa..8b698e8ff 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -43,6 +43,34 @@ class Employee extends Data private $deepSearch = 3; // Threshold for deeper search (min # of results before searching deeper) + private $disabledUsers; + + private $disableUserNameOrgchartTables = array( + 'employee_data', + 'employee_data_history', + 'group_data', + 'group_data_history', + 'position_data', + 'position_data_history', + 'relation_employee_backup' + ); + + private $disableUserNamePortalTables = array( + 'action_history', + 'approvals', + 'data', + 'data_extended', + 'data_history', + 'email_tracker', + 'notes', + 'process_query', + 'records', + 'service_chiefs', + 'signatures', + 'tags', + 'users' + ); + public function initialize() { $this->setDataTable($this->dataTable); @@ -221,6 +249,9 @@ private function updateEmployeeDataBatch(array $local_employees): array if (!empty($local_deleted_employees)) { $results[] = $this->disableEmployees($local_deleted_employees); + + $this->disableAllTables(); + $this->disablePortalTables(); } if (!empty($local_array)) { @@ -240,6 +271,101 @@ private function updateEmployeeDataBatch(array $local_employees): array return $results; } + private function disablePortalTables(): void + { + $portals = $this->getPortals(); + + $portal_db = $this->db; + + foreach ($portals as $portal) { + $portal_db->query('USE' . $portal['portal_database']); + + foreach ($this->disabledUsers as $user) { + // break down the userName to get original userName + $userName = explode('_', $user); + + // update all tables with the new userName + $vars = array(':disabledUserName' => $user, + ':originalUserName' => $userName[2]); + + foreach ($this->disableUserNamePortalTables as $table) { + $sql = 'UPDATE `' . $table . '` + SET `userID` = :disabledUserName + WHERE `userID` = :originalUserName'; + + $this->db->prepared_query($sql, $vars); + + if ($table == 'service_chiefs' || $table == 'users') { + $sql = 'UPDATE `' . $table . '` + SET `backupID` = :disabledUserName + WHERE `backupID` = :originalUserName'; + + $this->db->prepared_query($sql, $vars); + } + } + } + } + } + + private function getPortals(): array + { + // need to get the portals to update. Use ABSOLUTE_ORG_PATH to get all portals from + // the sites table will need to strip https://domain + $orgchart = str_replace(HTTP_HOST, '', ABSOLUTE_ORG_PATH); + $launchpad_db = new Db(DIRECTORY_HOST, DIRECTORY_USER, DIRECTORY_PASS, 'national_leaf_launchpad'); + + $vars = array(':orgchartPath' => $orgchart); + $sql = 'SELECT `portal_database` + FROM `sites` + WHERE `orgchart_path` = :orgchartPath'; + + $return_value = $launchpad_db->prepared_query($sql, $vars); + + return $return_value; + } + + private function disableAllTables(): void + { + // get all the newly disabled users + $this->disabledUsers = $this->getNewlyDisabledUsers(); + + foreach ($this->disabledUsers as $user) { + // break down the userName to get original userName + $userName = explode('_', $user); + + // update all tables with the new userName + $vars = array(':disabledUserName' => $user, + ':originalUserName' => $userName[2]); + + foreach ($this->disableUserNameOrgchartTables as $table) { + if ($table != 'relation_employee_backup') { + $sql = 'UPDATE `' . $table . '` + SET `author` = :disabledUserName + WHERE `author` = :originalUserName'; + } else { + $sql = 'UPDATE `' . $table . '` + SET `approverUserName` = :disabledUserName + WHERE `approverUserName` = :originalUserName'; + } + + $this->db->prepared_query($sql, $vars); + } + + } + } + + private function getNewlyDisabledUsers(): array + { + $vars = array(':deleteTime' => time() - 600); + $sql = 'SELECT `userName` + FROM `employees` + WHERE `deleted` > :deleteTime'; + + $return_value = $this->db->prepared_query($sql, $vars); + + return $return_value; + } + /** * @param array $local_employees_array * From 863f3d195b79fd8ddfb6efdf15d59035fd02be55 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Tue, 17 Dec 2024 15:46:57 -0500 Subject: [PATCH 03/10] Leaf 4486 - local orgchart userName update --- LEAF_Nexus/sources/Employee.php | 106 +++++++++++++++++--------------- 1 file changed, 57 insertions(+), 49 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 8b698e8ff..2cf1236f4 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -45,30 +45,35 @@ class Employee extends Data private $disabledUsers; + // the first value is the table, the second is the field. If the field is an array + // the first value needs to be the field used for the where clause. The field array + // is not current used but is setup to be able to be used later if needed. private $disableUserNameOrgchartTables = array( - 'employee_data', - 'employee_data_history', - 'group_data', - 'group_data_history', - 'position_data', - 'position_data_history', - 'relation_employee_backup' + 'employee_data' => 'author', + 'employee_data_history' => 'author', + 'group_data' => 'author', + 'group_data_history' => 'author', + 'position_data' => 'author', + 'position_data_history' => 'author', + 'relation_employee_backup' => 'approverUserName' ); + // the first value is the table, the second is the field. If the field is an array + // the first value needs to be the field used for the where clause. private $disableUserNamePortalTables = array( - 'action_history', - 'approvals', - 'data', - 'data_extended', - 'data_history', - 'email_tracker', - 'notes', - 'process_query', - 'records', - 'service_chiefs', - 'signatures', - 'tags', - 'users' + 'action_history' => 'userID', + 'approvals' => 'userID', + 'data' => 'userID', + 'data_extended' => 'userID', + 'data_history' => 'userID', + 'email_tracker' => 'userID', + 'notes' => 'userID', + 'process_query' => 'userID', + 'records' => 'userID', + 'service_chiefs' => array('userID', 'backupID'), + 'signatures' => 'userID', + 'tags' => 'userID', + 'users' => array('userID', 'backupID') ); public function initialize() @@ -277,6 +282,21 @@ private function disablePortalTables(): void $portal_db = $this->db; + $sql = ''; + + foreach ($this->disableUserNamePortalTables as $table => $field) { + if (is_array($field)) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field[0] . '` = :disabledUserName, + `' . $field[1] . '` = :disabledUserName + WHERE `' . $field[0] . '` = :originalUserName;'; + } else { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field . '` = :disabledUserName + WHERE `' . $field . '` = :originalUserName;'; + } + } + foreach ($portals as $portal) { $portal_db->query('USE' . $portal['portal_database']); @@ -288,21 +308,7 @@ private function disablePortalTables(): void $vars = array(':disabledUserName' => $user, ':originalUserName' => $userName[2]); - foreach ($this->disableUserNamePortalTables as $table) { - $sql = 'UPDATE `' . $table . '` - SET `userID` = :disabledUserName - WHERE `userID` = :originalUserName'; - - $this->db->prepared_query($sql, $vars); - - if ($table == 'service_chiefs' || $table == 'users') { - $sql = 'UPDATE `' . $table . '` - SET `backupID` = :disabledUserName - WHERE `backupID` = :originalUserName'; - - $this->db->prepared_query($sql, $vars); - } - } + $this->db->prepared_query($sql, $vars); } } } @@ -329,6 +335,21 @@ private function disableAllTables(): void // get all the newly disabled users $this->disabledUsers = $this->getNewlyDisabledUsers(); + $sql = ''; + + foreach ($this->disableUserNameOrgchartTables as $table => $field) { + if (is_array($field)) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field[0] . '` = :disabledUserName, + `' . $field[1] . '` = :disabledUserName + WHERE `' . $field[0] . '` = :originalUserName;'; + } else { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field . '` = :disabledUserName + WHERE `' . $field . '` = :originalUserName;'; + } + } + foreach ($this->disabledUsers as $user) { // break down the userName to get original userName $userName = explode('_', $user); @@ -337,20 +358,7 @@ private function disableAllTables(): void $vars = array(':disabledUserName' => $user, ':originalUserName' => $userName[2]); - foreach ($this->disableUserNameOrgchartTables as $table) { - if ($table != 'relation_employee_backup') { - $sql = 'UPDATE `' . $table . '` - SET `author` = :disabledUserName - WHERE `author` = :originalUserName'; - } else { - $sql = 'UPDATE `' . $table . '` - SET `approverUserName` = :disabledUserName - WHERE `approverUserName` = :originalUserName'; - } - - $this->db->prepared_query($sql, $vars); - } - + $this->db->prepared_query($sql, $vars); } } From 3838fe04eb77d1753de4e6687a32e463ceadf598 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 10:46:48 -0500 Subject: [PATCH 04/10] Leaf 4486 - update local disable/enable --- LEAF_Nexus/sources/Employee.php | 189 +++++++++++++++++++++++++------- 1 file changed, 149 insertions(+), 40 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 2cf1236f4..1fbc0ba85 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -124,6 +124,10 @@ public function refresh(string $user_name): array if (!isset($national_emp['data'])) { $this->disableEmployees(explode(',', $user_name)); + + $this->disableAllTables(); + $this->disablePortalTables(); + $return_value = array( 'status' => array( 'code' => 4, @@ -150,6 +154,10 @@ public function refresh(string $user_name): array ); } else { $this->disableEmployees(explode(',', $user_name)); + + $this->disableAllTables(); + $this->disablePortalTables(); + $return_value = array( 'status' => array( 'code' => 4, @@ -286,10 +294,12 @@ private function disablePortalTables(): void foreach ($this->disableUserNamePortalTables as $table => $field) { if (is_array($field)) { - $sql .= 'UPDATE `' . $table .'` - SET `' . $field[0] . '` = :disabledUserName, - `' . $field[1] . '` = :disabledUserName - WHERE `' . $field[0] . '` = :originalUserName;'; + foreach ($field as $fld) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $fld . '` = :disabledUserName + WHERE `' . $fld . '` = :originalUserName;'; + } + } else { $sql .= 'UPDATE `' . $table .'` SET `' . $field . '` = :disabledUserName @@ -298,51 +308,91 @@ private function disablePortalTables(): void } foreach ($portals as $portal) { - $portal_db->query('USE' . $portal['portal_database']); + $sql2 = 'USE ' . $portal['portal_database']; + $portal_db->prepared_query($sql2, array()); foreach ($this->disabledUsers as $user) { // break down the userName to get original userName - $userName = explode('_', $user); + $userName = explode('_', $user['userName']); // update all tables with the new userName - $vars = array(':disabledUserName' => $user, + $vars = array(':disabledUserName' => $user['userName'], ':originalUserName' => $userName[2]); - $this->db->prepared_query($sql, $vars); + $portal_db->prepared_query($sql, $vars); + } + } + } + + private function enableAllPortalTables(string $userName): void + { + $portals = $this->getPortals(); + + $portal_db = $this->db; + + $userNameParts = explode('_', $userName); + + $vars = array(':disabledUserName' => $userName, + ':originalUserName' => $userNameParts[2]); + $sql = ''; + + foreach ($this->disableUserNamePortalTables as $table => $field) { + if (is_array($field)) { + foreach ($field as $fld) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $fld . '` = :originalUserName + WHERE `' . $fld . '` = :disabledUserName;'; + } + + } else { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field . '` = :originalUserName + WHERE `' . $field . '` = :disabledUserName;'; } } + + foreach ($portals as $portal) { + $sql2 = 'USE ' . $portal['portal_database']; + $portal_db->prepared_query($sql2, array()); + + $portal_db->prepared_query($sql, $vars); + } } private function getPortals(): array { // need to get the portals to update. Use ABSOLUTE_ORG_PATH to get all portals from // the sites table will need to strip https://domain - $orgchart = str_replace(HTTP_HOST, '', ABSOLUTE_ORG_PATH); + $orgchart = str_replace('https://' . HTTP_HOST, '', ABSOLUTE_ORG_PATH); $launchpad_db = new Db(DIRECTORY_HOST, DIRECTORY_USER, DIRECTORY_PASS, 'national_leaf_launchpad'); $vars = array(':orgchartPath' => $orgchart); $sql = 'SELECT `portal_database` FROM `sites` - WHERE `orgchart_path` = :orgchartPath'; + WHERE `orgchart_path` = :orgchartPath + AND (`portal_database` IS NOT NULL + OR `portal_database` <> "")'; $return_value = $launchpad_db->prepared_query($sql, $vars); return $return_value; } - private function disableAllTables(): void + private function disableAllTables(int $deletedAgo = 600): void { // get all the newly disabled users - $this->disabledUsers = $this->getNewlyDisabledUsers(); + $this->disabledUsers = $this->getNewlyDisabledUsers($deletedAgo); $sql = ''; foreach ($this->disableUserNameOrgchartTables as $table => $field) { if (is_array($field)) { - $sql .= 'UPDATE `' . $table .'` - SET `' . $field[0] . '` = :disabledUserName, - `' . $field[1] . '` = :disabledUserName - WHERE `' . $field[0] . '` = :originalUserName;'; + foreach ($field as $fld) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $fld . '` = :disabledUserName + WHERE `' . $fld . '` = :originalUserName;'; + } + } else { $sql .= 'UPDATE `' . $table .'` SET `' . $field . '` = :disabledUserName @@ -352,21 +402,47 @@ private function disableAllTables(): void foreach ($this->disabledUsers as $user) { // break down the userName to get original userName - $userName = explode('_', $user); + $userName = explode('_', $user['userName']); // update all tables with the new userName - $vars = array(':disabledUserName' => $user, + $vars = array(':disabledUserName' => $user['userName'], ':originalUserName' => $userName[2]); $this->db->prepared_query($sql, $vars); } } - private function getNewlyDisabledUsers(): array + private function enableAllTables(string $userName): void { - $vars = array(':deleteTime' => time() - 600); + $userNameParts = explode('_', $userName); + + $vars = array(':disabledUserName' => $userName, + ':originalUserName' => $userNameParts[2]); + $sql = ''; + + foreach ($this->disableUserNameOrgchartTables as $table => $field) { + if (is_array($field)) { + foreach ($field as $fld) { + $sql .= 'UPDATE `' . $table .'` + SET `' . $fld . '` = :originalUserName + WHERE `' . $fld . '` = :disabledUserName;'; + } + + } else { + $sql .= 'UPDATE `' . $table .'` + SET `' . $field . '` = :originalUserName + WHERE `' . $field . '` = :disabledUserName;'; + } + } + + $this->db->prepared_query($sql, $vars); + } + + private function getNewlyDisabledUsers(int $deletedAgo = 600): array + { + $vars = array(':deleteTime' => time() - $deletedAgo); $sql = 'SELECT `userName` - FROM `employees` + FROM `employee` WHERE `deleted` > :deleteTime'; $return_value = $this->db->prepared_query($sql, $vars); @@ -503,6 +579,23 @@ private function disableEmployees(array $deleted_employees): array return $return_value; } + private function enableEmployee(string $userName): void + { + // userName will be in the format of disabled_ts_userName. + // This will need to be torn apart and only the userName kept. + $userNameParts = explode('_', $userName); + + $vars = array(':userName' => $userNameParts[2], + ':disabledUserName' => $userName, + ':deletedTime' => 0); + $sql = 'UPDATE `employee` + SET `userName` = :userName, + `deleted` = :deletedTime + WHERE `userName` = :disabledUserName'; + + $this->db->prepared_query($sql, $vars); + } + /** * @param array $national_employee_uids * @param array $local_employee_array @@ -921,54 +1014,70 @@ public function importFromNational($userName) /** * Marks employee as deleted + * disabling a user requires that all instances of the userName be updated both in + * orgchart and portals * @param int $empUID * @return bool */ public function disableAccount($empUID) { - if (!is_numeric($empUID)) - { + if (!is_numeric($empUID)) { return false; } + $memberships = $this->login->getMembership(); - if (!isset($memberships['groupID'][1])) - { + + if (!isset($memberships['groupID'][1])) { throw new Exception('Administrator access required to disable accounts'); } - $vars = array(':empUID' => $empUID, - ':time' => time(), - ); - $res = $this->db->prepared_query('UPDATE employee - SET deleted=:time - WHERE empUID=:empUID', $vars); + $vars = array(':empUID' => $empUID); + $sql = 'SELECT `userName` + FROM `employee` + WHERE `empUID` = :empUID'; + + $res = $this->db->prepared_query($sql, $vars); + + $this->disableEmployees(array($res[0]['userName'])); + + $this->disableAllTables(60); + $this->disablePortalTables(); return true; } /** * Marks employee as not deleted + * Enabling someone requires that all instances of the userName be updated in both + * the orgchart and portals * @param int $empUID * @return bool */ public function enableAccount($empUID) { - if (!is_numeric($empUID)) - { + if (!is_numeric($empUID)) { return false; } + $memberships = $this->login->getMembership(); - if (!isset($memberships['groupID'][1])) - { + + if (!isset($memberships['groupID'][1])) { throw new Exception('Administrator access required to enable accounts'); } - $vars = array(':empUID' => $empUID, - ':time' => 0, - ); - $res = $this->db->prepared_query('UPDATE employee + $vars = array(':empUID' => $empUID); + $sql = 'SELECT `userName` + FROM `employee` + WHERE `empUID` = :empUID'; + + $res = $this->db->prepared_query($sql, $vars); + + $this->enableEmployee($res[0]['userName']); + $this->enableAllTables($res[0]['userName']); + $this->enableAllPortalTables($res[0]['userName']); + /* $res = $this->db->prepared_query('UPDATE employee SET deleted=:time - WHERE empUID=:empUID', $vars); + WHERE empUID=:empUID', $vars); */ return true; } From 46f913e5b1fd024031315f61479da34aeac7e766 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 10:51:42 -0500 Subject: [PATCH 05/10] Leaf 4486 - remove comment --- LEAF_Nexus/sources/Employee.php | 3 --- 1 file changed, 3 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 1fbc0ba85..a06185083 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -1075,9 +1075,6 @@ public function enableAccount($empUID) $this->enableEmployee($res[0]['userName']); $this->enableAllTables($res[0]['userName']); $this->enableAllPortalTables($res[0]['userName']); - /* $res = $this->db->prepared_query('UPDATE employee - SET deleted=:time - WHERE empUID=:empUID', $vars); */ return true; } From 47bd9525988aafa4369d7e6f9693819833c84c99 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 13:27:08 -0500 Subject: [PATCH 06/10] Leaf 4486 - include national disabled employees --- LEAF_Nexus/sources/Employee.php | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index a06185083..958b34a66 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -258,8 +258,12 @@ private function updateEmployeeDataBatch(array $local_employees): array $this->prepareArrays($national_employee_uids, $local_array, $national_employees_list, $local_employee_array); + $users = $this->updateDisabledEmployees(); + $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); + $local_deleted_employees = array_merge($local_deleted_employees, $users); + if (!empty($local_deleted_employees)) { $results[] = $this->disableEmployees($local_deleted_employees); @@ -284,6 +288,25 @@ private function updateEmployeeDataBatch(array $local_employees): array return $results; } + private function updateDisabledEmployees(): array + { + $vars = array(); + $sql = 'SELECT `userName` + FROM `employee` + WHERE `deleted` > 0 + AND LEFT(`userName`, 9) <> "disabled_"'; + + $res = $this->db->prepared_query($sql, $vars); + + $userNames = array(); + + foreach ($res as $user) { + $userNames[] = $user['userName']; + } + + return $userNames; + } + private function disablePortalTables(): void { $portals = $this->getPortals(); From 188ecae25db56e691e272c34ca6c99561ea42fdf Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 13:53:42 -0500 Subject: [PATCH 07/10] Leaf 4486 - rearrange updates --- LEAF_Nexus/sources/Employee.php | 26 +++++++++++++------------- 1 file changed, 13 insertions(+), 13 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 958b34a66..e75c6233b 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -258,19 +258,6 @@ private function updateEmployeeDataBatch(array $local_employees): array $this->prepareArrays($national_employee_uids, $local_array, $national_employees_list, $local_employee_array); - $users = $this->updateDisabledEmployees(); - - $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); - - $local_deleted_employees = array_merge($local_deleted_employees, $users); - - if (!empty($local_deleted_employees)) { - $results[] = $this->disableEmployees($local_deleted_employees); - - $this->disableAllTables(); - $this->disablePortalTables(); - } - if (!empty($local_array)) { $results[] = $this->batchEmployeeUpdate($local_array); } @@ -283,6 +270,19 @@ private function updateEmployeeDataBatch(array $local_employees): array $results[] = $this->batchEmployeeDataUpdate($local_data_array); } + $users = $this->updateDisabledEmployees(); + + $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); + + $local_deleted_employees = array_merge($local_deleted_employees, $users); + error_log(print_r($local_deleted_employees, true), 3, '/var/www/php-logs/testing.log'); + + if (!empty($local_deleted_employees)) { + $results[] = $this->disableEmployees($local_deleted_employees); + + $this->disableAllTables(); + $this->disablePortalTables(); + } } return $results; From 80826d54c7ae3c409297ae468413430db78302a2 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 14:39:39 -0500 Subject: [PATCH 08/10] Leaf 4486 - fixing an error --- LEAF_Nexus/sources/Employee.php | 35 +++++++++++++++++++-------------- 1 file changed, 20 insertions(+), 15 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index e75c6233b..26ed7ccc7 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -258,6 +258,15 @@ private function updateEmployeeDataBatch(array $local_employees): array $this->prepareArrays($national_employee_uids, $local_array, $national_employees_list, $local_employee_array); + $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); + + if (!empty($local_deleted_employees)) { + $results[] = $this->disableEmployees($local_deleted_employees); + + $this->disableAllTables(); + $this->disablePortalTables(); + } + if (!empty($local_array)) { $results[] = $this->batchEmployeeUpdate($local_array); } @@ -270,15 +279,10 @@ private function updateEmployeeDataBatch(array $local_employees): array $results[] = $this->batchEmployeeDataUpdate($local_data_array); } - $users = $this->updateDisabledEmployees(); - - $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); + $users = $this->updateNationalDisabledEmployees(); - $local_deleted_employees = array_merge($local_deleted_employees, $users); - error_log(print_r($local_deleted_employees, true), 3, '/var/www/php-logs/testing.log'); - - if (!empty($local_deleted_employees)) { - $results[] = $this->disableEmployees($local_deleted_employees); + if (!empty($users)) { + $results[] = $this->disableEmployees($users); $this->disableAllTables(); $this->disablePortalTables(); @@ -288,7 +292,7 @@ private function updateEmployeeDataBatch(array $local_employees): array return $results; } - private function updateDisabledEmployees(): array + private function updateNationalDisabledEmployees(): array { $vars = array(); $sql = 'SELECT `userName` @@ -401,10 +405,10 @@ private function getPortals(): array return $return_value; } - private function disableAllTables(int $deletedAgo = 600): void + private function disableAllTables(): void { // get all the newly disabled users - $this->disabledUsers = $this->getNewlyDisabledUsers($deletedAgo); + $this->disabledUsers = $this->getNewlyDisabledUsers(); $sql = ''; @@ -461,12 +465,13 @@ private function enableAllTables(string $userName): void $this->db->prepared_query($sql, $vars); } - private function getNewlyDisabledUsers(int $deletedAgo = 600): array + private function getNewlyDisabledUsers(): array { - $vars = array(':deleteTime' => time() - $deletedAgo); + $vars = array(':deleteTime' => 0); $sql = 'SELECT `userName` FROM `employee` - WHERE `deleted` > :deleteTime'; + WHERE `deleted` > :deleteTime + AND LEFT(`userName`, 9) <> "disabled_"'; $return_value = $this->db->prepared_query($sql, $vars); @@ -1063,7 +1068,7 @@ public function disableAccount($empUID) $this->disableEmployees(array($res[0]['userName'])); - $this->disableAllTables(60); + $this->disableAllTables(); $this->disablePortalTables(); return true; From f6166f7b02be65305dd7d1f6d71c13fd91ab63c5 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Wed, 18 Dec 2024 14:47:32 -0500 Subject: [PATCH 09/10] Leaf 4486 - fixing error --- LEAF_Nexus/sources/Employee.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 26ed7ccc7..17bccf3e4 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -586,14 +586,13 @@ private function disableEmployees(array $deleted_employees): array `userName` = concat('disabled_', `deleted`, '_', `userName`) WHERE `userName` IN (" . implode(",", array_fill(1, count($deleted_employees), '?')) . ")"; - $result = $this->db->prepared_query($sql, array_values($deleted_employees)); + $this->db->prepared_query($sql, array_values($deleted_employees)); $return_value = array( 'status' => array( 'code' => 2, 'message' => '' - ), - 'data' => $result + ) ); } else { $return_value = array( From 730ce8c99de10145ca53298cbe14cfd607bd94f4 Mon Sep 17 00:00:00 2001 From: Jamie P Holcomb Date: Thu, 26 Dec 2024 07:52:02 -0500 Subject: [PATCH 10/10] Leaf 4486 - minor comparison change --- LEAF_Nexus/sources/Employee.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/LEAF_Nexus/sources/Employee.php b/LEAF_Nexus/sources/Employee.php index 17bccf3e4..378c9677d 100644 --- a/LEAF_Nexus/sources/Employee.php +++ b/LEAF_Nexus/sources/Employee.php @@ -258,7 +258,7 @@ private function updateEmployeeDataBatch(array $local_employees): array $this->prepareArrays($national_employee_uids, $local_array, $national_employees_list, $local_employee_array); - $local_deleted_employees = array_diff(array_column($local_employees_uid, 'userName'), array_column($national_employees_list, 'userName')); + $local_deleted_employees = array_diff(array_column($local_employees_uid['data'], 'userName'), array_column($national_employees_list['data'], 'userName')); if (!empty($local_deleted_employees)) { $results[] = $this->disableEmployees($local_deleted_employees);