Credit allotment is now derived directly from BillingCycle::for($account)->creditAllotment() instead of a cached Pennant feature, removing the dynamic cache-invalidation footgun (forgetPlanFeatureCache) that had to be called from every subscription/workspace mutation.
29 lines
686 B
PHP
29 lines
686 B
PHP
<?php
|
|
|
|
declare(strict_types=1);
|
|
|
|
namespace App\Actions\Workspace;
|
|
|
|
use App\Jobs\PostHog\SyncAccountUsage;
|
|
use App\Models\User;
|
|
use App\Models\Workspace;
|
|
use App\Services\PostHogService;
|
|
|
|
class DeleteWorkspace
|
|
{
|
|
public static function execute(User $user, Workspace $workspace): void
|
|
{
|
|
User::where('current_workspace_id', $workspace->id)->update(['current_workspace_id' => null]);
|
|
|
|
$account = $workspace->account;
|
|
$accountId = (string) $workspace->account_id;
|
|
|
|
$workspace->delete();
|
|
|
|
$account?->syncWorkspaceQuantity();
|
|
|
|
if (PostHogService::isEnabled()) {
|
|
SyncAccountUsage::dispatch($accountId, null);
|
|
}
|
|
}
|
|
}
|