trypost/app/Actions/Workspace/DeleteWorkspace.php
Paulo Castellano ccd78e3c8d fix(posthog): harden usage sync after deletes and workspace removal
Use Account::postsCountCacheKey everywhere, avoid findOrFail when syncing
post deletes, dispatch SyncAccountUsage after DeleteWorkspace when enabled,
and add coverage for the new paths.

Co-authored-by: Cursor <cursoragent@cursor.com>
2026-05-19 19:01:53 -03:00

26 lines
601 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]);
$accountId = (string) $workspace->account_id;
$workspace->delete();
if (PostHogService::isEnabled()) {
SyncAccountUsage::dispatch($accountId, null);
}
}
}