diff --git a/app/Leaf/VAMCActiveDirectory.php b/app/Leaf/VAMCActiveDirectory.php index 1c070a802..b119bbd63 100644 --- a/app/Leaf/VAMCActiveDirectory.php +++ b/app/Leaf/VAMCActiveDirectory.php @@ -113,16 +113,15 @@ public function importADData($file) // import any remaining entries $this->importData(); + } + public function disableNationalOrgchartEmployees(): void + { // get all userNames that should be disabled $disableUsersList = $this->getUserNamesToBeDisabled(); - error_log(print_r($disableUsersList, true), 3, '/var/www/php-logs/errors.log'); - // Disable users not in this array - //$this->preventRecycledUserName($disableUsersList); - - + $this->preventRecycledUserName($disableUsersList); } // Imports data from \t and \n delimited file of format: @@ -250,35 +249,39 @@ private function getUserNamesToBeDisabled(): array $sql = 'SELECT `userName` FROM `employee` WHERE `deleted` = 0 - AND `lastUpdated` < (UNIX_TIMESTAMP(NOW() - 108000) '; + AND `lastUpdated` < (UNIX_TIMESTAMP(NOW() - 108000))'; $return_value = $this->db->prepared_query($sql, array()); return $return_value; } - private function getNewlyDeletedUsers($time): array + private function preventRecycledUserName(array $userNames): void { - $sql = 'SELECT `userName` - FROM `employee` - WHERE `userName` LIKE "disabled_{$time}_%"'; + /*$commaUserNames = implode(',', $userNames); + $deleteTime = time(); - $return_value = $this->db->prepared_query($sql, array()); + $vars = array(':deleteTime' => $deleteTime);*/ + $commaUserNames = ''; - return $return_value; - } + foreach ($userNames as $user) { + $commaUserNames .= '"' . $user['userName'] . '",'; + } - private function preventRecycledUserName(array $userNames): void - { - $commaUserNames = implode(',', $userNames); $deleteTime = time(); - $vars = array(':deleteTime' => $deleteTime); + $vars = array(':deleteTime' => $deleteTime, + ':userNames' => $commaUserNames); + error_log(print_r($vars, true), 3, '/var/www/php-logs/testing.log'); + /*$sql = 'UPDATE `employee` + SET `deleted` = :deleteTime, + `userName` = concat("disabled_", `deleted`, "_", `userName`) + WHERE `userName` IN ("' . implode('","', array_values($userNames)) . '")';*/ $sql = 'UPDATE `employee` SET `deleted` = :deleteTime, `userName` = concat("disabled_", `deleted`, "_", `userName`) - WHERE `userName` IN ("' . implode('","', array_values($userNames)) . '")'; + WHERE `userName` IN (:userNames)'; $this->db->prepared_query($sql, $vars); diff --git a/scripts/disableNationalOrgchartEmpolyees.php b/scripts/disableNationalOrgchartEmpolyees.php new file mode 100644 index 000000000..7d4117175 --- /dev/null +++ b/scripts/disableNationalOrgchartEmpolyees.php @@ -0,0 +1,17 @@ +disableNationalOrgchartEmployees(); + +$endTime = microtime(true); +$totalTime = round(($endTime - $startTime)/60, 2); + +error_log(print_r($file . " took " . $totalTime . " minutes to complete.", true), 3 , '/var/www/php-logs/ad_processing.log'); \ No newline at end of file diff --git a/scripts/scheduled-task-commands/updateNationalOrgchartEmployees.php b/scripts/scheduled-task-commands/updateNationalOrgchartEmployees.php new file mode 100644 index 000000000..39c3f867b --- /dev/null +++ b/scripts/scheduled-task-commands/updateNationalOrgchartEmployees.php @@ -0,0 +1,24 @@ +query($sql); + +function updateEmps($VISNS) { + foreach ($VISNS as $visn) { + if (str_starts_with($visn['data'], 'DN,')) { + exec("php /var/www/scripts/updateNationalOrgchart.php {$visn['cacheID']} > /dev/null 2>/dev/null &"); + echo "Deploying to: {$visn['cacheID']}\r\n"; + } + } + + exec ("php disableNationalOrgchartEmployees.php > /dev/null 2>/dev/null &"); +} + +updateEmps($VISNS); \ No newline at end of file