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

Runtime enable/disable auditing suggestion #387

Closed
lauri911 opened this issue Feb 15, 2018 · 3 comments
Closed

Runtime enable/disable auditing suggestion #387

lauri911 opened this issue Feb 15, 2018 · 3 comments
Assignees
Labels

Comments

@lauri911
Copy link

Q A
New Feature? yes
Package version 6.0.x

Expected Behaviour

Sometimes is need to disable auditing for one model temporarily, for example when doing some big imports and auditing for every row is not necessary.

For example:

Customer::disableAuditing();

foreach($thousandsImportedCustomers as $importedCustomer){
    Customer::create($data);   // don't want to audit this here
}

Customer::enableAuditing();

Possible Solutions

I am doing it via additional trait at moment but you could just add something like that to have it right out of the box :)

public static $auditingDisabled = false;

public static function isAuditingEnabled(): bool
 {
        if (self::$auditingDisabled) {
            return false;
        }

        if (App::runningInConsole()) {
            return Config::get('audit.console', false);
        }

        return true;
}

public static function disableAuditing()
{
        self::$auditingDisabled = true;
}

public static function enableAuditing()
{
        self::$auditingDisabled = false;
}

@quetzyg quetzyg self-assigned this Feb 15, 2018
@quetzyg quetzyg added the V6 label Feb 15, 2018
@quetzyg
Copy link
Contributor

quetzyg commented Feb 15, 2018

Thanks for your suggestion @lauri911.
I'll take it into consideration.

@lauri911
Copy link
Author

lauri911 commented Feb 15, 2018

Thanks, because adding it with additional trait is little bit tricky and "dirty":

    use Auditable, AuditingDisablingFunctionality {

        AuditingDisablingFunctionality::isAuditingEnabled insteadOf Auditable;

        Auditable::isAuditingEnabled as originalIsAuditingEnabled;

    }

And then in trait:

    public static function isAuditingEnabled(): bool
    {
        if (self::$auditingDisabled) {
            return false;
        }

        return static::originalIsAuditingEnabled();
    }

@quetzyg
Copy link
Contributor

quetzyg commented Feb 15, 2018

I'll update the documentation ASAP.

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

No branches or pull requests

2 participants