--- /dev/null
+<?php
+
+class IPF_Admin_Log
+{
+ public static function log($who, $action, $repr, $class, $url=null)
+ {
+ $data = array(
+ 'username' => $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);
+ }
+}
+
--- /dev/null
+<?php
+
+class Migration_20140103000000 extends \PFF\Migrations\Migration
+{
+ function migrate()
+ {
+ $this->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');
+ }
+}
+
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)
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);
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)
+++ /dev/null
-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
-
+++ /dev/null
-<?php
-
-class AdminLog extends BaseAdminLog
-{
- const ADDITION = 1;
- const CHANGE = 2;
- const DELETION = 3;
-
- public static function logAction($who, $action, $repr, $url=null)
- {
- $log = new AdminLog;
- $log->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;
- }
-}
-
+++ /dev/null
-<?php
-
-/**
- * This class has been auto-generated by the IPF_ORM Framework.
- * Changes to this file may cause incorrect behavior
- * and will be lost if the code is regenerated.
- */
-
-abstract class BaseAdminLog extends IPF_ORM_Record
-{
- public static function setTableDefinition(IPF_ORM_Table $table)
- {
- $table->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
<h3>{trans 'My Actions'}</h3>
<ul class="actionlist">
{foreach $admin_log as $log}
- <li class="{if $log.is_addition()}addlink{/if}{if $log.is_change()}changelink{/if}{if $log.is_deletion()}deletelink{/if}">{if !$log.is_deletion()}<a href="{$log.object_url}">{/if}{$log.object_repr}{if !$log.is_deletion()}</a>{/if}<br /><span class="mini quiet">{$log.object_class} at {$log.created_at|date} by {$log.username}</span></li>
+ <li class="{$log.action}link">
+ {if $log.object_url}
+ <a href="{$log.object_url}">{$log.object_repr}</a>
+ {else}
+ {$log.object_repr}
+ {/if}
+ <br><span class="mini quiet">{$log.object_class} at {$log.created_at|date} by {$log.username}</span>
+ </li>
{/foreach}
</ul>
</div>
}
}
- $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'),