Files
HickLab3D_Dashboard/app/Console/Commands/EtsySync.php
T
hermes c8c5822166
Deploy HickLab3D Dashboard / Deploy to production (push) Successful in 38s
[verified] Harden Etsy MCP validation and scheduled token refresh
2026-11-07 21:54:33 +00:00

46 lines
1.4 KiB
PHP

<?php
namespace App\Console\Commands;
use App\Models\EtsyConnection;
use App\Services\Etsy;
use Illuminate\Console\Attributes\Description;
use Illuminate\Console\Attributes\Signature;
use Illuminate\Console\Command;
use Throwable;
#[Signature('etsy:sync')]
#[Description('Force a fresh pull of Etsy receipts and active listings into the dashboard cache')]
class EtsySync extends Command
{
public function handle(Etsy $etsy): int
{
$connection = EtsyConnection::first();
if (! $connection || ! $etsy->configured()) {
$this->line('Etsy sync skipped: shop is not configured or not connected.');
return self::SUCCESS;
}
$failed = false;
try {
$receipts = $etsy->receipts($connection, fresh: true);
$this->line('etsy receipts: refreshed ('.($receipts['count'] ?? 0).' open)');
} catch (Throwable $exception) {
$failed = true;
$this->warn('etsy receipts: '.$exception->getMessage());
}
try {
$listings = $etsy->listings($connection, fresh: true);
$this->line('etsy listings: refreshed ('.count($listings['results'] ?? []).' active)');
} catch (Throwable $exception) {
$failed = true;
$this->warn('etsy listings: '.$exception->getMessage());
}
return $failed ? self::FAILURE : self::SUCCESS;
}
}