2018-09-24 13:53:18 +02:00
|
|
|
<?php
|
|
|
|
|
|
|
|
namespace Grocy\Controllers;
|
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
use Psr\Http\Message\ResponseInterface as Response;
|
|
|
|
use Psr\Http\Message\ServerRequestInterface as Request;
|
|
|
|
|
2018-09-24 13:53:18 +02:00
|
|
|
class SystemApiController extends BaseApiController
|
|
|
|
{
|
2023-05-13 14:43:51 +02:00
|
|
|
public function GetConfig(Request $request, Response $response, array $args)
|
2020-04-13 10:35:20 +02:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$constants = get_defined_constants();
|
|
|
|
|
|
|
|
// Some GROCY_* constants are not really config settings and therefore should not be exposed
|
2020-09-01 21:29:47 +02:00
|
|
|
unset($constants['GROCY_AUTHENTICATED'], $constants['GROCY_DATAPATH'], $constants['GROCY_IS_EMBEDDED_INSTALL'], $constants['GROCY_USER_ID']);
|
2020-04-13 10:35:20 +02:00
|
|
|
|
2020-08-31 20:40:31 +02:00
|
|
|
$returnArray = [];
|
|
|
|
|
2020-04-13 10:35:20 +02:00
|
|
|
foreach ($constants as $constant => $value)
|
|
|
|
{
|
|
|
|
if (substr($constant, 0, 6) === 'GROCY_')
|
|
|
|
{
|
|
|
|
$returnArray[substr($constant, 6)] = $value;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->ApiResponse($response, $returnArray);
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
|
|
|
}
|
2020-08-31 20:40:31 +02:00
|
|
|
}
|
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
public function GetDbChangedTime(Request $request, Response $response, array $args)
|
2020-08-31 20:40:31 +02:00
|
|
|
{
|
|
|
|
return $this->ApiResponse($response, [
|
|
|
|
'changed_time' => $this->getDatabaseService()->GetDbChangedTime()
|
|
|
|
]);
|
|
|
|
}
|
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
public function GetSystemInfo(Request $request, Response $response, array $args)
|
2020-08-31 20:40:31 +02:00
|
|
|
{
|
|
|
|
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemInfo());
|
2020-04-13 10:35:20 +02:00
|
|
|
}
|
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
public function GetSystemTime(Request $request, Response $response, array $args)
|
2020-12-28 19:39:24 +01:00
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
|
|
|
$offset = 0;
|
|
|
|
$params = $request->getQueryParams();
|
|
|
|
if (isset($params['offset']))
|
|
|
|
{
|
2020-12-28 22:14:59 +01:00
|
|
|
if (filter_var($params['offset'], FILTER_VALIDATE_INT) === false)
|
2020-12-28 19:39:24 +01:00
|
|
|
{
|
|
|
|
throw new \Exception('Query parameter "offset" is not a valid integer');
|
|
|
|
}
|
|
|
|
|
|
|
|
$offset = $params['offset'];
|
|
|
|
}
|
|
|
|
|
|
|
|
return $this->ApiResponse($response, $this->getApplicationService()->GetSystemTime($offset));
|
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
public function LogMissingLocalization(Request $request, Response $response, array $args)
|
2018-09-30 13:02:07 +02:00
|
|
|
{
|
|
|
|
if (GROCY_MODE === 'dev')
|
|
|
|
{
|
|
|
|
try
|
|
|
|
{
|
2020-10-14 22:49:29 +02:00
|
|
|
$requestBody = $this->GetParsedAndFilteredRequestBody($request);
|
2018-09-30 13:02:07 +02:00
|
|
|
|
2020-03-01 23:47:47 +07:00
|
|
|
$this->getLocalizationService()->CheckAndAddMissingTranslationToPot($requestBody['text']);
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->EmptyApiResponse($response);
|
2018-09-30 13:02:07 +02:00
|
|
|
}
|
|
|
|
catch (\Exception $ex)
|
|
|
|
{
|
2019-01-19 14:51:51 +01:00
|
|
|
return $this->GenericErrorResponse($response, $ex->getMessage());
|
2018-09-30 13:02:07 +02:00
|
|
|
}
|
2020-03-01 23:47:47 +07:00
|
|
|
}
|
2018-09-30 13:02:07 +02:00
|
|
|
}
|
2019-02-09 13:41:40 +01:00
|
|
|
|
2023-05-13 14:43:51 +02:00
|
|
|
public function GetLocalizationStrings(Request $request, Response $response, array $args)
|
2021-06-29 20:24:02 +02:00
|
|
|
{
|
|
|
|
return $this->ApiResponse($response, json_decode($this->getLocalizationService()->GetPoAsJsonString()), true);
|
|
|
|
}
|
2018-09-24 13:53:18 +02:00
|
|
|
}
|