Hi,
I would like to know if i can have a ignore list in the Model so that AuditTrail does not log the fields in the ignore list in that particular model?
Hi,
I would like to know if i can have a ignore list in the Model so that AuditTrail does not log the fields in the ignore list in that particular model?
I have actually added the functionality for ignore and allowed lists within the behaviour.
Here is the Github for it: https://github.com/Sammaye/audittrail
To the author feel free to patch with this Git if it works for you and everything.
As an additional:
It will not write rows on update when both old and new values are null
It will not write rows on create when new values are null.
I have the same problem, can you share how to solve this?
Thank you very much!!
For those getting SQL syntax errors about " near 'NOT NULL" and the index on TEXT fields not having a key length, the following change appears to allow the migration to complete successfully, at least on MySQL 5.0.96 64-bit SLES:
'model' => 'string NOT NULL',
'field' => 'string NOT NULL',
...
$this->createIndex( 'idx_audit_trail_old_value', 'tbl_audit_trail', 'old_value(900)');
$this->createIndex( 'idx_audit_trail_new_value', 'tbl_audit_trail', 'new_value(900)');
Yes , the migration failed with mysql exception ,
> create index idx_audit_trail_old_value on tbl_audit_trail (old_value) …exception ‘CDbException’ with message ‘CDbCommand failed to execute the SQL statement: SQLSTATE[42000]: Syntax error or access violation: 1170 BLOB/TEXT column ‘old_value’ used in key specification without a key length. The SQL statement executed was: CREATE INDEX idx_audit_trail_old_value
ON tbl_audit_trail
(old_value
)’ in /usr/share/php/yii-1.1.12.b600af/framework/db/CDbCommand.php:354
Stack trace:
and removed the two indices
hi,
i am facing the same issue.
if i disable the url manager i can access to http://localhost/workspace2/yii/osa/index.php?r=auditTrail/admin
but after i enable the url manager i couldn’t access the page.
url =http://localhost/workspace2/yii/osa/auditTrail/admin
errors
CHttpException
You are not authorized to perform this action. (C:\xampp\htdocs\workspace2\yii\framework\web\auth\CAccessControlFilter.php:179)
#0 C:\xampp\htdocs\workspace2\yii\framework\web\auth\CAccessControlFilter.php(142): CAccessControlFilter->accessDenied(Object(CWebUser), 'You are not aut...')
#1 C:\xampp\htdocs\workspace2\yii\framework\web\filters\CFilter.php(38): CAccessControlFilter->preFilter(Object(CFilterChain))
#2 C:\xampp\htdocs\workspace2\yii\framework\web\CController.php(1145): CFilter->filter(Object(CFilterChain))
#3 C:\xampp\htdocs\workspace2\yii\framework\web\filters\CInlineFilter.php(58): CController->filterAccessControl(Object(CFilterChain))
#4 C:\xampp\htdocs\workspace2\yii\framework\web\filters\CFilterChain.php(130): CInlineFilter->filter(Object(CFilterChain))
#5 C:\xampp\htdocs\workspace2\yii\framework\web\CController.php(291): CFilterChain->run()
#6 C:\xampp\htdocs\workspace2\yii\framework\web\CController.php(265): CController->runActionWithFilters(Object(CInlineAction), Array)
#7 C:\xampp\htdocs\workspace2\yii\framework\web\CWebApplication.php(282): CController->run('error')
#8 C:\xampp\htdocs\workspace2\yii\framework\base\CErrorHandler.php(331): CWebApplication->runController('site/error')
#9 C:\xampp\htdocs\workspace2\yii\framework\base\CErrorHandler.php(204): CErrorHandler->render('error', Array)
#10 C:\xampp\htdocs\workspace2\yii\framework\base\CErrorHandler.php(129): CErrorHandler->handleException(Object(CHttpException))
#11 C:\xampp\htdocs\workspace2\yii\framework\base\CApplication.php(720): CErrorHandler->handle(Object(CExceptionEvent))
#12 [internal function]: CApplication->handleException(Object(CHttpException))
#13 {main}
main.config
<?php
// uncomment the following to define a path alias
// Yii::setPathOfAlias('local','path/to/local-folder');
// This is the main Web application configuration. Any writable
// CWebApplication properties can be configured here.
Yii::setPathOfAlias('bootstrap', dirname(__FILE__).'/../extensions/bootstrap');
return array(
'timeZone' => 'Asia/Kuala_Lumpur',
'basePath'=>dirname(__FILE__).DIRECTORY_SEPARATOR.'..',
'name'=>'One Stop Agency',
//main landing page
'defaultController'=> 'site/login',
// preloading 'log' component
'preload'=>array('log'),
// autoloading model and component classes
'import'=>array(
'application.models.*',
'application.components.*',
'ext.yii-mail.YiiMailMessage',//email sender
'ext.tcpdf.*',//pdf converter
'application.modules.auditTrail.models.AuditTrail',
'application.modules.auditTrail.AuditTrailModule',
),
//Theme style
//'theme'=>'abound',
'theme'=>'shadow_dancer',
'modules'=>array(
'auditTrail'=>array(
'userClass' => 'User', // the class name for the user object
'userIdColumn' => 'id', // the column name of the primary key for the user
'userNameColumn' => 'username', // the column name of the primary key for the user
),
// uncomment the following to enable the Gii tool
'gii'=>array(
'class'=>'system.gii.GiiModule',
'password'=>'osa',
// If removed, Gii defaults to localhost only. Edit carefully to taste.
'ipFilters'=>array('127.0.0.1','::1'),
//bootstrap theme yii generator
'generatorPaths'=>array(
'bootstrap.gii',
),
),
),
// application components
'components'=>array(
//'enableParamLogging' => true,
//copy from here
'widgetFactory'=>array(
'widgets'=>array(
'CGridView'=>array(
'htmlOptions'=>array('cellspacing'=>'0','cellpadding'=>'0'),
'itemsCssClass'=>'item-class',
'pagerCssClass'=>'pager-class'
),
'CJuiTabs'=>array(
'htmlOptions'=>array('class'=>'shadowtabs'),
),
'CJuiAccordion'=>array(
'htmlOptions'=>array('class'=>'shadowaccordion'),
),
'CJuiProgressBar'=>array(
'htmlOptions'=>array('class'=>'shadowprogressbar'),
),
'CJuiSlider'=>array(
'htmlOptions'=>array('class'=>'shadowslider'),
),
'CJuiSliderInput'=>array(
'htmlOptions'=>array('class'=>'shadowslider'),
),
'CJuiButton'=>array(
'htmlOptions'=>array('class'=>'shadowbutton'),
),
'CJuiButton'=>array(
'htmlOptions'=>array('class'=>'shadowbutton'),
),
'CJuiButton'=>array(
'htmlOptions'=>array('class'=>'button green'),
),
),
),
'widgetFactory'=>array(
'class'=>'CWidgetFactory',
),
//encryption method for id or data
'securityManager'=>array('cryptAlgorithm' => 'rijndael-256',
'encryptionKey' => '@&#(Y.edw239974HKK@dhkh:;./s{}'
),
//cookies handler validation
'request'=>array(
'enableCookieValidation'=>TRUE,
),
//session handling
'session' => array(
'class' => 'CDbHttpSession',//session store class
'connectionID'=>'db',//connect to db
'sessionTableName'=>'session',//session store to this table
'timeout' =>600 ,// 10 minutes (1*60*10)
'autoCreateSessionTable' => FALSE,//false wont create session table automatically
'useTransparentSessionID' => FALSE,
'autoStart' => TRUE,
'cookieMode' =>'only',
'cookieParams' => array('secure' => false, 'httponly' => false),
),
//auto login if cookies is sitll alive - browser not clean cache
'user'=>array(
// enable cookie-based authentication
'allowAutoLogin'=>false,//if browser closed redirect to login page-set to false
'authTimeout'=>600, // 15 minutes.
),
//Bootstrap yii
'bootstrap' => array(
'class' => 'ext.bootstrap.components.Bootstrap',
'responsiveCss' => false,
),
//email configurations
'mail' => array(
'class' => 'ext.yii-mail.YiiMail',
'transportType' => 'smtp',
'transportOptions' => array(
'host' => 'smtp.gmail.com',
'username' => 'eloansyns@gmail.com',
'password' => '!isdp1-1',
'port' => '465',
'encryption' => 'tls',
),
'viewPath' => 'application.views.mail',
'logging' => true,
'dryRun' => false
),
// uncomment the following to enable URLs in path-format
//Hide the index.php to secure shorter URL path
'urlManager'=>array(
'urlFormat'=>'path',
'showScriptName'=>false,
'caseSensitive'=>false,
//'urlSuffix'=>'.html',
'rules'=>array(
'<controller:\w+>/<id:\d+>'=>'<controller>/view',
'<controller:\w+>/<action:\w+>/<id:\d+>'=>'<controller>/<action>',
'<controller:\w+>/<action:\w+>'=>'<controller>/<action>',
'<module:\w+>/<controller:\w+>/<action:\w+>' => '<module>/<controller>/<action>',
),
),
// uncomment the following to use a MySQL database
'db'=>array(
'connectionString' => 'mysql:host=localhost;dbname=osa',
'emulatePrepare' => true,
'username' => 'root',
'password' => '',
'charset' => 'utf8',
),
/*
'authManager'=>array(
'class'=>'CDbAuthManager',
'connectionID'=>'db',
),*/
'errorHandler'=>array(
// use 'site/error' action to display errors
'errorAction'=>'site/error',
),
'log'=>array(
'class'=>'CLogRouter',
'routes'=>array(
array(
'class'=>'CFileLogRoute',
'levels'=>'error, warning',
),
// uncomment the following to show log messages on web pages
/*array(
'class'=>'CWebLogRoute',
),*/
),
),
),
// application-level parameters that can be accessed
// using Yii::app()->params['paramName']
'params'=>array(
// this is used in contact page
//'adminEmail'=>'shahriza@wellcom.com.my',
'adminEmail'=>'vinoth@wellcom.com.my',
// Add below to your config/main.php params for pagination
'defaultPageSize' => 20,
),
);
auditTrail-> AdminController.php
<?php
class AdminController extends Controller
{
public $defaultAction = "admin";
public $layout = '//layouts/column1';
/**
* @return array action filters
*/
public function filters()
{
return array(
'accessControl', // perform access control for CRUD operations
'postOnly + delete', // we only allow deletion via POST request
);
}
/**
* Specifies the access control rules.
* This method is used by the 'accessControl' filter.
* @return array access control rules
*/
public function accessRules()
{
return array(
array('allow', // allow all users to perform 'index' and 'view' actions
'actions'=>array(''),
'users'=>array('*'),
),
array('allow', // allow authenticated user to perform 'create' and 'update' actions
'actions'=>array('admin'),
'users'=>array('@'),
),
array('allow', // allow admin user to perform 'admin' and 'delete' actions
'actions'=>array('delete'),
'users'=>array('admin'),
),
array('deny', // deny all users
'users'=>array('*'),
),
);
}
public function actionAdmin()
{
$model=new AuditTrail('search');
$model->unsetAttributes(); // clear any default values
if(isset($_GET['AuditTrail'])) {
$model->attributes=$_GET['AuditTrail'];
}
$this->render('admin',array(
'model'=>$model,
));
}
}
i am cracking my head for this.
pls i need senior advice on this matter.
tq
anyone solve this issue 404 error - auditrail
Hi! In my project I want know when user create a record. I add some relation in LoggableBehavior:
public function attach($owner)
{
parent::attach($owner);
$owner->getMetaData()->addRelation('changes', array(CActiveRecord::HAS_MANY, 'AuditTrail', 'model_id',
'condition' => 'model = :model', 'params' => array('model' => get_class($owner))));
}
In model I add relation:
'userRegistry' => array(self::HAS_ONE, 'User', ['user_id' => 'ID'], 'through' => 'changes', 'condition' => 'changes.action = "CREATE"'),
.
IMHO, first code snippet is very useful not only for me. Can you add this method in class LoggableBehavior?
Hi. for auditTrail.1.1.1 in file behaviors\LoggableBehavior.php replace from "$log=new auditTrail;" to $log=new AuditTrail(); in public function afterDelete($event).
It’s work for me