From: Andrey Kutejko Date: Sun, 24 Aug 2014 17:50:53 +0000 (+0300) Subject: rework admin log X-Git-Tag: 0.6~166 X-Git-Url: https://git.andy128k.dev/?a=commitdiff_plain;h=f3f3a0d3fe69ef80ce23dad37c531f487a26c5ec;p=ipf.git rework admin log --- diff --git a/ipf/admin/log.php b/ipf/admin/log.php new file mode 100644 index 0000000..d6c487b --- /dev/null +++ b/ipf/admin/log.php @@ -0,0 +1,26 @@ + $who->username, + 'user_id' => $who->id, + 'action' => $action, + 'object_class' => $class, + 'object_repr' => $repr, + 'object_url' => $url, + ); + \PFF\Container::databaseQuery() + ->insertInto('admin_log', $data) + ->execute(); + } + + public static function logObject($component, $action, $object, $object_id=null) + { + $url = $object_id ? IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($component->app->slug(), $component->slug(), $object_id)) : ''; + self::log($component->request->user, $action, (string)$object, $component->verbose_name(), $url); + } +} + diff --git a/ipf/admin/migrations/20140103000000_create_admin_log.php b/ipf/admin/migrations/20140103000000_create_admin_log.php new file mode 100644 index 0000000..015a9f5 --- /dev/null +++ b/ipf/admin/migrations/20140103000000_create_admin_log.php @@ -0,0 +1,21 @@ +connection->exec('CREATE TABLE admin_log (' . + 'id BIGINT AUTO_INCREMENT,' . + 'username VARCHAR(32),' . + 'user_id BIGINT,' . + 'action VARCHAR(32) NOT NULL,' . + 'object_class VARCHAR(200),' . + 'object_repr VARCHAR(200),' . + 'object_url VARCHAR(200),' . + 'created_at TIMESTAMP,' . + 'INDEX idx_created_at_idx (created_at),' . + 'PRIMARY KEY(id)) '. + 'DEFAULT CHARACTER SET utf8 COLLATE utf8_unicode_ci ENGINE = INNODB'); + } +} + diff --git a/ipf/admin/model.php b/ipf/admin/model.php index 9a9fba3..679ecad 100644 --- a/ipf/admin/model.php +++ b/ipf/admin/model.php @@ -593,7 +593,7 @@ abstract class IPF_Admin_Component if ($form->isValid()) { list($id, $object) = $this->saveObject($form, null); - AdminLog::logAction($request->user, AdminLog::ADDITION, (string)$object, IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($this->app->slug(), $this->slug(), $id))); + IPF_Admin_Log::logObject($this, 'add', $object, $id); $url = @$request->POST['ipf_referrer']; if (!$url) @@ -630,7 +630,7 @@ abstract class IPF_Admin_Component throw new IPF_HTTP_Error404; if ($request->method == 'POST') { - AdminLog::logAction($request->user, AdminLog::DELETION, (string)$object); + IPF_Admin_Log::logObject($this, 'delete', $object); $this->deleteObject($object); @@ -664,7 +664,7 @@ abstract class IPF_Admin_Component if ($form->isValid()) { list($id, $object) = $this->saveObject($form, $object); - AdminLog::logAction($request->user, AdminLog::CHANGE, (string)$object, IPF_HTTP_URL::urlForView('IPF_Admin_Views_EditItem', array($this->app->slug(), $this->slug(), $id))); + IPF_Admin_Log::logObject($this, 'change', $object, $id); $url = @$request->POST['ipf_referrer']; if (!$url) diff --git a/ipf/admin/models.yml b/ipf/admin/models.yml deleted file mode 100644 index b98918c..0000000 --- a/ipf/admin/models.yml +++ /dev/null @@ -1,25 +0,0 @@ -AdminLog: - tableName: admin_log - actAs: - Timestampable: - updated: - disabled: true - columns: - username: string(32) - user_id: integer - object_id: integer - object_class: string(200) - object_repr: string(200) - object_url: string(200) - action_flag: integer - change_message: string(200) - - indexes: - idx_created_at: - fields: created_at - - options: - type: INNODB - collate: utf8_unicode_ci - charset: utf8 - diff --git a/ipf/admin/models/AdminLog.php b/ipf/admin/models/AdminLog.php deleted file mode 100644 index 3f8fa00..0000000 --- a/ipf/admin/models/AdminLog.php +++ /dev/null @@ -1,35 +0,0 @@ -username = $who->username; - $log->user_id = $who->id; - $log->object_repr = $repr; - $log->object_url = $url; - $log->action_flag = $action; - $log->save(); - } - - public function is_addition() - { - return $this->action_flag == AdminLog::ADDITION; - } - - public function is_change() - { - return $this->action_flag == AdminLog::CHANGE; - } - - public function is_deletion() - { - return $this->action_flag == AdminLog::DELETION; - } -} - diff --git a/ipf/admin/models/_generated/BaseAdminLog.php b/ipf/admin/models/_generated/BaseAdminLog.php deleted file mode 100644 index b49ba81..0000000 --- a/ipf/admin/models/_generated/BaseAdminLog.php +++ /dev/null @@ -1,43 +0,0 @@ -setTableName('admin_log'); - $table->setColumn('username', 'string', 32, array('type' => 'string', 'length' => '32')); - $table->setColumn('user_id', 'integer', null, array('type' => 'integer')); - $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_created_at', array('fields' => 'created_at')); - $table->setOption('type', 'INNODB'); - $table->setOption('collate', 'utf8_unicode_ci'); - $table->setOption('charset', 'utf8'); - - } - - public static function setUp(IPF_ORM_Table $table) - { - $table->addTemplate(new IPF_ORM_Template_Timestampable(array('updated' => array('disabled' => true)))); - } - - public static function table() - { - return IPF_ORM::getTable('AdminLog'); - } - - public static function query($alias='') - { - return IPF_ORM::getTable('AdminLog')->createQuery($alias); - } -} \ No newline at end of file diff --git a/ipf/admin/templates/admin/index.html b/ipf/admin/templates/admin/index.html index 9236fe3..34f7272 100644 --- a/ipf/admin/templates/admin/index.html +++ b/ipf/admin/templates/admin/index.html @@ -34,7 +34,14 @@

{trans 'My Actions'}

diff --git a/ipf/admin/views.php b/ipf/admin/views.php index 8a42707..e65d44b 100644 --- a/ipf/admin/views.php +++ b/ipf/admin/views.php @@ -25,12 +25,12 @@ function IPF_Admin_Views_Index($request, $match) } } - $admin_log = IPF_ORM_Query::create() - ->select("*") - ->from('AdminLog') - ->orderby('created_at desc') + $admin_log = \PFF\Container::databaseQuery() + ->from('admin_log') + ->orderBy('created_at DESC') ->limit(10) - ->execute(); + ->asObject(true) + ->fetchAll(); $context = array( 'page_title' => __('Site Administration'),