TenantAtlas/apps/platform/app/Console/Commands/SyncPolicies.php
Ahmed Darrazi 1123b122d9
Some checks failed
PR Fast Feedback / fast-feedback (pull_request) Failing after 7m13s
feat: cut over tenant core to managed environments
2026-05-07 08:35:42 +02:00

40 lines
1008 B
PHP

<?php
namespace App\Console\Commands;
use App\Jobs\SyncPoliciesJob;
use App\Models\ManagedEnvironment;
use Illuminate\Console\Command;
class SyncPolicies extends Command
{
protected $signature = 'intune:sync-policies {--tenant=} {--types=* : Limit to specific policy types}';
protected $description = 'Sync supported Intune policies from Microsoft Graph';
public function handle(): int
{
$tenant = $this->resolveTenant();
$types = $this->option('types') ?: null;
SyncPoliciesJob::dispatch($tenant->id, $types);
$this->info("Policy sync dispatched for tenant {$tenant->graphTenantId()}");
return Command::SUCCESS;
}
private function resolveTenant(): ManagedEnvironment
{
$tenantId = $this->option('tenant');
if ($tenantId) {
return ManagedEnvironment::query()
->forTenant($tenantId)
->firstOrFail();
}
return ManagedEnvironment::currentOrFail();
}
}