mirror of
https://github.com/invoiceninja/invoiceninja.git
synced 2026-03-03 02:57:01 +00:00
Add account deleted event
This commit is contained in:
52
app/Events/Account/AccountDeleted.php
Normal file
52
app/Events/Account/AccountDeleted.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
/**
|
||||
* Invoice Ninja (https://invoiceninja.com).
|
||||
*
|
||||
* @link https://github.com/invoiceninja/invoiceninja source repository
|
||||
*
|
||||
* @copyright Copyright (c) 2025. Invoice Ninja LLC (https://invoiceninja.com)
|
||||
*
|
||||
* @license https://www.elastic.co/licensing/elastic-license
|
||||
*/
|
||||
|
||||
namespace App\Events\Account;
|
||||
|
||||
use Illuminate\Broadcasting\Channel;
|
||||
use Illuminate\Broadcasting\InteractsWithSockets;
|
||||
use Illuminate\Broadcasting\PrivateChannel;
|
||||
use Illuminate\Foundation\Events\Dispatchable;
|
||||
use Illuminate\Queue\SerializesModels;
|
||||
|
||||
/**
|
||||
* Class AccountDeleted.
|
||||
*/
|
||||
class AccountDeleted
|
||||
{
|
||||
use Dispatchable;
|
||||
use InteractsWithSockets;
|
||||
use SerializesModels;
|
||||
|
||||
|
||||
/**
|
||||
* Create a new event instance.
|
||||
*
|
||||
* @param $user
|
||||
* @param $company
|
||||
* @param $event_vars
|
||||
*/
|
||||
public function __construct(public string $account_key, public string $email, public string $ip)
|
||||
{
|
||||
}
|
||||
|
||||
// /**
|
||||
// * Get the channels the event should broadcast on.
|
||||
// *
|
||||
// * @return Channel|array
|
||||
// */
|
||||
public function broadcastOn()
|
||||
{
|
||||
return [];
|
||||
// return new PrivateChannel('channel-name');
|
||||
}
|
||||
}
|
||||
52
app/Listeners/Account/AccountDeletedListener.php
Normal file
52
app/Listeners/Account/AccountDeletedListener.php
Normal file
@@ -0,0 +1,52 @@
|
||||
<?php
|
||||
|
||||
namespace App\Listeners\Account;
|
||||
|
||||
use App\Utils\Ninja;
|
||||
use App\Models\Company;
|
||||
use App\Models\Activity;
|
||||
use App\Libraries\MultiDB;
|
||||
use App\Jobs\Mail\NinjaMailerJob;
|
||||
use App\Jobs\Mail\NinjaMailerObject;
|
||||
use Illuminate\Contracts\Queue\ShouldQueue;
|
||||
|
||||
class AccountDeletedListener implements ShouldQueue
|
||||
{
|
||||
/**
|
||||
* Create the event listener.
|
||||
*
|
||||
*/
|
||||
public function __construct()
|
||||
{
|
||||
}
|
||||
|
||||
/**
|
||||
* Handle the event.
|
||||
*
|
||||
* @param object $event
|
||||
* @return void
|
||||
*/
|
||||
public function handle($event)
|
||||
{
|
||||
|
||||
if (Ninja::isHosted()) {
|
||||
|
||||
MultiDB::setDB('db-ninja-01');
|
||||
|
||||
$company = Company::find(config('ninja.ninja_default_company_id'));
|
||||
|
||||
$activity = new Activity();
|
||||
|
||||
$activity->user_id = null;
|
||||
$activity->company_id = $company->id;
|
||||
$activity->account_id = $company->account_id;
|
||||
$activity->activity_type_id = Activity::ACCOUNT_DELETED;
|
||||
$activity->notes = "Account {$event->account_key} deleted by {$event->email} from {$event->ip}";
|
||||
$activity->ip = $event->ip;
|
||||
$activity->is_system = false;
|
||||
$activity->save();
|
||||
|
||||
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user