From b558641875f41a550059dcd26a66b54214a663e1 Mon Sep 17 00:00:00 2001 From: bernardhanna Date: Tue, 17 Jun 2025 15:21:26 +0100 Subject: [PATCH] amy events --- app/Console/Commands/excel/Generic.php | 40 +++++++++++++++++--------- app/Imports/GenericEventsImport.php | 32 --------------------- 2 files changed, 26 insertions(+), 46 deletions(-) diff --git a/app/Console/Commands/excel/Generic.php b/app/Console/Commands/excel/Generic.php index f6db83592..0830d8192 100644 --- a/app/Console/Commands/excel/Generic.php +++ b/app/Console/Commands/excel/Generic.php @@ -9,29 +9,41 @@ class Generic extends Command { + /** + * The name and signature of the console command. + * + * @var string + */ protected $signature = 'excel:generic'; + + /** + * The console command description. + * + * @var string + */ protected $description = 'Generic Excel Importer'; + /** + * Create a new command instance. + * + * @return void + */ + public function __construct() + { + parent::__construct(); + } + + /** + * Execute the console command. + */ public function handle(): void { Log::info('Loading Generic Excel'); - // Load rows to determine the actual count (only the first sheet) - $collection = Excel::toCollection(new GenericEventsImport($this->output), 'example.xlsx', 'excel'); - $rows = $collection->first(); - $rowCount = $rows->count(); - - $this->info("Rows to import: {$rowCount}"); - - // Re-run with row count and output for progress tracking - $importer = new GenericEventsImport($this->output, $rowCount); - Excel::import( - $importer, + new GenericEventsImport(), 'example.xlsx', 'excel' ); - - $this->info("✅ Import completed successfully."); } -} +} \ No newline at end of file diff --git a/app/Imports/GenericEventsImport.php b/app/Imports/GenericEventsImport.php index 33c266799..b24df3afa 100644 --- a/app/Imports/GenericEventsImport.php +++ b/app/Imports/GenericEventsImport.php @@ -12,34 +12,9 @@ use Maatwebsite\Excel\Concerns\WithHeadingRow; use PhpOffice\PhpSpreadsheet\Cell\DefaultValueBinder; use PhpOffice\PhpSpreadsheet\Shared\Date; -use Symfony\Component\Console\Output\OutputInterface; -use Symfony\Component\Console\Helper\ProgressBar; class GenericEventsImport extends DefaultValueBinder implements ToModel, WithCustomValueBinder, WithHeadingRow { - protected $output; - protected $progressBar; - protected $total; - - public function __construct(?OutputInterface $output = null, int $total = 0) - { - $this->output = $output; - $this->total = $total; - - if ($this->output && $total > 0) { - $this->progressBar = new ProgressBar($this->output, $total); - $this->progressBar->start(); - } - } - - public function __destruct() - { - if ($this->progressBar) { - $this->progressBar->finish(); - $this->output->writeln("\nImport complete."); - } - } - public function parseDate($value) { // Handle Excel dates or normal string dates @@ -59,13 +34,6 @@ public function parseDate($value) public function model(array $row): ?Model { Log::info('Importing row:', $row); - if ($this->progressBar) { - $this->progressBar->advance(); - } - - if (!empty($row['activity_title']) && $this->output) { - $this->output->writeln(" Imported: " . $row['activity_title']); - } // Validate required fields if (