Skip to content
Snippets Groups Projects
Commit 7987f2aa authored by Anton Bagliy's avatar Anton Bagliy
Browse files

ADD: 1c sync logs table, tab in updates #382

parent 56f7d439
Branches
No related merge requests found
CREATE SEQUENCE seq_logs_sync_1c
START WITH 1
INCREMENT BY 1
NO MINVALUE
NO MAXVALUE
CACHE 1;
CREATE TABLE logs_sync_1c (
id integer DEFAULT nextval('seq_logs_sync_1c'::regclass) NOT NULL,
date timestamp(0) without time zone DEFAULT now() NOT NULL
);
ALTER TABLE ONLY logs_sync_1c
ADD CONSTRAINT logs_sync_pk PRIMARY KEY (id);
CREATE OR REPLACE FUNCTION public.logs_sync_1c()
RETURNS integer
LANGUAGE plpgsql
AS $function$
declare vID int default -1;
vRowUpd int;
begin
INSERT INTO logs_sync_1c DEFAULT VALUES returning id into vID;
get diagnostics vRowUpd = ROW_COUNT;
RETURN vRowUpd - 1;
end
$function$;
CREATE OR REPLACE FUNCTION public.getAllSyncDates()
RETURNS TABLE("Date" timestamp)
LANGUAGE plpgsql
AS $function$
BEGIN
return query
SELECT logs_sync_1c."date" as "Date"
FROM logs_sync_1c
ORDER BY logs_sync_1c."date" DESC;
END
$function$;
\ No newline at end of file
<?php
class Controller_Api_V0_SyncLogs extends Controller_Handler_Api
{
/**
* @api {get} api/v0/LogSync Log synchronization with 1C
* @apiName Log synchronization with 1C
* @apiGroup Sync
* @apiVersion 0.1.0
* @apiParam {String} token Api key
* @apiDescription This method logs 1C synchronization timestamp
* @apiExample {curl} Example usage:
* curl -i http://grade/~dev_rating/api/v0/SyncLogs?token=osw839hfgh9a23hgfh92hasff232f2oasf
* @apiSuccessExample {json} Success-Response:
* HTTP/1.1 200 OK
* {
* "response": {
* }
* }
*
*/
public function action_get_index()
{
try {
$response = [];
Model_System::Log1CSync();
return $response;
} catch (Exception $e) {
$this->badRequestError($e->getMessage());
}
return null;
}
}
......@@ -25,6 +25,7 @@ class Controller_Authentication extends Controller
'Blocks' => [
'News' => Model_System::getChangeLog('news.md'),
'Updates' => Model_System::getChangeLog('updates.md'),
'Syncs' => Model_System::getSyncLog(),
]
]);
$this->response->body($this->twig);
......
......@@ -39,6 +39,28 @@ class Model_System extends Model
return $log;
}
public static function getSyncLog() {
$query = 'SELECT * FROM getAllSyncDates()';
$result = DB::query(Database::SELECT, $query)
->execute();
$log = [];
foreach ($result as $row) {
$log[] = [
'date' => substr($row["Date"], 0, 10),
'text' => substr($row["Date"], strpos($row["Date"], ' '), 9),
];
}
return $log;
}
public static function Log1CSync() {
$query = 'SELECT * FROM logs_sync_1c() AS "Num"';
$result = DB::query(Database::SELECT, $query)
->execute()->get("Num");
return $result;
}
/**
* Clean comments of json content and decode it with json_decode().
......
......@@ -11,6 +11,17 @@ Route::set('apiv0:final-report', 'api/v0/final-report')
'controller' => 'FinalReport',
]);
Route::set('apiv0:SyncLogs', 'api/v0/sync-logs')
->filter(function($route, $params, $request) {
$params['action'] = strtolower($request->method()) . '_' . $params['action'];
return $params;
})
->defaults([
'action' => 'index',
'directory' => 'Api/V0',
'controller' => 'SyncLogs',
]);
Route::set('apiv0:student', 'api/v0/student')
->filter(function($route, $params, $request) {
$params['action'] = strtolower($request->method()) . '_' . $params['action'];
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment