-
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?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
<?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 commentThe reason will be displayed to describe this comment to others. Learn more. Removed trailing new line |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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 commentThe 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 commentThe 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 I would introduce a property named |
||
$this->settings[$Model->alias]['ignore'] = array('created', 'updated', 'modified'); | ||
$this->settings[$Model->alias]['habtm'] = array(); | ||
if (!isset($settings['habtm'])) { | ||
|
@@ -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 commentThe reason will be displayed to describe this comment to others. Learn more. Code style issue There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. |
||
$Model->Audit->useDbConfig = $this->settings[$Model->alias]['data_source']; | ||
$Model->Audit->AuditDelta->useDbConfig = $this->settings[$Model->alias]['data_source']; | ||
} | ||
|
||
// If a currentUser() method exists in the model class (or, of | ||
// course, in a superclass) the call that method to pull all user | ||
// data. Assume than an ID field exists. | ||
|
@@ -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 commentThe 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 commentThe 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. |
||
$this->Audit->useDbConfig = $this->settings[$Model->alias]['data_source']; | ||
$this->Audit->AuditDelta->useDbConfig = $this->settings[$Model->alias]['data_source']; | ||
} | ||
$this->Audit->create(); | ||
$this->Audit->save($data); | ||
|
||
|
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.