1
0
www.mikescher.com/www/internals/updateslog.php

66 lines
1.7 KiB
PHP
Raw Normal View History

2020-01-14 22:25:43 +01:00
<?php
2018-02-03 15:44:40 +01:00
require_once (__DIR__ . '/../internals/database.php');
class UpdatesLog
{
2020-01-15 00:45:30 +01:00
/** @var Website */
private $site;
/** @var array */
private $staticData;
public function __construct(Website $site)
{
$this->site = $site;
$this->load();
}
private function load()
{
$all = require (__DIR__ . '/../statics/blog/__all.php');
$this->staticData = array_map(function($a){return self::readSingle($a);}, $all);
}
private static function readSingle($d)
{
return $d;
}
public function listUpdateData()
{
return $this->staticData;
}
public function insert($name, $version)
2018-02-03 15:44:40 +01:00
{
$ip = get_client_ip();
2020-01-15 00:45:30 +01:00
$ippath = (__DIR__ . '/../dynamic/self_ip_address.auto.cfg');
2018-02-03 15:44:40 +01:00
$self_ip = file_exists($ippath) ? file_get_contents($ippath) : 'N/A';
if ($self_ip === $ip) $ip = "self";
2020-01-15 00:45:30 +01:00
$this->site->Database()->sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())",
2018-02-03 15:44:40 +01:00
[
[':pn', $name, PDO::PARAM_STR],
[':ip', $ip, PDO::PARAM_STR],
[':vn', $version, PDO::PARAM_STR],
]);
}
2020-01-15 00:45:30 +01:00
public function listProgramsInformation()
2018-02-03 15:44:40 +01:00
{
2020-01-15 00:45:30 +01:00
return $this->site->Database()->sql_query_assoc('SELECT programname AS name, Count(*) as count_total, MAX(date) AS last_query, (SELECT COUNT(*) FROM updateslog AS u1 WHERE u1.programname=u0.programname AND NOW() - INTERVAL 7 DAY < u1.date) AS count_week FROM updateslog AS u0 GROUP BY programname');
2018-02-03 15:44:40 +01:00
}
2020-01-15 00:45:30 +01:00
public function getEntries($name, $limit)
2018-02-03 15:44:40 +01:00
{
2020-01-15 00:45:30 +01:00
return $this->site->Database()->sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt',
2018-02-03 15:44:40 +01:00
[
[':pn', $name, PDO::PARAM_STR],
[':lt', $limit, PDO::PARAM_INT],
]);
}
}