argument('file'); $url = $this->option('url'); if (! $filePath && ! $url) { $this->error('Either provide a file path or use --url option'); return 1; } if ($url) { // Process ZIP from URL $this->info("Starting ZIP download and import from: {$url}"); if ($this->option('queue')) { ImportRiksdagDataJob::dispatch($url, true); $this->info('ZIP import job has been queued. Check queue workers for progress.'); } else { try { $job = new ImportRiksdagDataJob($url, true); $job->handle(); $this->info('ZIP import completed successfully!'); } catch (\Exception $e) { $this->error('ZIP import failed: '.$e->getMessage()); return 1; } } } else { // Process single file if (! file_exists($filePath)) { $this->error("File not found: {$filePath}"); return 1; } // Validate JSON format $jsonContent = file_get_contents($filePath); $testDecode = json_decode($jsonContent, true); if (json_last_error() !== JSON_ERROR_NONE) { $this->error('Invalid JSON format: '.json_last_error_msg()); return 1; } $this->info("Starting import from: {$filePath}"); if ($this->option('queue')) { ImportRiksdagDataJob::dispatch($filePath, false); $this->info('Import job has been queued. Check queue workers for progress.'); } else { try { $job = new ImportRiksdagDataJob($filePath, false); $job->handle(); $this->info('Import completed successfully!'); } catch (\Exception $e) { $this->error('Import failed: '.$e->getMessage()); return 1; } } } return 0; } }