cornernote / yii-audit-module

Track and display usage information including page requests, database field changes, php errors and yii logs.
https://cornernote.github.io/yii-audit-module
Other
22 stars 13 forks source link

Error with AuditLogRoute #6

Closed dadinugroho closed 10 years ago

dadinugroho commented 10 years ago

Hi cornernote,

Great yii module, Please help me on making this working, I am using manual install and always got this error message...

include(error, warning, profile, audit.php): failed to open stream: No such file or directory

<?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.
return array(
    'basePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'protected',
    'runtimePath' => dirname(__FILE__) . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . '..' . DIRECTORY_SEPARATOR . 'runtime',
    'name' => 'myInventory',
    'aliases' => array(
        // yiistrap configuration
        'bootstrap' => realpath(__DIR__ . '/../extensions/yiistrap'), // change if necessary
        // yiiwheels configuration
        'yiiwheels' => realpath(__DIR__ . '/../extensions/yiiwheels'), // change if necessary
        // audit configuration
        'audit' => realpath(__DIR__ . '/../modules/audit'), // change if necessary
    ),
    // preloading 'log' component
    'preload' => array('log', 'errorHandler'),
    // autoloading model and component classes
    'import' => array(
        'application.models.*',
        'application.components.*',
        'bootstrap.helpers.TbHtml',
        'bootstrap.helpers.TbArray',
        'bootstrap.behaviors.TbWidget',
        'application.modules.auth.*',
        'application.modules.auth.components.*',
        'bootstrap.widgets.*',
        'yiiwheels.widgets.toggle.WhToggleColumn',
    ),
    'modules' => array(
        // uncomment the following to enable the Gii tool
        'gii' => array(
            'class' => 'system.gii.GiiModule',
            'password' => 'dominica',
            'generatorPaths' => array('bootstrap.gii', 'application.gii'),
            // If removed, Gii defaults to localhost only. Edit carefully to taste.
            'ipFilters' => array('127.0.0.1', '::1', '192.168.1.145'),
        ),
        'auth' => array(
            'strictMode' => true, // when enabled authorization items cannot be assigned children of the same type.
            'userClass' => 'User', // the name of the user model class.
            'userIdColumn' => 'id', // the name of the user id column.
            'userNameColumn' => 'username', // the name of the user name column.
            'defaultLayout' => 'application.views.layouts.main_auth', // the layout used by the module.
            'viewDir' => null, // the path to view files to use with this module.
        ),
        'audit' => array(
            // path to the AuditModule class
            'class' => 'audit.AuditModule',
            // set this to your user view url,
            // AuditModule will replace --user_id-- with the actual user_id
            'userViewUrl' => array('/user/view', 'id' => '--user_id--'),
            // Set to false if you do not wish to track database audits.
            'enableAuditField' => true,
            // The ID of the CDbConnection application component. If not set, a SQLite3
            // database will be automatically created in protected/runtime/audit-AuditVersion.db.
            'connectionID' => 'db',
            // Whether the DB tables should be created automatically if they do not exist. Defaults to true.
            // If you already have the table created, it is recommended you set this property to be false to improve performance.
            'autoCreateTables' => true,
            // The layout used for module controllers.
            'layout' => 'audit.views.layouts.main',
            // The widget used to render grid views.
            'gridViewWidget' => 'bootstrap.widgets.TbGridView',
            // The widget used to render detail views.
            'detailViewWidget' => 'zii.widgets.CDetailView',
            // Defines the access filters for the module.
            // The default is AuditAccessFilter which will allow any user listed in AuditModule::adminUsers to have access.
            'controllerFilters' => array(
                'auditAccess' => array('audit.components.AuditAccessFilter'),
            ),
            // A list of users who can access this module.
            'adminUsers' => array('dadinugroho'),
            // The path to YiiStrap.
            // Only required if you do not want YiiStrap in your app config, for example, if you are running YiiBooster.
            // Only required if you did not install using composer.
            // Please note:
            // - You must download YiiStrap even if you are using YiiBooster in your app.
            // - When using this setting YiiStrap will only loaded in the menu interface (eg: index.php?r=menu).
            'yiiStrapPath' => 'bootstrap',
        ),
    ),
    // application components
    'components' => array(
        'session' => array(
            'class' => 'CCacheHttpSession',
        ),
        'cache' => array(
            'class' => 'system.caching.CApcCache',
        ),
        // yiistrap configuration
        'bootstrap' => array(
            'class' => 'bootstrap.components.TbApi',
        ),
        // yiiwheels configuration
        'yiiwheels' => array(
            'class' => 'yiiwheels.YiiWheels',
        ),
        'request' => array(
            'enableCsrfValidation' => true,
            'enableCookieValidation' => true,
        ),
        'authManager' => array(
            'class' => 'CDbAuthManager',
            'connectionID' => 'db',
            'behaviors' => array(
                'auth' => array(
                    'class' => 'auth.components.AuthBehavior',
                ),
            ),
        ),
        'user' => array(
            'class' => 'auth.components.AuthWebUser',
            'admins' => array('dadinugroho'), // users with full access
            'allowAutoLogin' => false,
        ),
        'errorHandler' => array(
            // path to the AuditErrorHandler class
            'class' => 'audit.components.AuditErrorHandler',
            // set this as you normally would for CErrorHandler
            'errorAction' => 'site/error',
            // Set to false to only track error requests.  Defaults to true.
            'trackAllRequests' => true,
            // Set to false to not handle fatal errors.  Defaults to true.
            'catchFatalErrors' => true,
            // Request keys that we do not want to save in the tracking data.
            'auditRequestIgnoreKeys' => array('PHP_AUTH_PW', 'password'),
        ),
        'urlManager' => array(
            'urlFormat' => 'path',
            'showScriptName' => false,
            'rules' => array(
                '<controller:\w+>/<id:\d+>' => '<controller>/view',
                '<controller:\w+>/<action:\w+>/<id:\d+>' => '<controller>/<action>',
                '<controller:\w+>/<action:\w+>' => '<controller>/<action>',
            ),
        ),
        'db' => array(
            'connectionString' => 'mysql:host=localhost;dbname=myinv_app',
            'emulatePrepare' => true,
            'enableParamLogging' => true,
            'username' => 'root',
            'password' => 'xxx',
            'charset' => 'utf8',
        ),
        'errorHandler' => array(
            // use 'site/error' action to display errors
            'errorAction' => 'site/error',
        ),
        'log' => array(
            'class' => 'CLogRouter',
            'routes' => array(
                // path to the AuditLogRoute class
                'class' => 'audit.components.AuditLogRoute',
                // can be: trace, warning, error, info, profile
                // can also be anything else you want to pass as a level to `Yii::log()`
                'levels' => 'error, warning, profile, audit',
            // 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' => 'webmaster@example.com',
        'encriptionKey' => 'xxx',
        'defaultPageSize' => 5,
    ),
);

How to set the alias for audit? also how to link it to yiistrap?

Thank you very much.

cornernote commented 10 years ago

@dadinugroho

include(error, warning, profile, audit.php): failed to open stream: No such file or directory

Your config looks fine. Try removing the log section of the config, just to see if that helps.

How to set the alias for audit?

You have already done that in this line:

'audit' => realpath(__DIR__ . '/../modules/audit'), // change if necessary

also how to link it to yiistrap?

As you use yiistrap as your bootstrap wrapper, you shouldn't need to do anything. But you should remove this line as it's only needed if you use a different bootstrap wrapper:

'yiiStrapPath' => 'bootstrap',
dadinugroho commented 10 years ago

@cornernote Thank you for prompt response. I can get rid of the log error. However, when try to access the audit (my project server is myinv-app.lan, so access it as myinv-app.lan/audit), I got another error message,

Property "AuditModule.gridViewWidget" is not defined.

I think I have defined it on the config/main.php. When I checked the AuditModule, there is not gridViewWidget property. I tried to comment these lines

        // The widget used to render grid views.

// 'gridViewWidget' => 'bootstrap.widgets.TbGridView', // The widget used to render detail views. // 'detailViewWidget' => 'zii.widgets.CDetailView', // Defines the access filters for the module.

But, now the error message is changed to

CErrorHandler and its behaviors do not have a method or closure named "hasAuditRequest".

Again, I remove errorHandler from preload array, error message is still the same.

Any help on this? And why the log part is not working on my project?

Thanks a lot.

cornernote commented 10 years ago

Do you have the latest development version or a release version?

cornernote commented 10 years ago

I just made a 1.1.5 release. Please try with that.

dadinugroho commented 10 years ago

I am using 1.1.4 the release version

cornernote commented 10 years ago

Please update and let me know how you go On 18/05/2014 9:41 AM, "dadinugroho" notifications@github.com wrote:

I am using 1.1.4 the release version

— Reply to this email directly or view it on GitHubhttps://github.com/cornernote/yii-audit-module/issues/6#issuecomment-43427731 .

dadinugroho commented 10 years ago

I have updated the module, but still got the error message

CErrorHandler and its behaviors do not have a method or closure named "hasAuditRequest". – /home/dadinugroho/projects/myinv-app/protected/modules/audit/views/request/footer.php(33): CComponent->call("hasAuditRequest", array())

28 29 /* @var AuditErrorHandler $errorHandler / 30 $errorHandler = $app->getErrorHandler(); 31 32 $output = array(); 33 if ($errorHandler->hasAuditRequest()) { 34 $auditRequest = $errorHandler->getAuditRequest(); 35 if ($isAdmin) 36 $output[] = CHtml::link($auditRequest->id, array('/' . $audit->id . '/request/view', 'id' => $auditRequest->id)); 37 else 38 $output[] = $auditRequest->id;

cornernote commented 10 years ago

Hello,

In a TestController, try this...

echo Yii::getPathOfAlias('audit');

Is the path as expected?

-- Brett

On Sun, May 18, 2014 at 9:57 AM, dadinugroho notifications@github.comwrote:

I have updated the module, but got this error message

Alias "audit.AuditModule" is invalid. Make sure it points to an existing PHP file and the file is readable.

— Reply to this email directly or view it on GitHubhttps://github.com/cornernote/yii-audit-module/issues/6#issuecomment-43427986 .

dadinugroho commented 10 years ago

yes, it is.

/home/dadinugroho/projects/myinv-app/protected/modules/audit

cornernote commented 10 years ago

Alias "audit.AuditModule" is invalid. Make sure it points to an existing PHP file and the file is readable.

Do you have a file and line where this error is triggered from?

If you are available, add me on skype (username: cornernote). If it's ok I would like to remote into your computer (teamviewer or ssh or something) to understand and assist with this issue so that I can improve the documentation for others who experience similar issues.

-- Brett

On Sun, May 18, 2014 at 10:02 PM, dadinugroho notifications@github.comwrote:

yes, it is.

/home/dadinugroho/projects/myinv-app/protected/modules/audit

— Reply to this email directly or view it on GitHubhttps://github.com/cornernote/yii-audit-module/issues/6#issuecomment-43438670 .

dadinugroho commented 10 years ago

The error on Audit log route is fixed. However, the error whenever I tried to open the myinv-app.lan/audit is still there, which is

CErrorHandler and its behaviors do not have a method or closure named "hasAuditRequest".

However, the rest of the code seems ok.

My skype is adinugro.

dadinugroho commented 10 years ago

Hi cornerstone,

I tried to debug the code. Below is the line that produce error message.

/modules/audit/views/request/__footer.php:

$errorHandler = $app->getErrorHandler(); echo 'Test' . get_class($errorHandler);

I tried to check the class of $errorHandler. It should be an AuditErrorHandler.php, but the echo shows CErrorHandler. Is that may be the caused? If I comment the code it did not show any error.

cornernote commented 10 years ago

Hey,

You have errorHandler component defined twice in your config. Remove the default one and leave the one you added with the audit module.

-- Brett

On Mon, May 19, 2014 at 1:40 PM, dadinugroho notifications@github.comwrote:

Hi cornerstone,

I tried to debug the code. Below is the line that produce error message.

/modules/audit/views/request/__footer.php:

$errorHandler = $app->getErrorHandler(); echo 'Test' . get_class($errorHandler);

I tried to check the class of $errorHandler. It should be an AuditErrorHandler.php, but the echo shows CErrorHandler. Is that may be the caused? If I comment the code it did not show any error.

— Reply to this email directly or view it on GitHubhttps://github.com/cornernote/yii-audit-module/issues/6#issuecomment-43464772 .

dadinugroho commented 10 years ago

Ah, great. It works now. Thanks you so much. I am still having another problem, though. The field changes setting. Let me open the new issue rather than put it in here since it is not related to the title anymore.

Thank you so much.

vinao commented 10 years ago

Hello Guys

I have one problem when is exhibition page the connection server fail/falls???? someone please could me help???

thanks

cornernote commented 10 years ago

@vinao please open a new issue and provide steps so that I can replicate your error.