Skip to content

Commit

Permalink
Leaf 4486 - update to update scripts
Browse files Browse the repository at this point in the history
  • Loading branch information
jampaul3 committed Jan 14, 2025
1 parent 56216f9 commit 6e901de
Show file tree
Hide file tree
Showing 2 changed files with 62 additions and 7 deletions.
40 changes: 40 additions & 0 deletions scripts/scheduled-task-commands/refreshOrgchartEmps.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php
require_once 'globals.php';
require_once APP_PATH . '/Leaf/Db.php';

$dir = '/var/www/html';

$startTime = microtime(true);

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

$vars = array(':orgcharts' => '/NATIONAL/101/orgchart');

$sql = 'SELECT `site_path`
FROM `sites`
WHERE `site_type` = "orgchart"
AND `site_path` IN (:orgcharts)
ORDER BY `site_path`';

$paths = $db->prepared_query($sql, $vars);

passthru("cat /dev/null > /var/www/tmp/refreshOrgcharts.txt");

echo "Refresh Orgcharts Started ...\r\n";

$forgcharts = fopen('/var/www/tmp/refreshOrgcharts.txt', 'w');

foreach ($paths as $path) {
$site = rtrim($path['site_path'], '/');
fwrite($forgcharts, "{$dir}{$site}/\r\n");
}

fclose($forgcharts);

echo "Refreshing Orgcharts\r\n";
passthru("cat /var/www/tmp/refreshOrgcharts.txt | parallel -j 100 -d '\r\n' php {}scripts/refreshOrgchartEmployees.php");

$endTime = microtime(true);
$timeInMinutes = round(($endTime - $startTime) / 60, 2);
echo "Refresh took {$timeInMinutes} minutes and ended at ";
echo date('Y-m-d g:i:s a'). "\r\n";
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@
require_once 'globals.php';
require_once APP_PATH . '/Leaf/Db.php';

$dir = '/var/www/scripts/updateNationalOrgchart.php';

$startTime = microtime(true);

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

$sql = 'SELECT `cacheID`, LEFT(`data`, 5) AS `data`
Expand All @@ -10,13 +14,24 @@

$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";
}
passthru("cat /dev/null > /var/www/tmp/nationalUpdate.txt");

echo "Beginning National Update ...\r\n";

$national = fopen('/var/www/tmp/nationalUpdate.txt', 'w');

foreach ($VISNS as $visn) {
if (str_starts_with($visn['data'], 'DN,')) {
fwrite($national, "{$dir} {$visn['cacheID']}\r\n");
}
}

updateEmps($VISNS);
fclose($national);

echo "Updating National Orgcharts\r\n";
passthru("cat /var/www/tmp/national.txt | parallel -j 100 -d '\r\n' php {}");

$endTime = microtime(true);
$timeInMinutes = round(($endTime - $startTime) / 60, 2);
echo "National Update took {$timeInMinutes} minutes and ended at ";
echo date('Y-m-d g:i:s a'). "\r\n";

0 comments on commit 6e901de

Please sign in to comment.