Commit 8531668d authored by dmorley's avatar dmorley

use a function for getMeta like a real boy

parent 58aea2eb
Pipeline #583 failed with stage
in 3 minutes and 29 seconds
......@@ -449,4 +449,4 @@ updateMeta('pods_updated');
$time_end = microtime(true);
$execution_time = ($time_end - $time_start)/60;
updateMeta('pods_update_runtime', round($execution_time));
$languagesupdated ?: updateMeta('languages_updated');
($languagesupdated ?: updateMeta('languages_updated'));
......@@ -22,19 +22,6 @@ $status = isset($_GET['status']) || $input === 'status';
$simpleview = !($mapview || $podmin || $podminedit || $statsview);
$fullview = false;
try {
$dbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'pods_updated'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
$pods_updated = $dbstatus['date_created'];
?>
<!doctype html>
<html lang="en">
......@@ -153,7 +140,7 @@ $navs = [
</div>
</main>
<footer class="ml-3 text-muted">
<small>Data refreshed <?php echo Carbon::createFromFormat('Y-m-d H:i:s.u', $pods_updated)->diffForHumans(); ?></small>
<small>Data refreshed <?php echo Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('pods_updated','date_created'))->diffForHumans(); ?></small>
</footer>
<input type="hidden" name="input" value="<?php echo $input ?>"/>
<script src="node_modules/jquery/dist/jquery.min.js"></script>
......
......@@ -228,3 +228,27 @@ function updateMeta($name, $value = '1')
die('Error in SQL query: ' . $e->getMessage());
}
}
/**
* Get meta table last item
*
* @param string|string
*
* @return value
*/
function getMeta($name, $select = 'value')
{
try {
$metaresult = R::getRow("
SELECT $select
FROM meta
WHERE name = '$name'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Error in SQL query: ' . $e->getMessage());
}
$result = $metaresult[$select];
return $result;
}
......@@ -7,55 +7,7 @@ require_once __DIR__ . '/boot.php';
use Carbon\Carbon;
use RedBeanPHP\R;
try {
$updbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'pods_updated'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
try {
$durdbstatus = R::getRow("
SELECT value
FROM meta
WHERE name = 'pods_update_runtime'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
try {
$langdbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'languages_updated'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
try {
$backdbstatus = R::getRow("
SELECT date_created
FROM meta
WHERE name = 'backup'
ORDER BY id DESC
LIMIT 1
");
} catch (\RedBeanPHP\RedException $e) {
die('Status Red Error in SQL query: ' . $e->getMessage());
}
$pods_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', $updbstatus['date_created'])->diffInMinutes();
$pods_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('pods_updated','date_created'))->diffInMinutes();
echo "<small>";
if ($pods_updated_stats < 120) {
echo "System status is Green<br>";
......@@ -64,12 +16,12 @@ if ($pods_updated_stats < 120) {
}
echo "Last Update was " . $pods_updated_stats . " minutes<br>";
echo "Last Update run duration was " . $durdbstatus['value'] . " minutes<br>";
echo "Last Update run duration was " . getMeta('pods_update_runtime') . " minutes<br>";
$lang_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', $langdbstatus['date_created'])->diffInHours();
$lang_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('languages_updated','date_created'))->diffInHours();
echo "Last Language check was " . $lang_updated_stats . " hours<br>";
$back_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', $backdbstatus['date_created'])->diffInMinutes();
$back_updated_stats = Carbon::createFromFormat('Y-m-d H:i:s.u', getMeta('backup','date_created'))->diffInMinutes();
echo "Last SQL Backup was " . $back_updated_stats . " minutes<br>";
echo "</small>";
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment