Yii Framework Forum: [EXTENSION] AuditTrail - Yii Framework Forum

Jump to content

  • (5 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic

[EXTENSION] AuditTrail Module to make audit trail functionality super simple and quick Rate Topic: ***** 5 Votes

#61 User is offline   Van Damm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 04-September 11
  • Location:Ukraine

Posted 30 September 2011 - 07:23 AM

I'd like to thank you for this extension: it is very useful!

Please consider following bugs I encountered:
  • Provided db migration does not work with MySQL. Here's what I had to change:
    • column types not set for model and field, modified to:
      'model' => 'string NOT NULL',
      'field' => 'string NOT NULL',

    • MySQL does not allow indices on full-text fields. Had to remove keys on old_value and new_value

  • Not all Yii applications contain generated-by-default Controller class. It's better to use your own base controller class (eg AuditTrailController), that implements required variables

0

#62 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 01 October 2011 - 12:18 PM

View PostVan Damm, on 30 September 2011 - 07:23 AM, said:

I'd like to thank you for this extension: it is very useful!

Please consider following bugs I encountered:
  • Provided db migration does not work with MySQL. Here's what I had to change:
    • column types not set for model and field, modified to:
      'model' => 'string NOT NULL',
      'field' => 'string NOT NULL',

    • MySQL does not allow indices on full-text fields. Had to remove keys on old_value and new_value

  • Not all Yii applications contain generated-by-default Controller class. It's better to use your own base controller class (eg AuditTrailController), that implements required variables




Thanks for the tips. I have the typos in the migrations updated, sorry for that! I'm on the fence about the controller issue, though. I was trying to make the module just sort of "work" and look like the rest of your app. If I make it use its own controller, then you have to figure out a way to make it easy to modify without making someone edit the module code. I just made AuditTrailController check the config file for its variables and then set defaults if there is nothing in the config for menu, breadcrumbs, and layout. Does that sound like a good compromise? If so I can bundle and release a minor version
0

#63 User is offline   Van Damm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 04-September 11
  • Location:Ukraine

Posted 02 October 2011 - 04:48 AM

View PostMadSkillsTisdale, on 01 October 2011 - 12:18 PM, said:

Does that sound like a good compromise?

Yes, it may be the way.
Also, you can use getter methods in your behavior instead of relying on magic, ie:
$this->getOwner()
in place of
$this->Owner
as using the method directly is a bit faster
0

#64 User is offline   Van Damm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 04-September 11
  • Location:Ukraine

Posted 04 October 2011 - 08:55 AM

I'm using this extension now and extended it to suit my needs. Feel free to use my enhanced version and merge it with main extension if you wish.

Here's what I did:
  • Refactored code
  • Added possibility to ignore attributes from trailing
  • Added possibility to log model creation only
  • Added property to set time format
  • Added possibility to save timestamp instead of formatted time
  • Added possibility to use model's field instead of user id (this is useful when you have no specific users in your application, but there are more important models, to which other ones are bound)

The only modified file for now is LoggableBehavior.php:
Spoiler


P.S.: Can you publish the extension on some code hosting site like GitHub so we can help you enhance the extension?
1

#65 User is offline   yiqing95 

  • Master Member
  • PipPipPipPip
  • Yii
  • Group: Members
  • Posts: 604
  • Joined: 27-December 10
  • Location:china

Posted 23 October 2011 - 11:53 AM

View PostVan Damm, on 04 October 2011 - 08:55 AM, said:

I'm using this extension now and extended it to suit my needs. Feel free to use my enhanced version and merge it with main extension if you wish.

Here's what I did:
  • Refactored code
  • Added possibility to ignore attributes from trailing
  • Added possibility to log model creation only
  • Added property to set time format
  • Added possibility to save timestamp instead of formatted time
  • Added possibility to use model's field instead of user id (this is useful when you have no specific users in your application, but there are more important models, to which other ones are bound)

The only modified file for now is LoggableBehavior.php:
Spoiler


P.S.: Can you publish the extension on some code hosting site like GitHub so we can help you enhance the extension?

it 's true that there are some errors in the original version , i agree with put the extension to github or google code , thus we can make it better :lol:
0

#66 User is offline   lolgolflol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 13-October 11

Posted 11 November 2011 - 01:56 AM

I have issue , Event afterDelete is not work. How I fix?
0

#67 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 11 November 2011 - 01:12 PM

GitHub is up!

https://github.com/C...e/YiiAuditTrail

Beware - This is not a stable version! I'm used to svn, so I got the core code up fine. I ran into some errors I didn't understand when trying to create a branch for the nonstable copy, so I just committed everything to master. In any event, this is what is there:

Van Damm's code is integrated into LoggableBehavior, but with a few changes. I do not like the configuration values inside of the behavior, so I moved them to the module. The behavior gets them from the module as needed, but this way they can be set up in the main config file. This will make updating to later versions of the code easier since you don't have to go back and reset defaults inside of any core objects that would be overwritten by the new files.

I still can't get PHPUnit running on my freaking laptop. Every time I try I wind up wasting most of the day. I should have just hand tested instead, but I don't have time now. Please check it out and let me know what you think!
0

#68 User is offline   Van Damm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 04-September 11
  • Location:Ukraine

Posted 11 November 2011 - 05:26 PM

I think that you still need to be able to configure the behavior individually for different models even if default values are retrieved from module configuration. This is needed because different models can require different logging options.
0

#69 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 11 November 2011 - 05:35 PM

View PostVan Damm, on 11 November 2011 - 05:26 PM, said:

I think that you still need to be able to configure the behavior individually for different models even if default values are retrieved from module configuration. This is needed because different models can require different logging options.



Maybe I don't understand enough about what you were thinking. Were you thinking that each time you instantiate a model you would set the criteria then? Maybe a code or pseudocode sample would help me understand how this would happen? I can change the code accordingly once I see ow you were thinking to use it
0

#70 User is offline   Van Damm 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 27
  • Joined: 04-September 11
  • Location:Ukraine

Posted 11 November 2011 - 05:49 PM

You need to attach the behavior to each model you want it to log:
public function behaviors()
{
  return array(
    'LoggableBehavior' => 'application.modules.auditTrail.behaviors.LoggableBehavior',
  );
}
So you may need to apply different logging settings to different model classes.

For example, you want changes to User models to be logged using timestamps instead of textual date representation and changes to Comment models to ignore 'modification_date' field:
class User extends ActiveRecord 
{
  // ...
  public function behaviors()
  {
    return array(
      'LoggableBehavior'=> array(
        'class' => 'application.modules.auditTrail.behaviors.LoggableBehavior',
        'saveTimestamp' => true
      );
    );
  }
  // ...
}

class Comment extends ActiveRecord 
{
  // ...
  public function behaviors()
  {
    return array(
      'LoggableBehavior'=> array(
        'class' => 'application.modules.auditTrail.behaviors.LoggableBehavior',
        'ignore' => array('modification_date')
      );
    );
  }
  // ...
}


What I mean here is that the developer needs to be able to customize behavior settings for each model class it is being attached to.
0

#71 User is offline   lolgolflol 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 8
  • Joined: 13-October 11

Posted 12 November 2011 - 10:02 PM

I use extension and have issue. When I delete but audit does not work but create and update do work. I was checked bug I know afterDelete doesn't work. Why is it and How do fix?
0

#72 User is offline   Borange Juice 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 6
  • Joined: 07-December 11

Posted 12 December 2011 - 04:39 AM

Hi,

I love this extension. Have you considered normalising the database schema into something more on the lines of this?

AuditLog

All the best.
0

#73 User is offline   Tekato 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 11-November 11

Posted 14 December 2011 - 04:04 AM

hey guyz...i can't seam to make the modul work. I read all the info in this thread and no luck. The error i get is this:

CException     Alias "auditTrail.AuditTrailModule" is invalid. Make sure it points to an existing PHP file.

i copied the ziped content in modules dir and modified the main.php fiel with the import and modules but stil no working.

Can anyone help me?!
0

#74 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 14 December 2011 - 08:27 AM

View PostBorange Juice, on 12 December 2011 - 04:39 AM, said:

Hi,

I love this extension. Have you considered normalising the database schema into something more on the lines of this?

AuditLog

All the best.



This is cool. I haven't seen this before. Thanks for showing it to me! Van Damm, any words of wisdom on this? I think you probably have dealt with the limitations of the current module more than I have, and I am curious to know your take on this link.
0

#75 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 14 December 2011 - 08:28 AM

View PostTekato, on 14 December 2011 - 04:04 AM, said:

hey guyz...i can't seam to make the modul work. I read all the info in this thread and no luck. The error i get is this:

CException     Alias "auditTrail.AuditTrailModule" is invalid. Make sure it points to an existing PHP file.

i copied the ziped content in modules dir and modified the main.php fiel with the import and modules but stil no working.

Can anyone help me?!



Can you post the full section of your config files where you import audit trail, as well as let us know what file is giving you the error? Seems like we can probably solve this easily enough.
0

#76 User is offline   Tekato 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 11-November 11

Posted 15 December 2011 - 07:47 AM

@ MadSkillsTisdale it workes now

My only problem now is that i don't know how to modify it so it showes the names instead of the id's:(
For example i have a computer table that has multiple colums of with half are id's that are in relation to other tables. how do i enhance the behavior file so that it saves in the log table the names asociated to the id's. Anyone has a clue?
0

#77 User is offline   MadSkillsTisdale 

  • Standard Member
  • PipPip
  • Yii
  • Group: Members
  • Posts: 101
  • Joined: 15-February 09
  • Location:New Orleans, LA

Posted 15 December 2011 - 06:00 PM

View PostTekato, on 15 December 2011 - 07:47 AM, said:

@ MadSkillsTisdale it workes now

My only problem now is that i don't know how to modify it so it showes the names instead of the id's:(
For example i have a computer table that has multiple colums of with half are id's that are in relation to other tables. how do i enhance the behavior file so that it saves in the log table the names asociated to the id's. Anyone has a clue?



You wouldn't save the names associated, you would modify the display in the widget configuration to look up the foreign rows and display the fields you want at display time. The widget accepts configuration like CDataGrid does, so you would change the display the same way. Does that make sense?
0

#78 User is offline   Tekato 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 9
  • Joined: 11-November 11

Posted 16 December 2011 - 03:35 AM

yes i thought @ that but how does he know what table i make reference to?! Do youu have a small example?!
0

#79 User is offline   chriscao 

  • Junior Member
  • Pip
  • Yii
  • Group: Members
  • Posts: 43
  • Joined: 03-February 10

Posted 19 January 2012 - 06:56 AM

View PostVan Damm, on 04 October 2011 - 08:55 AM, said:

I'm using this extension now and extended it to suit my needs. Feel free to use my enhanced version and merge it with main extension if you wish.

Here's what I did:
  • Refactored code
  • Added possibility to ignore attributes from trailing
  • Added possibility to log model creation only
  • Added property to set time format
  • Added possibility to save timestamp instead of formatted time
  • Added possibility to use model's field instead of user id (this is useful when you have no specific users in your application, but there are more important models, to which other ones are bound)

The only modified file for now is LoggableBehavior.php:
Spoiler


P.S.: Can you publish the extension on some code hosting site like GitHub so we can help you enhance the extension?



A good job~
0

#80 User is offline   maybeme 

  • Newbie
  • Yii
  • Group: Members
  • Posts: 1
  • Joined: 27-February 12

Posted 27 February 2012 - 05:14 PM

The migration doesn't work for a mysql database. I edited the migration as this:

$this->createTable( 'tbl_audit_trail',
	array(
		'id' => 'pk',
		'old_value' => 'text',
		'new_value' => 'text',
		'action' => 'string NOT NULL',
		'model' => 'string NOT NULL', // added the string keyword
		'field' => 'string NOT NULL', // added the string keyword
		'stamp' => 'datetime NOT NULL',
		'user_id' => 'string',
		'model_id' => 'string NOT NULL',
			)
);


And I commented out the lines where the migration adds the indexes on old_value and new_value. I think they're not needed (sorting on those won't happen a lot I think), and mysql doesn't support searching in TEXT data without a maximum size.

I also think user_id should be an integer (in my case it is)
1

Share this topic:


  • (5 Pages)
  • +
  • « First
  • 2
  • 3
  • 4
  • 5
  • You cannot start a new topic
  • You cannot reply to this topic

1 User(s) are reading this topic
0 members, 1 guests, 0 anonymous users