From 8b3bd668c529a24d1c37f32882673a8374e7b4b1 Mon Sep 17 00:00:00 2001 From: Andrey Kutejko Date: Tue, 17 Dec 2013 08:31:37 +0200 Subject: [PATCH] refactor admin log --- ipf/admin/models.yml | 8 +--- ipf/admin/models/AdminLog.php | 46 ++++++++++---------- ipf/admin/models/_generated/BaseAdminLog.php | 4 +- 3 files changed, 26 insertions(+), 32 deletions(-) diff --git a/ipf/admin/models.yml b/ipf/admin/models.yml index 0e27a3e..b98918c 100644 --- a/ipf/admin/models.yml +++ b/ipf/admin/models.yml @@ -10,20 +10,16 @@ AdminLog: object_id: integer object_class: string(200) object_repr: string(200) + object_url: string(200) action_flag: integer change_message: string(200) indexes: - idx_object_id: - fields: object_id - idx_object_class: - fields: object_class idx_created_at: fields: created_at - idx_action_flag: - fields: action_flag options: type: INNODB collate: utf8_unicode_ci charset: utf8 + diff --git a/ipf/admin/models/AdminLog.php b/ipf/admin/models/AdminLog.php index 04aa978..1e70e61 100644 --- a/ipf/admin/models/AdminLog.php +++ b/ipf/admin/models/AdminLog.php @@ -6,43 +6,43 @@ class AdminLog extends BaseAdminLog const CHANGE = 2; const DELETION = 3; - public static function logAction($request, $object, $action_flag, $message='') + public static function logAction($request, $object, $action_flag, $object_url=null, $message='') { - $log = new AdminLog(); - $log->username = $request->user->username; - $log->user_id = $request->user->id; - $log->object_id = (int)$object[$object->getTable()->getIdentifier()]; - $log->object_class = get_class($object); - $log->object_repr = (string)$object; - $log->action_flag = $action_flag; - $log->change_message = $message; + $log = new AdminLog; + $log->username = $request->user->username; + $log->user_id = $request->user->id; + + $log->object_id = (int)$object[$object->getTable()->getIdentifier()]; + $log->object_class = get_class($object); + $log->object_repr = (string)$object; + + if (!$object_url) { + $app = IPF_Utils::appByModel($log->object_class); + if ($app) + $object_url = IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($app->getSlug(), strtolower($log->object_class), $log->object_id)); + } + + $log->object_url = $object_url; + + $log->action_flag = $action_flag; + $log->change_message = $message; + $log->save(); } public function is_addition() { - if ($this->action_flag==AdminLog::ADDITION) - return true; - return false; + return $this->action_flag == AdminLog::ADDITION; } public function is_change() { - if ($this->action_flag==AdminLog::CHANGE) - return true; - return false; + return $this->action_flag == AdminLog::CHANGE; } public function is_deletion() { - if ($this->action_flag==AdminLog::DELETION) - return true; - return false; - } - - public function GetAdminUrl() - { - return IPF_HTTP_URL::urlForView('IPF_Admin_Views_Index').IPF_Utils::appLabelByModel($this->object_class).'/'.strtolower($this->object_class).'/'.$this->object_id.'/'; + return $this->action_flag == AdminLog::DELETION; } } diff --git a/ipf/admin/models/_generated/BaseAdminLog.php b/ipf/admin/models/_generated/BaseAdminLog.php index a26051e..b49ba81 100644 --- a/ipf/admin/models/_generated/BaseAdminLog.php +++ b/ipf/admin/models/_generated/BaseAdminLog.php @@ -16,12 +16,10 @@ abstract class BaseAdminLog extends IPF_ORM_Record $table->setColumn('object_id', 'integer', null, array('type' => 'integer')); $table->setColumn('object_class', 'string', 200, array('type' => 'string', 'length' => '200')); $table->setColumn('object_repr', 'string', 200, array('type' => 'string', 'length' => '200')); + $table->setColumn('object_url', 'string', 200, array('type' => 'string', 'length' => '200')); $table->setColumn('action_flag', 'integer', null, array('type' => 'integer')); $table->setColumn('change_message', 'string', 200, array('type' => 'string', 'length' => '200')); - $table->addIndex('idx_object_id', array('fields' => 'object_id')); - $table->addIndex('idx_object_class', array('fields' => 'object_class')); $table->addIndex('idx_created_at', array('fields' => 'created_at')); - $table->addIndex('idx_action_flag', array('fields' => 'action_flag')); $table->setOption('type', 'INNODB'); $table->setOption('collate', 'utf8_unicode_ci'); $table->setOption('charset', 'utf8'); -- 2.49.0