Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 245 | Revision 263 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
233 lars 1
<?php
2
 
260 lars 3
    namespace App\Console\Commands;
233 lars 4
 
260 lars 5
    use App\Models\Directory;
6
    use App\Models\Item;
7
    use App\Models\Action;
8
    use App\Models\ActionMedium;
9
    use App\Models\ItemMedium;
10
    use App\Models\DirectoryMedium;
11
    use Illuminate\Console\Command;
12
    use Illuminate\Support\Facades\DB;
233 lars 13
 
260 lars 14
    class convertDB extends Command
15
    {
16
        /**
17
         * The name and signature of the console command.
18
         *
19
         * @var string
20
         */
21
        protected $signature = 'command:convertDB';
233 lars 22
 
260 lars 23
        /**
24
         * The console command description.
25
         *
26
         * @var string
27
         */
28
        protected $description = 'Converts the old webanOS-DB to laravel';
233 lars 29
 
260 lars 30
        /**
31
         * Execute the console command.
32
         *
33
         * @return void
34
         */
35
 
36
        public function handle(): void
238 lars 37
        {
260 lars 38
            $this->migrateDirs();
39
            $this->migrateItems();
40
            $this->migrateActions();
234 lars 41
        }
260 lars 42
 
43
        private function migrateDirs()
44
        {
45
            $this->info( "Migriere Kategorien" );
46
            $sql = '
47
                SELECT
48
                    *
49
                FROM
50
                    directory
51
            ';
52
            $dirs = DB::connection( 'old' )->select( $sql );
53
            foreach ( $dirs as $row )
54
            {
55
                //var_dump($row);
56
                Directory::factory()->createQuietly( [
57
                    "id"           => $row->ID,
58
                    "directory_id" => $row->Father,
59
                    "name"         => $row->Name,
60
                    "status"       => $row->status,
61
                    "kennung"      => $row->Kennung,
62
                    "description"  => $row->Beschreibung,
63
                    "short_line_1" => $row->short_line_1,
64
                    "url"          => $row->url,
65
                    "created_at"   => $row->erstellt_am,
66
                    "updated_at"   => $row->letzte_Aenderung_am,
67
                ] );
68
            }
69
        }
70
 
71
        private function migrateItems()
72
        {
73
            $this->info( "Migriere Artikel" );
74
            $sql = '
75
                SELECT
76
                    *
77
                FROM
78
                    artikel
79
                WHERE
80
                    father>=-1
81
            ';
82
            $dirs = DB::connection( 'old' )->select( $sql );
83
            foreach ( $dirs as $row )
84
            {
85
                $dir = new Item();
86
                $dir->id = $row->ID;
87
                $dir->directory_id = $row->Father;
88
                $dir->name = $row->kurzbezeichnung;
89
                $dir->status = $row->status;
90
                $dir->kennung = $row->kennung;
91
                $dir->description = $row->beschreibung;
92
                $dir->created_at = $row->erstellt_am;
93
                $dir->updated_at = $row->letzte_Aenderung_am;
94
                $dir->save();
95
            }
96
            $sql = "
97
                SELECT
98
                    p.*
99
                FROM
100
                    preise p
101
                JOIN
102
                    artikel a
103
                ON
104
                    a.id=p.artikel_id
105
                WHERE
106
                    a.father >=-1
107
            ";
108
            $prices = DB::connection( 'old' )->select( $sql );
109
            foreach ( $prices as $price )
110
            {
111
                Price::factory()->createQuietly( [
112
                    "item_id"     => $price->artikel_id,
113
                    "preis_index" => $price->preis_index,
114
                    "preis"       => $price->preis,
115
                    "staffel"     => $price->staffel,
116
                    "created_at"  => $price->geaendert_am,
117
                    "updated_at"  => $price->geaendert_am
118
                ] );
119
            }
120
 
121
        }
122
 
123
        private function migrateActions()
124
        {
125
            $sql = "
126
                SELECT
127
                    *
128
                FROM
129
                    Aktionen
130
            ";
131
            $actions = DB::connection( 'old' )->select( $sql );
132
            foreach ( $actions as $action )
133
            {
134
                $actionDB = new Action();
135
                $actionDB->id = $action->ID;
136
                $actionDB->headline = $action->headline;
137
                $actionDB->text = $action->text;
138
                $actionDB->rang = $action->rang;
139
                $actionDB->config = $action->config;
140
                $actionDB->category = $action->kategorie;
141
                $actionDB->notes = $action->notizen;
142
                $actionDB->valid_from = $action->von;
143
                $actionDB->valid_to = $action->bis;
144
            }
145
        }
233 lars 146
    }