Skip to content

Commit

Permalink
Initial audit date fix
Browse files Browse the repository at this point in the history
Signed-off-by: snipe <[email protected]>
  • Loading branch information
snipe committed Feb 17, 2022
1 parent 7fe7d56 commit ea429d6
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions app/Http/Controllers/SettingsController.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
use App\Http\Requests\SettingsSamlRequest;
use App\Http\Requests\SetupUserRequest;
use App\Models\Setting;
use App\Models\Asset;
use App\Models\User;
use App\Notifications\FirstAdminNotification;
use App\Notifications\MailTest;
Expand All @@ -23,6 +24,7 @@
use Response;
use App\Helpers\StorageHelper;
use App\Http\Requests\SlackSettingsRequest;
use Carbon\Carbon;

/**
* This controller handles all actions related to Settings for
Expand Down Expand Up @@ -621,6 +623,39 @@ public function postAlerts(Request $request)
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) {

// Be careful - this could be a negative number
$audit_diff_months = ($setting->audit_interval - (int)$request->input('audit_interval'));

\Log::error('we need to update audit dates');
\Log::error('Audit difference: '.$audit_diff_months);

$assets = Asset::whereNotNull('next_audit_date')->take(10)->get();

foreach ($assets as $asset) {

if ($asset->next_audit_date != '') {

$old_next_audit = Carbon::parse($asset->next_audit_date);
\Log::error('Old audit date: '.$old_next_audit);
\Log::error('Adding '.$audit_diff_months.' months');

$new_next_audit = $old_next_audit->addMonths($audit_diff_months)->format('Y-m-d');

\Log::error('New audit date: '.$new_next_audit);

$asset->next_audit_date = $new_next_audit;
$asset->forceSave();
}

}

}



$alert_email = rtrim($request->input('alert_email'), ',');
$alert_email = trim($alert_email);
$admin_cc_email = rtrim($request->input('admin_cc_email'), ',');
Expand All @@ -635,6 +670,7 @@ public function postAlerts(Request $request)
$setting->audit_warning_days = $request->input('audit_warning_days');
$setting->show_alerts_in_menu = $request->input('show_alerts_in_menu', '0');


if ($setting->save()) {
return redirect()->route('settings.index')
->with('success', trans('admin/settings/message.update.success'));
Expand Down

0 comments on commit ea429d6

Please sign in to comment.