46 lines
1.4 KiB
PHP
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;
|
|
}
|
|
}
|