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>
26 lines
601 B
PHP
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);
|
|
}
|
|
}
|
|
}
|