argument('direction')); if (! in_array($direction, ['push', 'pull'], true)) { $this->error('Direction must be "push" or "pull".'); return self::FAILURE; } $url = trim((string) ($this->option('url') ?: config('helpdesk.sync.remote_url'))); $token = trim((string) ($this->option('token') ?: config('helpdesk.sync.remote_token'))); if ($url === '' || $token === '') { $this->error('Configure HELPDESK_SYNC_REMOTE_URL and HELPDESK_SYNC_REMOTE_TOKEN, or pass --url and --token.'); return self::FAILURE; } $settingsOnly = (bool) $this->option('settings-only'); $includeFiles = ! (bool) $this->option('without-files'); $mirror = (bool) $this->option('mirror'); $this->info(sprintf( '%s Helpdesk %s %s', ucfirst($direction), $settingsOnly ? 'settings' : 'settings + data', $direction === 'push' ? 'to '.$url : 'from '.$url, )); if ($mirror) { $this->warn('Mirror mode is enabled. Destination Helpdesk rows absent from the source can be deleted.'); } try { $result = $direction === 'push' ? $sync->push($url, $token, $settingsOnly, $includeFiles, $mirror) : $sync->pull($url, $token, $settingsOnly, $includeFiles, $mirror); } catch (Throwable $exception) { $this->error($exception->getMessage()); return self::FAILURE; } $this->newLine(); $this->table( ['Metric', 'Value'], collect($result)->map(fn ($value, $key): array => [ (string) $key, is_scalar($value) || $value === null ? (string) $value : json_encode($value, JSON_UNESCAPED_SLASHES), ])->values()->all(), ); return self::SUCCESS; } }