init
This commit is contained in:
232 files changed
+25416
No files matched your search
@@ -0,0 +1,54 @@
|
||||
<?php
|
||||
|
||||
namespace App\Console\Commands;
|
||||
|
||||
use App\Jobs\SyncCafeBazaarApp;
|
||||
use App\Models\MobileApp;
|
||||
use App\Services\CafeBazaar\SyncCafeBazaarAppAction;
|
||||
use Illuminate\Console\Attributes\Description;
|
||||
use Illuminate\Console\Attributes\Signature;
|
||||
use Illuminate\Console\Command;
|
||||
|
||||
#[Signature('bazaar:sync {--app= : Synchronize one app by package name} {--now : Run immediately instead of queueing} {--force : Ignore normal freshness intervals}')]
|
||||
#[Description('Synchronize Cafe Bazaar purchases, subscriptions, reviews, and release states')]
|
||||
class SyncCafeBazaarAppsCommand extends Command
|
||||
{
|
||||
public function handle(SyncCafeBazaarAppAction $sync): int
|
||||
{
|
||||
$packageName = $this->option('app');
|
||||
$query = MobileApp::query()->where('is_active', true);
|
||||
|
||||
if (is_string($packageName) && $packageName !== '') {
|
||||
$query->where('package_name', $packageName);
|
||||
} else {
|
||||
$query->where('bazaar_sync_enabled', true);
|
||||
}
|
||||
|
||||
$apps = $query->get()->filter(function (MobileApp $app) use ($packageName): bool {
|
||||
if (is_string($packageName) && $packageName !== '') {
|
||||
return true;
|
||||
}
|
||||
|
||||
return $app->bazaar_last_synced_at === null
|
||||
|| $app->bazaar_last_synced_at->lte(now()->subMinutes($app->bazaar_sync_interval_minutes));
|
||||
});
|
||||
|
||||
if ($apps->isEmpty()) {
|
||||
$this->components->info('No Cafe Bazaar app synchronization is due.');
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
|
||||
foreach ($apps as $app) {
|
||||
if ($this->option('now')) {
|
||||
$result = $sync->execute($app, (bool) $this->option('force'));
|
||||
$this->line("{$app->name}: {$result['status']}");
|
||||
} else {
|
||||
SyncCafeBazaarApp::dispatch($app->id, (bool) $this->option('force'));
|
||||
$this->line("{$app->name}: queued");
|
||||
}
|
||||
}
|
||||
|
||||
return self::SUCCESS;
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user