Revision 245 | Revision 264 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed
<?phpnamespace App\Console\Commands;use App\Models\Directory;use App\Models\Item;use App\Models\Action;use App\Models\ActionMedium;use App\Models\ItemMedium;use App\Models\DirectoryMedium;use Illuminate\Console\Command;use Illuminate\Support\Facades\DB;class convertDB extends Command{/*** The name and signature of the console command.** @var string*/protected $signature = 'command:convertDB';/*** The console command description.** @var string*/protected $description = 'Converts the old webanOS-DB to laravel';/*** Execute the console command.** @return void*/public function handle(): void{$this->migrateDirs();$this->migrateItems();$this->migrateActions();}private function migrateDirs(){$this->info( "Migriere Kategorien" );$sql = 'SELECT*FROMdirectory';$dirs = DB::connection( 'old' )->select( $sql );foreach ( $dirs as $row ){//var_dump($row);Directory::factory()->createQuietly( ["id" => $row->ID,"directory_id" => $row->Father,"name" => $row->Name,"status" => $row->status,"kennung" => $row->Kennung,"description" => $row->Beschreibung,"short_line_1" => $row->short_line_1,"url" => $row->url,"created_at" => $row->erstellt_am,"updated_at" => $row->letzte_Aenderung_am,] );}}private function migrateItems(){$this->info( "Migriere Artikel" );$sql = 'SELECT*FROMartikelWHEREfather>=-1';$dirs = DB::connection( 'old' )->select( $sql );foreach ( $dirs as $row ){$dir = new Item();$dir->id = $row->ID;$dir->directory_id = $row->Father;$dir->name = $row->kurzbezeichnung;$dir->status = $row->status;$dir->kennung = $row->kennung;$dir->description = $row->beschreibung;$dir->created_at = $row->erstellt_am;$dir->updated_at = $row->letzte_Aenderung_am;$dir->save();}$sql = "SELECTp.*FROMpreise pJOINartikel aONa.id=p.artikel_idWHEREa.father >=-1";$prices = DB::connection( 'old' )->select( $sql );foreach ( $prices as $price ){Price::factory()->createQuietly( ["item_id" => $price->artikel_id,"preis_index" => $price->preis_index,"preis" => $price->preis,"staffel" => $price->staffel,"created_at" => $price->geaendert_am,"updated_at" => $price->geaendert_am] );}}private function migrateActions(){$sql = "SELECT*FROMAktionen";$actions = DB::connection( 'old' )->select( $sql );foreach ( $actions as $action ){$actionDB = new Action();$actionDB->id = $action->ID;$actionDB->headline = $action->headline;$actionDB->text = $action->text;$actionDB->rang = $action->rang;$actionDB->config = $action->config;$actionDB->category = $action->kategorie;$actionDB->notes = $action->notizen;$actionDB->valid_from = $action->von;$actionDB->valid_to = $action->bis;}}}