From f904691006c732183854f79973e10c56beb5083f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Mike=20Schw=C3=B6rer?= Date: Wed, 15 Jan 2020 00:45:30 +0100 Subject: [PATCH] UpdatesLog --- www/commands/progs_updatecheck.php | 2 +- www/internals/alephnoteStatistics.php | 2 -- www/internals/updateslog.php | 46 +++++++++++++++++++++------ www/internals/website.php | 9 +++++- 4 files changed, 45 insertions(+), 14 deletions(-) diff --git a/www/commands/progs_updatecheck.php b/www/commands/progs_updatecheck.php index 93108a8..245f42a 100644 --- a/www/commands/progs_updatecheck.php +++ b/www/commands/progs_updatecheck.php @@ -10,7 +10,7 @@ if (!isset($API_OPTIONS['name'])) httpDie(400, "Wrong parameters."); $name = $API_OPTIONS['name']; -$updatedata = Programs::listUpdateData(); +$updatedata = UpdatesLog::listUpdateData(); if (!array_key_exists($name, $updatedata)) httpError(404, 'Invalid Request - [Name] not found'); diff --git a/www/internals/alephnoteStatistics.php b/www/internals/alephnoteStatistics.php index 6c59386..1f1be2b 100644 --- a/www/internals/alephnoteStatistics.php +++ b/www/internals/alephnoteStatistics.php @@ -10,8 +10,6 @@ class AlephNoteStatistics public function __construct(Website $site) { $this->site = $site; - - $site->Database(); } public function getTotalUserCount() diff --git a/www/internals/updateslog.php b/www/internals/updateslog.php index dc40512..01ee07d 100644 --- a/www/internals/updateslog.php +++ b/www/internals/updateslog.php @@ -4,17 +4,45 @@ require_once (__DIR__ . '/../internals/database.php'); 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(); - $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'; if ($self_ip === $ip) $ip = "self"; - Database::connect(); - Database::sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())", + $this->site->Database()->sql_exec_prep("INSERT INTO updateslog (programname, ip, version, date) VALUES (:pn, :ip, :vn, NOW())", [ [':pn', $name, PDO::PARAM_STR], [':ip', $ip, PDO::PARAM_STR], @@ -22,16 +50,14 @@ class UpdatesLog ]); } - public static function listProgramsInformation() + public function listProgramsInformation() { - Database::connect(); - 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'); + 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'); } - public static function getEntries($name, $limit) + public function getEntries($name, $limit) { - Database::connect(); - return Database::sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt', + return $this->site->Database()->sql_query_assoc_prep('SELECT * FROM updateslog WHERE programname = :pn ORDER BY date DESC LIMIT :lt', [ [':pn', $name, PDO::PARAM_STR], [':lt', $limit, PDO::PARAM_INT], diff --git a/www/internals/website.php b/www/internals/website.php index ebaf9c2..e564c62 100644 --- a/www/internals/website.php +++ b/www/internals/website.php @@ -21,6 +21,7 @@ class Website /** @var Euler|null */ private $euler = null; /** @var Programs|null */ private $programs = null; /** @var AlephNoteStatistics|null */ private $anstats = null; + /** @var UpdatesLog|null */ private $updateslog = null; public function init() { @@ -196,10 +197,16 @@ class Website 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; } + public function UpdatesLog() + { + if ($this->updateslog === null) { require_once 'updateslog.php'; $this->updateslog = new UpdatesLog($this); } + return $this->updateslog; + } + /** * @return bool */