-
Notifications
You must be signed in to change notification settings - Fork 77
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add the ability to define alternative data source in plugin's bootstrap.php #116
base: master
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for contributing. I like the idea, but this needs some work.
Plus needs tests and should be added to the documentation.
@@ -0,0 +1,4 @@ | |||
<?php | |||
if(!Configure::check('AuditLog.data_source')) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
While I personally like configuring my plugins through Configure, this introduces a second way of configuration besides the established one, as documented here:
https://github.com/robwilkerson/CakePHP-Audit-Log-Plugin#configuration
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This also means the configuration will be written for every request.
<?php | ||
if(!Configure::check('AuditLog.data_source')) { | ||
Configure::write('AuditLog.data_source', 'default'); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Removed trailing new line
@@ -60,6 +60,7 @@ public function setup(Model $Model, $settings = array()) { | |||
} | |||
|
|||
if (!isset($this->settings[$Model->alias])) { | |||
$this->settings[$Model->alias]['data_source'] = Configure::read('AuditLog.data_source'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we use the normal and established way of configuration for this plugin, we can use a fall back to default
.
I would introduce a property named $defaultDataSource
set to default
.
@@ -173,6 +174,11 @@ public function afterSave(Model $Model, $created, $options = array()) { | |||
array('hasMany' => array('AuditLog.Audit')) | |||
); | |||
|
|||
if(isset($this->settings[$Model->alias]['data_source'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Code style issue if (
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This could be extracted into a separate protected method. Would increase readability, reduce method length and complexity and would enable one to overwrite that new method, if needed.
@@ -318,6 +324,10 @@ public function afterDelete(Model $Model) { | |||
); | |||
|
|||
$this->Audit = ClassRegistry::init('AuditLog.Audit'); | |||
if(isset($this->settings[$Model->alias]['data_source'])) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Indentation wrong.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The next few lines are practically a copy of the new code above. Another reason for extacting it into a generalized method.
Audit data is growing much faster than real data, so it is may be needed to use alternative database to store the audit logs.