Skip to content

Commit

Permalink
Leaf 4630 - script to update existing disabled users
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Jan 7, 2025
1 parent 168d1ee commit d5d840b
Show file tree
Hide file tree
Showing 3 changed files with 95 additions and 2 deletions.
9 changes: 7 additions & 2 deletions app/Leaf/VAMCActiveDirectory.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,10 +115,15 @@ public function importADData(string $file): string
$this->importData();
}

public function disableNationalOrgchartEmployees(): void
public function disableNationalOrgchartEmployees(array $disabledUsers = null): void
{
// get all userNames that should be disabled
$disableUsersList = $this->getUserNamesToBeDisabled();
if ($disabledUsers === null) {
$disableUsersList = $this->getUserNamesToBeDisabled();
} else {
$disableUsersList = $disabledUsers;
}


// Disable users not in this array
$this->preventRecycledUserName($disableUsersList);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
<?php
require_once 'globals.php';
require_once APP_PATH . '/Leaf/Db.php';

$VISNS = array('acc.dva.va.gov',
'cem.va.gov',
'dva.va.gov',
'mpi.v21.med.va.gov',
'r01.med.va.gov',
'r02.med.va.gov',
'r03.med.va.gov',
'r04.med.va.gov',
'va',
'va.gov',
'vba.va.gov',
'vha.med.va.gov',
'VHA01',
'VHA02',
'VHA03',
'VHA04',
'VHA05',
'VHA06',
'VHA07',
'VHA08',
'VHA09',
'VHA10',
'VHA11',
'VHA12',
'VHA15',
'VHA16',
'VHA17',
'VHA18',
'VHA19',
'VHA20',
'VHA21',
'VHA22',
'VHA23',
);

function updateEmps($VISNS) {
foreach ($VISNS as $visn) {
if (str_starts_with($visn['data'], 'DN,')) {
exec("php /var/www/scripts/updateExistingDisabledNationalOrgchart.php {$visn} > /dev/null 2>/dev/null &");
echo "Deploying to: {$visn}\r\n";
}
}
}

updateEmps($VISNS);
39 changes: 39 additions & 0 deletions scripts/updateExistingDisabledNationalOrgchart.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?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);

if (count($argv) < 1) {
// no argument supplied
exit();
}

$file = $argv[1];

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

$vars = array(':domain' => $file);
$sql = 'SELECT `userName`
FROM `employee`
WHERE `deleted` > 0
AND LEFT(`userName`, 9) <> "disabled_"
AND `domain` = :domain
LIMIT 1000';

$VISNS = $db->prepared_query($sql, $vars);
$users = array();

foreach ($VISNS as $user) {
$users[] = $user['userName'];
}

$dir = new App\Leaf\VAMCActiveDirectory($national_db);

$dir->disableNationalOrgchartEmployees($users);

$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/update_existing.log');

0 comments on commit d5d840b

Please sign in to comment.