1
0
mirror of https://github.com/invoiceninja/invoiceninja.git synced 2024-11-10 05:02:36 +01:00
invoiceninja/app/Jobs/PurgeClientData.php
2018-03-14 19:51:49 +02:00

45 lines
940 B
PHP

<?php
namespace App\Jobs;
use App\Jobs\Job;
use App\Models\Invoice;
use App\Models\LookupAccount;
use DB;
use Exception;
use App\Libraries\HistoryUtils;
class PurgeClientData extends Job
{
public function __construct($client)
{
$this->client = $client;
}
/**
* Execute the job.
*
* @return void
*/
public function handle()
{
$invoices = $this->client->invoices()->withTrashed()->get();
$expenses = $this->client->expenses()->withTrashed()->get();
foreach ($invoices as $invoice) {
foreach ($invoice->documents as $document) {
$document->delete();
}
}
foreach ($expenses as $expense) {
foreach ($expense->documents as $document) {
$document->delete();
}
}
$this->client->forceDelete();
HistoryUtils::deleteHistory($this->client);
}
}