From 0fbbc26ab67e88a3ec0af33742d1fe35233243a2 Mon Sep 17 00:00:00 2001 From: objecttothis Date: Tue, 19 Mar 2024 11:20:49 +0400 Subject: [PATCH] Convert Barcode to new Types --- ...000000_Migration_Convert_Barcode_Types.php | 77 +++++++++++++++++++ 1 file changed, 77 insertions(+) create mode 100644 app/Database/Migrations/20240319000000_Migration_Convert_Barcode_Types.php diff --git a/app/Database/Migrations/20240319000000_Migration_Convert_Barcode_Types.php b/app/Database/Migrations/20240319000000_Migration_Convert_Barcode_Types.php new file mode 100644 index 000000000..f05d83c58 --- /dev/null +++ b/app/Database/Migrations/20240319000000_Migration_Convert_Barcode_Types.php @@ -0,0 +1,77 @@ +appconfig = model(Appconfig::class); + $this->config = config(OSPOS::class)->settings; + + parent::__construct($forge); + } + + /** + * Perform a migration step. + */ + public function up(): void + { + + $old_barcode_type = $this->config['barcode_type']; + + switch($old_barcode_type) + { + case 'Code39': + $new_barcode_type = 'C39'; + break; + case 'Ean13': + $new_barcode_type = 'EAN13'; + break; + case 'Ean8': + $new_barcode_type = 'EAN8'; + break; + default: + case 'Code128': + $new_barcode_type = 'C128'; + break; + } + + $this->appconfig->save(['barcode_type' => $new_barcode_type]); + } + + /** + * Revert a migration step. + */ + public function down(): void + { + $new_barcode_type = $this->config['barcode_type']; + + switch($new_barcode_type) + { + case 'C39': + $old_barcode_type = 'Code39'; + break; + case 'EAN13': + $old_barcode_type = 'Ean13'; + break; + case 'EAN8': + $old_barcode_type = 'Ean8'; + break; + default: + case 'C128': + $old_barcode_type = 'Code128'; + break; + } + + $this->appconfig->save(['barcode_type' => $old_barcode_type]); + } +}