1
0

Add check-db to egg and save parents as json-objects

This commit is contained in:
2022-10-20 14:56:27 +02:00
parent 16051928c1
commit 805627be17
12 changed files with 234 additions and 16 deletions

View File

@@ -49,4 +49,12 @@ class MikescherGitGraph implements IWebsiteModule
return ['result'=>'ok', 'message' => ''];
}
/**
* @return string[]
*/
public function checkDatabaseConsistency(): array
{
return $this->extgitgraph->checkDatabase();
}
}

View File

@@ -30,7 +30,8 @@ class SelfTest implements IWebsiteModule
'modules::updateslog' => 'Program Updates (data)',
'modules::webapps' => 'Webapps (data)',
'modules::highscores' => 'Highscores (data)',
'backend::git' => 'Git Repository'
'egg::db-check' => 'ExtendedGitGraph (db-check)',
'backend::git' => 'Git Repository',
];
private $methods = [];
@@ -118,6 +119,8 @@ class SelfTest implements IWebsiteModule
$this->addCheckConsistency("modules::webapps::webapps-check-consistency", function(){ return Website::inst()->modules->WebApps(); });
$this->addCheckConsistency("modules::highscores::highscores-check-consistency", function(){ return Website::inst()->modules->Highscores(); });
$this->addLambdaStatus("egg::db-check::check-db-consistency", function(){ return Website::inst()->modules->ExtendedGitGraph()->checkDatabaseConsistency(); });
$ajaxsecret = Website::inst()->config['ajax_secret'];
$this->addMethodPathResponse( "api::default::base-test-2", 200, '{}', '/api/test');
@@ -362,6 +365,77 @@ class SelfTest implements IWebsiteModule
];
}
private function addLambdaStatus(string $name, Closure $fun)
{
$this->methods []=
[
'name' => $name,
'func' => function() use ($name, $fun)
{
try
{
$result = $fun();
if (empty($result)) return
[
'result' => self::STATUS_OK,
'message' => 'OK',
'long' => 'Okay',
'exception' => null,
];
if (isset($result['result']) && isset($result['message'])) {
if ($result['result'] === 'err') return
[
'result' => self::STATUS_ERROR,
'message' => $result['message'],
'long' => isset($result['long']) ? $result['long'] : null,
'exception' => null,
];
if ($result['result'] === 'warn') return
[
'result' => self::STATUS_WARN,
'message' => $result['message'],
'long' => isset($result['long']) ? $result['long'] : null,
'exception' => null,
];
if ($result['result'] === 'ok') return
[
'result' => self::STATUS_OK,
'message' => 'OK',
'long' => isset($result['long']) ? $result['long'] : null,
'exception' => null,
];
}
if (is_array($result) && is_string($result[0])) {
return
[
'result' => self::STATUS_ERROR,
'message' => count($result) . " errors occured",
'long' => implode("\n", $result),
'exception' => null,
];
}
throw new Exception("Unknown result: " . print_r($result, true));
}
catch (Throwable $e)
{
return
[
'result' => self::STATUS_ERROR,
'message' => str_max_len($e->getMessage(), 48),
'long' => formatException($e),
'exception' => $e,
];
}
}
];
}
private function addMethodPathResponse(string $name, int $status, string $json_expected, string $path)
{
$this->methods []=