[+] BO: Addition, deletion and edition are now logged
This commit is contained in:
+12
-1
@@ -43,6 +43,9 @@ class LoggerCore extends ObjectModel
|
||||
|
||||
/** @var integer Object ID */
|
||||
public $object_id;
|
||||
|
||||
/** @var integer Object ID */
|
||||
public $id_employee;
|
||||
|
||||
/** @var string Object creation date */
|
||||
public $date_add;
|
||||
@@ -61,6 +64,7 @@ class LoggerCore extends ObjectModel
|
||||
'error_code' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'message' => array('type' => self::TYPE_STRING, 'validate' => 'isMessage', 'required' => true),
|
||||
'object_id' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'id_employee' => array('type' => self::TYPE_INT, 'validate' => 'isUnsignedInt'),
|
||||
'object_type' => array('type' => self::TYPE_STRING, 'validate' => 'isName'),
|
||||
'date_add' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
'date_upd' => array('type' => self::TYPE_DATE, 'validate' => 'isDate'),
|
||||
@@ -98,7 +102,7 @@ class LoggerCore extends ObjectModel
|
||||
* @param boolean $allow_duplicate if set to true, can log several time the same information (not recommended)
|
||||
* @return boolean true if succeed
|
||||
*/
|
||||
public static function addLog($message, $severity = 1, $error_code = null, $object_type = null, $object_id = null, $allow_duplicate = false)
|
||||
public static function addLog($message, $severity = 1, $error_code = null, $object_type = null, $object_id = null, $allow_duplicate = false, $id_employee = null)
|
||||
{
|
||||
$log = new Logger();
|
||||
$log->severity = intval($severity);
|
||||
@@ -106,6 +110,13 @@ class LoggerCore extends ObjectModel
|
||||
$log->message = pSQL($message);
|
||||
$log->date_add = date('Y-m-d H:i:s');
|
||||
$log->date_upd = date('Y-m-d H:i:s');
|
||||
|
||||
if ($id_employee === null && isset(Context::getContext()->employee) && Validate::isLoadedObject(Context::getContext()->employee))
|
||||
$id_employee = Context::getContext()->employee->id;
|
||||
|
||||
if ($id_employee !== null)
|
||||
$log->id_employee = (int)$id_employee;
|
||||
|
||||
if (!empty($object_type) && !empty($object_id))
|
||||
{
|
||||
$log->object_type = pSQL($object_type);
|
||||
|
||||
@@ -647,12 +647,14 @@ class AdminControllerCore extends Controller
|
||||
$this->errors[] = Tools::displayError('Unable to delete associated images.');
|
||||
|
||||
$object->deleted = 1;
|
||||
if ($object->update())
|
||||
if ($res = $object->update())
|
||||
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token;
|
||||
}
|
||||
elseif ($object->delete())
|
||||
elseif ($res = $object->delete())
|
||||
$this->redirect_after = self::$currentIndex.'&conf=1&token='.$this->token;
|
||||
$this->errors[] = Tools::displayError('An error occurred during deletion.');
|
||||
if ($res)
|
||||
Logger::addLog(sprintf($this->l('%s deletion'), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
|
||||
}
|
||||
}
|
||||
else
|
||||
@@ -701,6 +703,7 @@ class AdminControllerCore extends Controller
|
||||
/* voluntary do affectation here */
|
||||
elseif (($_POST[$this->identifier] = $this->object->id) && $this->postImage($this->object->id) && !count($this->errors) && $this->_redirect)
|
||||
{
|
||||
Logger::addLog(sprintf($this->l('%s addition'), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
|
||||
$parent_id = (int)Tools::getValue('id_parent', 1);
|
||||
$this->afterAdd($this->object);
|
||||
$this->updateAssoShop($this->object->id);
|
||||
@@ -735,7 +738,6 @@ class AdminControllerCore extends Controller
|
||||
{
|
||||
/* Checking fields validity */
|
||||
$this->validateRules();
|
||||
|
||||
if (empty($this->errors))
|
||||
{
|
||||
$id = (int)Tools::getValue($this->identifier);
|
||||
@@ -801,6 +803,7 @@ class AdminControllerCore extends Controller
|
||||
if (empty($this->redirect_after))
|
||||
$this->redirect_after = self::$currentIndex.($parent_id ? '&'.$this->identifier.'='.$object->id : '').'&conf=4&token='.$this->token;
|
||||
}
|
||||
Logger::addLog(sprintf($this->l('%s edition'), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
|
||||
}
|
||||
else
|
||||
$this->errors[] = Tools::displayError('An error occurred while updating an object.').
|
||||
|
||||
@@ -38,6 +38,7 @@ class AdminLogsControllerCore extends AdminController
|
||||
|
||||
$this->fields_list = array(
|
||||
'id_log' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25),
|
||||
'employee' => array('title' => $this->l('Employee'), 'align' => 'center', 'width' => 100),
|
||||
'severity' => array('title' => $this->l('Severity (1-4)'), 'align' => 'center', 'width' => 50),
|
||||
'message' => array('title' => $this->l('Message')),
|
||||
'object_type' => array('title' => $this->l('Object type'), 'width' => 75),
|
||||
@@ -62,6 +63,8 @@ class AdminLogsControllerCore extends AdminController
|
||||
)
|
||||
);
|
||||
$this->list_no_link = true;
|
||||
$this->_select .= 'CONCAT(LEFT(e.firstname, 1), \'. \', e.lastname) employee';
|
||||
$this->_join .= ' LEFT JOIN '._DB_PREFIX_.'employee e ON (a.id_employee = e.id_employee)';
|
||||
parent::__construct();
|
||||
}
|
||||
|
||||
|
||||
@@ -1714,6 +1714,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
if ($this->object->add())
|
||||
{
|
||||
Logger::addLog(sprintf($this->l('%s addition'), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
|
||||
$this->addCarriers();
|
||||
$this->updateAccessories($this->object);
|
||||
$this->updatePackItems($this->object);
|
||||
@@ -1855,6 +1856,7 @@ class AdminProductsControllerCore extends AdminController
|
||||
|
||||
if ($object->update())
|
||||
{
|
||||
Logger::addLog(sprintf($this->l('%s edition'), $this->className), 1, null, $this->className, (int)$this->object->id, true, (int)$this->context->employee->id);
|
||||
if (in_array($this->context->shop->getContext(), array(Shop::CONTEXT_SHOP, Shop::CONTEXT_ALL)))
|
||||
{
|
||||
if ($this->isTabSubmitted('Shipping'))
|
||||
|
||||
@@ -1924,6 +1924,7 @@ CREATE TABLE `PREFIX_log` (
|
||||
`message` text NOT NULL,
|
||||
`object_type` varchar(32) DEFAULT NULL,
|
||||
`object_id` int(10) unsigned DEFAULT NULL,
|
||||
`id_employee` int(10) unsigned DEFAULT NULL,
|
||||
`date_add` datetime NOT NULL,
|
||||
`date_upd` datetime NOT NULL,
|
||||
PRIMARY KEY (`id_log`)
|
||||
|
||||
@@ -18,4 +18,6 @@ CHANGE `module_name` `module_name` VARCHAR(64) NULL DEFAULT NULL;
|
||||
/* PHP:add_module_to_hook(blockmyaccount, actionModuleRegisterHookAfter); */;
|
||||
/* PHP:add_module_to_hook(blockmyaccountfooter, actionModuleRegisterHookAfter); */;
|
||||
/* PHP:add_module_to_hook(blockmyaccount, actionModuleUnRegisterHookAfter); */;
|
||||
/* PHP:add_module_to_hook(blockmyaccountfooter, actionModuleUnRegisterHookAfter); */;
|
||||
/* PHP:add_module_to_hook(blockmyaccountfooter, actionModuleUnRegisterHookAfter); */;
|
||||
|
||||
ALTER TABLE `PREFIX_log` ADD `id_employee` INT(10) UNSIGNED NULL AFTER `object_id`;
|
||||
Reference in New Issue
Block a user