Skip to content
Permalink
Browse files
Merge pull request #682 from Alexandr-logrus/alpha
Update cycle_states.php
  • Loading branch information
sergejey committed Feb 7, 2020
2 parents a731888 + 2cfaa2d commit b3dd6b7ac6ed78357072d46ec0273df65c305a0f
Showing 1 changed file with 12 additions and 28 deletions.
@@ -15,14 +15,21 @@

$checked_time = 0;

$objects = getObjectsByClass('systemStates');
$total = count($objects);

if ($_GET['once'])
{
$last_run = getGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run');

if ((time() - $last_run) > 5 * 60)
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
cycleBody();

for ($i = 0; $i < $total; $i++)
{
callMethod($objects[$i]['TITLE'] . '.checkState');
}
}

echo "OK";
@@ -37,7 +44,10 @@
{
setGlobal((str_replace('.php', '', basename(__FILE__))) . 'Run', time(), 1);
$checked_time = time();
cycleBody();
for ($i = 0; $i < $total; $i++)
{
callMethod($objects[$i]['TITLE'] . '.checkState');
}
}

if (file_exists('./reboot') || IsSet($_GET['onetime']))
@@ -50,29 +60,3 @@

DebMes("Unexpected close of cycle: " . basename(__FILE__));
}

/**
* Summary of cycleBody
* @return void
*/
function cycleBody()
{
// check main system states
$objects = getObjectsByClass('systemStates');
$total = count($objects);

for ($i = 0; $i < $total; $i++)
{
$oldState = getGlobal($objects[$i]['TITLE'] . '.stateColor');
callMethod($objects[$i]['TITLE'] . '.checkState');
$newState = getGlobal($objects[$i]['TITLE'] . '.stateColor');

if ($newState != $oldState)
{
echo $objects[$i]['TITLE'] . " state changed to " . $newState . PHP_EOL;

$params = array('STATE' => $newState);
callMethod($objects[$i]['TITLE'] . '.stateChanged', $params);
}
}
}

0 comments on commit b3dd6b7

Please sign in to comment.