inspiren-sem-tool/app/Console/Commands/GetGoogleCompanyDetails.php

46 lines
1.6 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\Client;
use Illuminate\Console\Command;
use Illuminate\Support\Facades\DB;
use App\Services\GoogleAdsService;
use Illuminate\Support\Facades\Log;
class GetGoogleCompanyDetails extends Command
{
protected $signature = 'google-ads:get-company-details';
protected $description = 'Get company details from Google Ads';
public function handle()
{
try {
DB::beginTransaction();
$this->info("Fetching company details from Google Ads...");
$mccCustomerId = env('GOOGLE_ADS_LOGIN_CUSTOMER_ID'); // Manager ID without dashes
$adsService = new GoogleAdsService();
$accounts = $adsService->listAccounts();
Log::info('Fetched accounts from Google Ads', ['accounts' => $accounts]);
foreach ($accounts as $account) {
$company = Client::updateOrCreate(
['customer_id' => $account['id']],
[
'name' => $account['name'],
'status' => $account['status'],
'time_zone' => $account['time_zone'],
]
);
$this->info("Customer ID: {$account['customer_id']}, Name: {$account['name']}, Status: {$account['status']}");
}
DB::commit();
} catch (\Exception $e) {
DB::rollBack();
Log::error('Error creating project iteration: '.$e->getMessage(), [
'trace' => $e->getTraceAsString(),
]);
return 1;
}
}
}