diff --git a/app/Console/Commands/ImportNewInstitutionCaps.php b/app/Console/Commands/ImportNewInstitutionCaps.php new file mode 100644 index 00000000..201aff75 --- /dev/null +++ b/app/Console/Commands/ImportNewInstitutionCaps.php @@ -0,0 +1,68 @@ +argument('file'); + + if (!file_exists($file)) { + $this->error("File does not exist: $file"); + return 1; + } + + $csv = Reader::createFromPath($file, 'r'); + $csv->setHeaderOffset(0); + + $records = $csv->getRecords(); + + foreach ($records as $record) { + try { + // Remove any hyphens that could be exist in the csv file provided + $guid = str_replace('-', '', $record['guid']); + + Cap::create([ + 'guid' => $guid, + 'fed_cap_guid' => $record['fed_cap_guid'], + 'institution_guid' => $record['institution_guid'], + 'start_date' => $record['start_date'], + 'end_date' => $record['end_date'], + 'total_attestations' => $record['total_attestations'], + 'active_status' => TRUE, + 'confirmed' => TRUE, + 'total_reserved_graduate_attestations' => $record['total_reserved_graduate_attestations'], + ]); + + $this->info("Created cap for: {$record['guid']}"); + } catch (\Exception $e) { + $this->error("Error processing record for {$record['guid']}: " . $e->getMessage()); + } + } + + $this->info('Data import completed.'); + return 0; + } +}