Skip to content

Commit

Permalink
Leaf 4486 - local orgchart userName update
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Dec 17, 2024
1 parent f6e3f67 commit 863f3d1
Showing 1 changed file with 57 additions and 49 deletions.
106 changes: 57 additions & 49 deletions LEAF_Nexus/sources/Employee.php
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down Expand Up @@ -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']);

Expand All @@ -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);
}
}
}
Expand All @@ -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);
Expand All @@ -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);
}
}

Expand Down

0 comments on commit 863f3d1

Please sign in to comment.