Skip to content

Commit

Permalink
Leaf 4376 - updates to disable users
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Dec 16, 2024
1 parent 950a228 commit 4c29539
Show file tree
Hide file tree
Showing 3 changed files with 62 additions and 18 deletions.
39 changes: 21 additions & 18 deletions app/Leaf/VAMCActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down Expand Up @@ -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);

Expand Down
17 changes: 17 additions & 0 deletions scripts/disableNationalOrgchartEmpolyees.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
require_once 'scheduled-task-commands/globals.php';
require_once APP_PATH . '/Leaf/Db.php';
require_once APP_PATH . '/Leaf/VAMCActiveDirectory.php';

$startTime = microtime(true);


$national_db = new App\Leaf\Db(DIRECTORY_HOST, DIRECTORY_USER, DIRECTORY_PASS, 'national_orgchart');
$dir = new App\Leaf\VAMCActiveDirectory($national_db);

$dir->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');
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?php
require_once 'globals.php';
require_once APP_PATH . '/Leaf/Db.php';

$db = new App\Leaf\Db(DIRECTORY_HOST, DIRECTORY_USER, DIRECTORY_PASS, 'national_orgchart');

$sql = 'SELECT `cacheID`, LEFT(`data`, 5) AS `data`
FROM `cache`
WHERE LEFT(`data`, 3) = "DN,"';

$VISNS = $db->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);

0 comments on commit 4c29539

Please sign in to comment.