1
0

UpdatesLog

This commit is contained in:
Mike Schwörer 2020-01-15 00:45:30 +01:00
parent a96315a103
commit f904691006
Signed by: Mikescher
GPG Key ID: D3C7172E0A70F8CF
4 changed files with 45 additions and 14 deletions

View File

@ -10,7 +10,7 @@ if (!isset($API_OPTIONS['name'])) httpDie(400, "Wrong parameters.");
$name = $API_OPTIONS['name']; $name = $API_OPTIONS['name'];
$updatedata = Programs::listUpdateData(); $updatedata = UpdatesLog::listUpdateData();
if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found'); if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found');

View File

@ -10,8 +10,6 @@ class AlephNoteStatistics
public function __construct(Website $site) public function __construct(Website $site)
{ {
$this->site = $site; $this->site = $site;
$site->Database();
} }
public function getTotalUserCount() public function getTotalUserCount()

View File

@ -4,17 +4,45 @@ require_once (__DIR__ . '/../internals/database.php');
class UpdatesLog class UpdatesLog
{ {
public static function insert($name, $version) /** @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)
{ {
$ip = get_client_ip(); $ip = get_client_ip();
$ippath = __DIR__ . '/../dynamic/self_ip_address.auto.cfg'; $ippath = (__DIR__ . '/../dynamic/self_ip_address.auto.cfg');
$self_ip = file_exists($ippath) ? file_get_contents($ippath) : 'N/A'; $self_ip = file_exists($ippath) ? file_get_contents($ippath) : 'N/A';
if ($self_ip === $ip) $ip = "self"; if ($self_ip === $ip) $ip = "self";
Database::connect(); $this->site->Database()->sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())",
Database::sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())",
[ [
[':pn', $name, PDO::PARAM_STR], [':pn', $name, PDO::PARAM_STR],
[':ip', $ip, PDO::PARAM_STR], [':ip', $ip, PDO::PARAM_STR],
@ -22,16 +50,14 @@ class UpdatesLog
]); ]);
} }
public static function listProgramsInformation() public function listProgramsInformation()
{ {
Database::connect(); 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');
return 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');
} }
public static function getEntries($name, $limit) public function getEntries($name, $limit)
{ {
Database::connect(); return $this->site->Database()->sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt',
return Database::sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt',
[ [
[':pn', $name, PDO::PARAM_STR], [':pn', $name, PDO::PARAM_STR],
[':lt', $limit, PDO::PARAM_INT], [':lt', $limit, PDO::PARAM_INT],

View File

@ -21,6 +21,7 @@ class Website
/** @var Euler|null */ private $euler = null; /** @var Euler|null */ private $euler = null;
/** @var Programs|null */ private $programs = null; /** @var Programs|null */ private $programs = null;
/** @var AlephNoteStatistics|null */ private $anstats = null; /** @var AlephNoteStatistics|null */ private $anstats = null;
/** @var UpdatesLog|null */ private $updateslog = null;
public function init() public function init()
{ {
@ -196,10 +197,16 @@ class Website
public function AlephNoteStatistics() public function AlephNoteStatistics()
{ {
if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics(); } if ($this->anstats === null) { require_once 'alephnoteStatistics.php'; $this->anstats = new AlephNoteStatistics($this); }
return $this->anstats; return $this->anstats;
} }
public function UpdatesLog()
{
if ($this->updateslog === null) { require_once 'updateslog.php'; $this->updateslog = new UpdatesLog($this); }
return $this->updateslog;
}
/** /**
* @return bool * @return bool
*/ */