1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-12 22:22:32 +01:00

Log purged clients

This commit is contained in:
Hillel Coren 2018-04-26 10:27:59 +03:00
parent ea7ca53848
commit 4fc60b02f4
2 changed files with 24 additions and 5 deletions

View File

@ -8,6 +8,7 @@ use App\Models\LookupAccount;
use DB; use DB;
use Exception; use Exception;
use App\Libraries\HistoryUtils; use App\Libraries\HistoryUtils;
use Utils;
class PurgeClientData extends Job class PurgeClientData extends Job
{ {
@ -23,8 +24,24 @@ class PurgeClientData extends Job
*/ */
public function handle() public function handle()
{ {
$invoices = $this->client->invoices()->withTrashed()->get(); $user = auth()->user();
$expenses = $this->client->expenses()->withTrashed()->get(); $client = $this->client;
$contact = $client->getPrimaryContact();
if (! $user->is_admin) {
return;
}
$message = sprintf('%s %s (%s) purged client: %s %s', date('Y-m-d h:i:s'), $user->email, request()->getClientIp(), $client->name, $contact->email);
if (config('app.log') == 'single') {
@file_put_contents(storage_path('logs/purged-clients.log'), $message, FILE_APPEND);
} else {
Utils::logError('[purged client] ' . $message);
}
$invoices = $client->invoices()->withTrashed()->get();
$expenses = $client->expenses()->withTrashed()->get();
foreach ($invoices as $invoice) { foreach ($invoices as $invoice) {
foreach ($invoice->documents as $document) { foreach ($invoice->documents as $document) {

View File

@ -68,9 +68,11 @@
@if ($client->trashed()) @if ($client->trashed())
@can('edit', $client) @can('edit', $client)
{!! Button::danger(trans('texts.purge_client')) @if (auth()->user()->is_admin)
->appendIcon(Icon::create('warning-sign')) {!! Button::danger(trans('texts.purge_client'))
->withAttributes(['onclick' => 'onPurgeClick()']) !!} ->appendIcon(Icon::create('warning-sign'))
->withAttributes(['onclick' => 'onPurgeClick()']) !!}
@endif
{!! Button::primary(trans('texts.restore_client')) {!! Button::primary(trans('texts.restore_client'))
->appendIcon(Icon::create('cloud-download')) ->appendIcon(Icon::create('cloud-download'))
->withAttributes(['onclick' => 'onRestoreClick()']) !!} ->withAttributes(['onclick' => 'onRestoreClick()']) !!}