Skip to content
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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from

Conversation

MrXavierLin
Copy link

Audit data is growing much faster than real data, so it is may be needed to use alternative database to store the audit logs.

Copy link
Contributor

@ravage84 ravage84 left a 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')) {
Copy link
Contributor

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

Copy link
Contributor

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');
}
Copy link
Contributor

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');
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation wrong.

Copy link
Contributor

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'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code style issue if (

Copy link
Contributor

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'])) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Indentation wrong.

Copy link
Contributor

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants