]> git.andy128k.dev Git - ipf.git/commitdiff
refactor admin log
authorAndrey Kutejko <andy128k@gmail.com>
Tue, 17 Dec 2013 06:31:37 +0000 (08:31 +0200)
committerAndrey Kutejko <andy128k@gmail.com>
Tue, 17 Dec 2013 06:31:37 +0000 (08:31 +0200)
ipf/admin/models.yml
ipf/admin/models/AdminLog.php
ipf/admin/models/_generated/BaseAdminLog.php

index 0e27a3ea3d07c5572db37b07cc97ddb887d9e3da..b98918c633fa3b9cfa24a7e0aa32adeb653f2161 100644 (file)
@@ -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
+
index 04aa978b49cf3d80e4dd5c75a6a5f428ec469b94..1e70e6112647900fba3705099c4e66f013bfbc7d 100644 (file)
@@ -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;
     }
 }
 
index a26051ea14a2386696b25aca3db708ee026963bd..b49ba813a57ea8c39f3a67c3711c52e843a67d2d 100644 (file)
@@ -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');