continue working on selftest
This commit is contained in:
6
www/internals/iwebsitemodule.php
Normal file
6
www/internals/iwebsitemodule.php
Normal file
@@ -0,0 +1,6 @@
|
||||
<?php
|
||||
|
||||
interface IWebsiteModule
|
||||
{
|
||||
public function checkConsistency();
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class AdventOfCode
|
||||
class AdventOfCode implements IWebsiteModule
|
||||
{
|
||||
const YEARS =
|
||||
[
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class AlephNoteStatistics
|
||||
class AlephNoteStatistics implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@@ -29,4 +29,9 @@ class AlephNoteStatistics
|
||||
{
|
||||
return $this->site->modules->Database()->sql_query_assoc('SELECT * FROM an_statslog WHERE NoteCount>0 ORDER BY LastChanged DESC');
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Blog
|
||||
class Blog implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Books
|
||||
class Books implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@@ -39,8 +39,8 @@ class Books
|
||||
|
||||
for ($i=1; $i <= $a['imagecount']; $i++)
|
||||
{
|
||||
$a['extraimages_urls'] []= '/data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
$a['extraimages_urls'] []= '/data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../../data/images/book_img/' . $a['id'] . '_img' . $i . '.jpg';
|
||||
}
|
||||
|
||||
$a['book_count'] = is_array($a['pdf']) ? count($a['pdf']) : 1;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Database
|
||||
class Database implements IWebsiteModule
|
||||
{
|
||||
/* @var PDO $pdo */
|
||||
private $pdo = NULL;
|
||||
@@ -91,4 +91,9 @@ class Database
|
||||
|
||||
return $stmt->rowCount();
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Euler
|
||||
class Euler implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Highscores
|
||||
class Highscores implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@@ -105,4 +105,9 @@ class Highscores
|
||||
[ ':pid', $playerid, PDO::PARAM_INT ],
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -2,7 +2,7 @@
|
||||
|
||||
require_once (__DIR__ . '/../../extern/egg/ExtendedGitGraph2.php');
|
||||
|
||||
class MikescherGitGraph
|
||||
class MikescherGitGraph implements IWebsiteModule
|
||||
{
|
||||
/** @var ExtendedGitGraph2 */
|
||||
private $extgitgraph;
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class Programs
|
||||
class Programs implements IWebsiteModule
|
||||
{
|
||||
const PROG_LANGS = [ 'Java', 'C#', 'Delphi', 'PHP', 'C++' ];
|
||||
|
||||
@@ -67,8 +67,8 @@ class Programs
|
||||
{
|
||||
foreach ($a['extra_images'] as $fn)
|
||||
{
|
||||
$a['extraimages_urls'] []= '/data/images/program_img/' . $fn;
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../data/images/program_img/' . $fn;
|
||||
$a['extraimages_urls'] []= '/data/images/program_img/' . $fn;
|
||||
$a['extraimages_paths'] []= __DIR__ . '/../../data/images/program_img/' . $fn;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -249,7 +249,7 @@ class Programs
|
||||
|
||||
foreach ($prog['extraimages_paths'] as $eipath)
|
||||
{
|
||||
if (!file_exists($eipath)) return ['result'=>'err', 'message' => 'Extra-Image not found ' . $prog['title_short']];
|
||||
if (!file_exists($eipath)) return ['result'=>'err', 'message' => 'Extra-Image not found ' . $prog['name'], 'long' => $eipath];
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class SelfTest
|
||||
class SelfTest implements IWebsiteModule
|
||||
{
|
||||
private const STATUS_ERROR = 2;
|
||||
private const STATUS_WARN = 1;
|
||||
@@ -167,8 +167,15 @@ class SelfTest
|
||||
|
||||
try
|
||||
{
|
||||
//$r = curl_http_request($_SERVER['HTTP_HOST'] . $path);
|
||||
$r = curl_http_request('https://www.mikescher.com/' . $path);
|
||||
if (!Website::inst()->isProd()) return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => '{'.$xname.'} not executed: curl requests in dev mode prohibited',
|
||||
'long' => null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
$r = curl_http_request($_SERVER['HTTP_HOST'] . $path);
|
||||
if ($r['statuscode'] == $status) return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
@@ -191,7 +198,7 @@ class SelfTest
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => "{$xname} failed: " . $e->getMessage(),
|
||||
'long' => formatException($e),
|
||||
'long' => str_max_len($e->getMessage(), 48),
|
||||
'exception' => $e,
|
||||
];
|
||||
}
|
||||
@@ -206,7 +213,58 @@ class SelfTest
|
||||
|
||||
private function addCheckConsistency(string $name, Closure $moduleSupplier)
|
||||
{
|
||||
//TODO
|
||||
$this->methods []=
|
||||
[
|
||||
'name' => $name,
|
||||
'func' => function() use ($name, $moduleSupplier)
|
||||
{
|
||||
$xname = explode('::', $name)[2];
|
||||
|
||||
try
|
||||
{
|
||||
/** @var IWebsiteModule $module */
|
||||
$module = $moduleSupplier();
|
||||
|
||||
$consistency = $module->checkConsistency();
|
||||
|
||||
if ($consistency['result'] === 'err') return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => $consistency['message'],
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
if ($consistency['result'] === 'warn') return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => $consistency['message'],
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
if ($consistency['result'] === 'ok') return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => 'OK',
|
||||
'long' => isset($consistency['long']) ? $consistency['long'] : null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
throw new Exception("Unknown result: " . print_r($consistency, true));
|
||||
}
|
||||
catch (Exception $e)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_ERROR,
|
||||
'message' => str_max_len($e->getMessage(), 48),
|
||||
'long' => formatException($e),
|
||||
'exception' => $e,
|
||||
];
|
||||
}
|
||||
}
|
||||
];
|
||||
}
|
||||
|
||||
private function addMethodPathResponse(string $name, int $statuscode, string $json_expected, string $path)
|
||||
@@ -239,25 +297,53 @@ class SelfTest
|
||||
$rex = '/^' . str_replace('*', '([^:]*)', $filter) . '$/';
|
||||
|
||||
$fullmessage = '';
|
||||
$fullwarnmessage = '';
|
||||
|
||||
$warnings = 0;
|
||||
$count = 0;
|
||||
$lastresult = null;
|
||||
foreach ($this->methods as $method)
|
||||
{
|
||||
if (!preg_match($rex, $method['name'])) continue;
|
||||
|
||||
$r = $method['func']();
|
||||
if ($r['result'] !== self::STATUS_OK) return $r;
|
||||
$fullmessage = $fullmessage . $method['message'] . "\n";
|
||||
$lastresult = $r = $method['func']();
|
||||
if ($r['result'] === self::STATUS_ERROR) return $r;
|
||||
if ($r['result'] === self::STATUS_WARN) { $warnings++; $fullwarnmessage .= $r['message'] . "\n"; }
|
||||
$fullmessage .= $r['message'] . "\n";
|
||||
|
||||
$count++;
|
||||
}
|
||||
|
||||
if ($warnings > 0)
|
||||
{
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => "$warnings/$count methods had warnings",
|
||||
'long' => $fullwarnmessage,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
|
||||
if ($count === 0) return
|
||||
[
|
||||
'result' => self::STATUS_WARN,
|
||||
'message' => "No methods matched filter",
|
||||
'long' => null,
|
||||
'exception' => null,
|
||||
];
|
||||
|
||||
return
|
||||
[
|
||||
'result' => self::STATUS_OK,
|
||||
'message' => "{$count} methods succeeded",
|
||||
'long' => $fullmessage,
|
||||
'message' => "OK",
|
||||
'long' => "$count methods succeeded\n\n" . $fullmessage,
|
||||
'exception' => null,
|
||||
];
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class UpdatesLog
|
||||
class UpdatesLog implements IWebsiteModule
|
||||
{
|
||||
/** @var Website */
|
||||
private $site;
|
||||
@@ -61,4 +61,20 @@ class UpdatesLog
|
||||
[':lt', $limit, PDO::PARAM_INT],
|
||||
]);
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
$warn = null;
|
||||
|
||||
$this->load();
|
||||
|
||||
foreach ($this->staticData as $name => $data)
|
||||
{
|
||||
if (!key_exists('version', $data)) return ['result'=>'err', 'message' => 'Missing value [version]'];
|
||||
if (!key_exists('url', $data)) return ['result'=>'err', 'message' => 'Missing value [url]'];
|
||||
}
|
||||
|
||||
if ($warn != null) return $warn;
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
<?php
|
||||
|
||||
class WebApps
|
||||
class WebApps implements IWebsiteModule
|
||||
{
|
||||
/** @var array */
|
||||
private $staticData;
|
||||
@@ -28,4 +28,22 @@ class WebApps
|
||||
usort($data, function($a, $b) { return strcasecmp($b['date'], $a['date']); });
|
||||
return $data;
|
||||
}
|
||||
|
||||
public function checkConsistency()
|
||||
{
|
||||
$warn = null;
|
||||
|
||||
$this->load();
|
||||
|
||||
$ids = [];
|
||||
|
||||
foreach ($this->staticData as $prog)
|
||||
{
|
||||
if (in_array($prog['id'], $ids)) return ['result'=>'err', 'message' => 'Duplicate id ' . $prog['id']];
|
||||
$ids []= $prog['id'];
|
||||
}
|
||||
|
||||
if ($warn != null) return $warn;
|
||||
return ['result'=>'ok', 'message' => ''];
|
||||
}
|
||||
}
|
||||
@@ -220,6 +220,13 @@ function isHTTPRequest()
|
||||
return (!isset($_SERVER['HTTPS'])) || empty($_SERVER['HTTPS']) || $_SERVER['HTTPS'] == "off";
|
||||
}
|
||||
|
||||
function str_max_len(string $str, int $max)
|
||||
{
|
||||
if (strlen($str) < $max) return $str;
|
||||
|
||||
return substr($str, 0, $max-3)."...";
|
||||
}
|
||||
|
||||
function formatException($e)
|
||||
{
|
||||
if ($e === null) return "NULL";
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
require_once 'ruleengine.php';
|
||||
require_once 'urlroute.php';
|
||||
require_once 'pageframeoptions.php';
|
||||
require_once 'iwebsitemodule.php';
|
||||
require_once 'modules.php';
|
||||
require_once 'fragments.php';
|
||||
|
||||
|
||||
Reference in New Issue
Block a user