Merge pull request #18590 from grokability/optionally-update-audit-dates
Added checkbox to determine if existing audit dates should be changed
This commit is contained in:
@@ -403,24 +403,23 @@ class SettingsController extends Controller
|
||||
return redirect()->to('admin')->with('error', trans('admin/settings/message.update.error'));
|
||||
}
|
||||
|
||||
// Check if the audit interval has changed - if it has, we want to update ALL of the assets audit dates
|
||||
if ($request->input('audit_interval') != $setting->audit_interval) {
|
||||
|
||||
// This could be a negative number if the user is trying to set the audit interval to a lower number than it was before
|
||||
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
||||
// Check if the audit interval has changed - if it has, check if we should update all of the assets audit dates
|
||||
if ((($request->input('audit_interval') != $setting->audit_interval)) && ($request->input('update_existing_dates') == 1)) {
|
||||
|
||||
// Batch update the dates. We have to use this method to avoid time limit exceeded errors on very large datasets,
|
||||
// but it DOES mean this change doesn't get logged in the action logs, since it skips the observer.
|
||||
// @see https://stackoverflow.com/questions/54879160/laravel-observer-not-working-on-bulk-insert
|
||||
$affected = Asset::whereNotNull('next_audit_date')
|
||||
->whereNull('deleted_at')
|
||||
->update(
|
||||
['next_audit_date' => DB::raw('DATE_ADD(next_audit_date, INTERVAL '.$audit_diff_months.' MONTH)')]
|
||||
);
|
||||
|
||||
Log::debug($affected .' assets affected by audit interval update');
|
||||
// This could be a negative number if the user is trying to set the audit interval to a lower number than it was before
|
||||
$audit_diff_months = ((int)$request->input('audit_interval') - (int)($setting->audit_interval));
|
||||
|
||||
// Batch update the dates. We have to use this method to avoid time limit exceeded errors on very large datasets,
|
||||
// but it DOES mean this change doesn't get logged in the action logs, since it skips the observer.
|
||||
// @see https://stackoverflow.com/questions/54879160/laravel-observer-not-working-on-bulk-insert
|
||||
$affected = Asset::whereNotNull('next_audit_date')
|
||||
->whereNull('deleted_at')
|
||||
->update(
|
||||
['next_audit_date' => DB::raw('DATE_ADD(next_audit_date, INTERVAL ' . $audit_diff_months . ' MONTH)')]
|
||||
);
|
||||
|
||||
Log::debug($affected . ' assets affected by audit interval update');
|
||||
}
|
||||
|
||||
$alert_email = rtrim($request->input('alert_email'), ',');
|
||||
|
||||
@@ -24,7 +24,7 @@ return [
|
||||
'allow_user_skin_help_text' => 'Checking this box will allow a user to override the UI skin with a different one.',
|
||||
'asset_ids' => 'Asset IDs',
|
||||
'audit_interval' => 'Audit Interval',
|
||||
'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months that you use. If you update this value, all of the "next audit dates" for assets with an upcoming audit date will be updated.',
|
||||
'audit_interval_help' => 'If you are required to regularly physically audit your assets, enter the interval in months that you use. ',
|
||||
'audit_warning_days' => 'Audit Warning Threshold',
|
||||
'audit_warning_days_help' => 'How many days in advance should we warn you when assets are due for auditing?',
|
||||
'auto_increment_assets' => 'Generate auto-incrementing asset tags',
|
||||
@@ -438,6 +438,7 @@ return [
|
||||
'client_secret' => 'Client Secret',
|
||||
'client_id' => 'Client ID',
|
||||
'too_many_users_to_show' => 'The number of users (:count) is larger than the unpaginated record limit (:max). Use the bulk user edit tool to manage group memberships.',
|
||||
'update_existing_dates' => 'Also update all of the existing "next audit dates" for assets with an upcoming audit with the Audit Interval above. This is most commonly used when the internal policy for audit interval has changed.',
|
||||
|
||||
'username_formats' => [
|
||||
'username_format' => 'Username Format',
|
||||
|
||||
@@ -205,6 +205,16 @@
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<!-- Alerts Enabled -->
|
||||
<div class="form-group {{ $errors->has('update_existing_dates') ? 'error' : '' }}">
|
||||
<div class="col-md-9 col-md-offset-3">
|
||||
<label class="form-control">
|
||||
<input type="checkbox" name="update_existing_dates" value="1" @checked(old('update_existing_dates'))>
|
||||
{{ trans('admin/settings/general.update_existing_dates') }}
|
||||
</label>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</fieldset>
|
||||
|
||||
</div>
|
||||
|
||||
Reference in New Issue
Block a user