configWriter = $configWriter; $this->scopeConfig = $scopeConfig; $this->json = $json; } public function upgrade(ModuleDataSetupInterface $setup, ModuleContextInterface $context) { $setup->startSetup(); // Migrate from old individual fields to new dynamic rows format if (version_compare($context->getVersion(), '1.1.0', '<')) { $this->migrateToVendorMapping(); } $setup->endSetup(); } /** * Migrate old configuration to new vendor mapping format */ protected function migrateToVendorMapping() { // Define the old configuration paths and their corresponding vendor names $oldConfigs = [ 'vendor_notes/general/thermo_fisher_note' => 'Thermo Fisher', 'vendor_notes/general/orion_note' => 'Orion', 'vendor_notes/general/nalgene_note' => 'Nalgene', 'vendor_notes/general/thermo_fisher_parts_note' => 'Thermo Fisher Parts' ]; $vendorMapping = []; foreach ($oldConfigs as $configPath => $vendorName) { $note = $this->scopeConfig->getValue($configPath); if ($note) { $vendorMapping[] = [ 'vendor_name' => $vendorName, 'note' => $note ]; } } // Save the new mapping if we have data if (!empty($vendorMapping)) { $serializedMapping = $this->json->serialize($vendorMapping); $this->configWriter->save( 'vendor_notes/general/vendor_mapping', $serializedMapping ); } } }