-
Notifications
You must be signed in to change notification settings - Fork 1
/
advancedlogger.php
105 lines (92 loc) · 3.53 KB
/
advancedlogger.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<?php
if (!defined('_PS_VERSION_')) {
exit;
}
class AdvancedLogger extends Module
{
public function __construct()
{
$this->name = 'advancedlogger';
$this->tab = 'administration';
$this->version = '1.0.1';
$this->author = 'Novanta';
$this->displayName = ('Advanced Logger');
$this->description = ('This module install a logger to track what appends under the hood');
$this->ps_versions_compliancy = array('min' => '1.7', 'max' => _PS_VERSION_);
$this->bootstrap = true;
parent::__construct();
}
public function isUsingNewTranslationSystem()
{
return true;
}
public function install()
{
return
parent::install() &&
$this->registerHook('actionObjectDeleteBefore') &&
$this->registerHook('actionObjectDeleteAfter') &&
$this->registerHook('actionObjectUpdateBefore') &&
$this->registerHook('actionObjectUpdateAfter') &&
$this->registerHook('actionObjectAddBefore') &&
$this->registerHook('actionObjectAddAfter');
}
public function uninstall()
{
return parent::uninstall();
}
public function hookActionObjectDeleteBefore($params)
{
/** @var ObjectModel */
$object = $params['object'];
if($object && get_class($object) == 'Combination')
{
PrestaShopLogger::addLog(sprintf('Combination deleted for Product %s', $object->id_product) , 2, null, get_class($object), $object->id, false, Context::getContext()->employee->id);
}
else if($object && get_class($object) == 'SpecificPrice')
{
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
$stack = ob_get_clean();
PrestaShopLogger::addLog(sprintf('SpecificPrice deleted: StackTrace: %s', $stack), 2, null, get_class($object), $object->id, false, Context::getContext()->employee->id);
}
}
public function hookActionObjectDeleteAfter($params)
{
// Nothing to do
}
public function hookActionObjectUpdateBefore($params)
{
$object = $params['object'];
if($object && get_class($object) == 'Combination')
{
PrestaShopLogger::addLog(sprintf('Combination updated for Product %s', $object->id_product) , 1, null, get_class($object), $object->id, false, Context::getContext()->employee->id);
}
else if($object && get_class($object) == 'SpecificPrice')
{
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
$stack = ob_get_clean();
PrestaShopLogger::addLog(sprintf('SpecificPrice updated: StackTrace: %s', $stack), 2, null, get_class($object), $object->id, false, Context::getContext()->employee->id);
}
}
public function hookActionObjectUpdateAfter($params)
{
// Nothing to do
}
public function hookActionObjectAddBefore($params)
{
$object = $params['object'];
if($object && get_class($object) == 'SpecificPrice')
{
ob_start();
debug_print_backtrace(DEBUG_BACKTRACE_IGNORE_ARGS, 20);
$stack = ob_get_clean();
PrestaShopLogger::addLog(sprintf('SpecificPrice added: StackTrace: %s', $stack), 2, null, get_class($object), $object->id, false, Context::getContext()->employee->id);
}
}
public function hookActionObjectAddAfter($params)
{
// Nothing to do
}
}