|
1
|
|
|
<?php declare (strict_types=1); |
|
2
|
|
|
/** |
|
3
|
|
|
* @license MIT |
|
4
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
5
|
|
|
* |
|
6
|
|
|
* This file is part of the EmmetBlue project, please read the license document |
|
7
|
|
|
* available in the root level of the project |
|
8
|
|
|
*/ |
|
9
|
|
|
namespace EmmetBlue\Core\Logger; |
|
10
|
|
|
|
|
11
|
|
|
use EmmetBlue\Core\Builder\BuilderFactory as Builder; |
|
12
|
|
|
use EmmetBlue\Core\Factory\DatabaseConnectionFactory as DBConnectionFactory; |
|
13
|
|
|
use EmmetBlue\Core\Builder\QueryBuilder\QueryBuilder as QB; |
|
14
|
|
|
use EmmetBlue\Core\Exception\SQLException; |
|
15
|
|
|
|
|
16
|
|
|
/** |
|
17
|
|
|
* Class DatabaseLog |
|
18
|
|
|
* |
|
19
|
|
|
* @author Samuel Adeshina <[email protected]> |
|
20
|
|
|
* |
|
21
|
|
|
* @since v0.0.1 08/06/2016 14:20 |
|
22
|
|
|
*/ |
|
23
|
|
|
class DatabaseLog implements LogInterface |
|
24
|
|
|
{ |
|
25
|
|
|
public static function logDeprecated(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql) |
|
26
|
|
|
{ |
|
27
|
|
|
$insertBuilder = (new Builder("QueryBuilder", "Insert"))->getBuilder(); |
|
28
|
|
|
try { |
|
29
|
|
|
$insertBuilder |
|
30
|
|
|
->into(' |
|
31
|
|
|
[Logs].[DatabaseLog] |
|
32
|
|
|
( |
|
33
|
|
|
PostTime, |
|
34
|
|
|
DatabaseUserId, |
|
35
|
|
|
Event, |
|
36
|
|
|
ObjectSchema, |
|
37
|
|
|
Object, |
|
38
|
|
|
TSQL |
|
39
|
|
|
) |
|
40
|
|
|
') |
|
41
|
|
|
->values([ |
|
42
|
|
|
'GETDATE()', |
|
43
|
|
|
QB::wrapString($databaseUserId, "'"), |
|
44
|
|
|
QB::wrapString((string)$event, "'"), |
|
45
|
|
|
QB::wrapString($objectSchema, "'"), |
|
46
|
|
|
QB::wrapString($object, "'"), |
|
47
|
|
|
QB::wrapString(str_replace("'", "\"", $tSql), "'") |
|
48
|
|
|
]); |
|
49
|
|
|
|
|
50
|
|
|
DBConnectionFactory::getConnection()->query((string)$insertBuilder); |
|
51
|
|
|
} catch (\PDOException $e) { |
|
52
|
|
|
echo $e->getMessage(); |
|
53
|
|
|
throw new SQLException(sprintf( |
|
54
|
|
|
"Unable to store database log" |
|
55
|
|
|
), 1); |
|
56
|
|
|
} |
|
57
|
|
|
} |
|
58
|
|
|
|
|
59
|
|
|
public static function log(string $databaseUserId, string $event, string $objectSchema, string $object, string $tSql){ |
|
|
|
|
|
|
60
|
|
|
|
|
61
|
|
|
} |
|
62
|
|
|
} |
|
63
|
|
|
|
This check looks from parameters that have been defined for a function or method, but which are not used in the method body.