opensupports/server/controllers/system/get-logs.php

59 lines
1.4 KiB
PHP
Raw Normal View History

<?php
use Respect\Validation\Validator as DataValidator;
2019-01-12 04:38:33 +01:00
use RedBeanPHP\Facade as RedBean;
2017-04-18 02:09:16 +02:00
/**
* @api {post} /system/get-logs Get logs
2019-03-06 16:47:24 +01:00
* @apiVersion 4.4.0
2017-04-18 02:09:16 +02:00
*
* @apiName Get logs
*
* @apiGroup System
2017-04-18 02:09:16 +02:00
*
* @apiDescription This path retrieves the all the logs.
2017-04-18 02:09:16 +02:00
*
* @apiPermission staff1
2017-04-18 02:09:16 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiParam {Number} page The page of logs.
2017-04-18 02:09:16 +02:00
*
2017-04-21 08:09:24 +02:00
* @apiUse NO_PERMISSION
* @apiUse INVALID_PAGE
2017-04-18 02:09:16 +02:00
*
2017-04-22 03:33:17 +02:00
* @apiSuccess {[Log](#api-Data_Structures-ObjectLog)[]} data Array of last logs
2017-04-18 02:09:16 +02:00
*
*/
class GetLogsController extends Controller {
const PATH = '/get-logs';
const METHOD = 'POST';
public function validations() {
return [
'permission' => 'staff_1',
'requestData' => [
'page' => [
'validation' => DataValidator::numeric(),
'error' => ERRORS::INVALID_PAGE
]
]
];
}
public function handler() {
$this->deleteLastLogs();
$page = Controller::request('page');
2017-01-11 04:21:27 +01:00
$logList = Log::find('ORDER BY id desc LIMIT ? OFFSET ?', [10, 10*($page-1)]);
Response::respondSuccess($logList->toArray());
}
public function deleteLastLogs() {
$removeOlderThanDays = 31;
$oldDate = floor(Date::getPreviousDate($removeOlderThanDays) / 10000);
2018-11-16 23:34:07 +01:00
try {
RedBean::exec("DELETE FROM log WHERE date < $oldDate");
} catch(Exception $e) {}
}
}