Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 281 | Revision 283 | 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;
272 lars 8
    use App\Models\Medium;
263 lars 9
    use App\Models\Price;
260 lars 10
    use App\Models\ActionMedium;
11
    use App\Models\ItemMedium;
12
    use App\Models\DirectoryMedium;
13
    use Illuminate\Console\Command;
14
    use Illuminate\Support\Facades\DB;
233 lars 15
 
260 lars 16
    class convertDB extends Command
17
    {
18
        /**
19
         * The name and signature of the console command.
20
         *
21
         * @var string
22
         */
23
        protected $signature = 'command:convertDB';
233 lars 24
 
260 lars 25
        /**
26
         * The console command description.
27
         *
28
         * @var string
29
         */
30
        protected $description = 'Converts the old webanOS-DB to laravel';
233 lars 31
 
260 lars 32
        /**
33
         * Execute the console command.
34
         *
35
         * @return void
36
         */
37
 
38
        public function handle(): void
238 lars 39
        {
272 lars 40
            $this->migrateMedia();
260 lars 41
            $this->migrateDirs();
42
            $this->migrateItems();
43
            $this->migrateActions();
234 lars 44
        }
260 lars 45
 
46
        private function migrateDirs()
47
        {
48
            $this->info( "Migriere Kategorien" );
49
            $sql = '
50
                SELECT
51
                    *
52
                FROM
53
                    directory
54
            ';
55
            $dirs = DB::connection( 'old' )->select( $sql );
56
            foreach ( $dirs as $row )
57
            {
58
                //var_dump($row);
59
                Directory::factory()->createQuietly( [
60
                    "id"           => $row->ID,
61
                    "directory_id" => $row->Father,
62
                    "name"         => $row->Name,
63
                    "status"       => $row->status,
64
                    "kennung"      => $row->Kennung,
65
                    "description"  => $row->Beschreibung,
66
                    "short_line_1" => $row->short_line_1,
67
                    "url"          => $row->url,
68
                    "created_at"   => $row->erstellt_am,
279 lars 69
                    "created_by"   => $row->erstellt_von,
70
                    "updated_by"   => $row->letzte_Aenderung_von,
260 lars 71
                    "updated_at"   => $row->letzte_Aenderung_am,
72
                ] );
73
            }
74
        }
75
 
76
        private function migrateItems()
77
        {
78
            $this->info( "Migriere Artikel" );
79
            $sql = '
80
                SELECT
81
                    *
82
                FROM
83
                    artikel
84
                WHERE
85
                    father>=-1
86
            ';
87
            $dirs = DB::connection( 'old' )->select( $sql );
88
            foreach ( $dirs as $row )
89
            {
90
                $dir = new Item();
91
                $dir->id = $row->ID;
92
                $dir->directory_id = $row->Father;
93
                $dir->name = $row->kurzbezeichnung;
94
                $dir->status = $row->status;
95
                $dir->kennung = $row->kennung;
96
                $dir->description = $row->beschreibung;
97
                $dir->created_at = $row->erstellt_am;
98
                $dir->updated_at = $row->letzte_Aenderung_am;
282 lars 99
                $ersteller = $medium->erstellt_von;
100
                if ( !$ersteller )
281 lars 101
                {
282 lars 102
                    $ersteller = "WebanOS Laravel Upgrade";
281 lars 103
                }
282 lars 104
                $bearbeiter = $medium->letzte_aenderung_von;
105
                if ( !$bearbeiter )
281 lars 106
                {
282 lars 107
                    $bearbeiter = "WebanOS Laravel Upgrade";
281 lars 108
                }
282 lars 109
                $dir->created_by = $ersteller;
110
                $dir->updated_by = $bearbeiter;
260 lars 111
                $dir->save();
112
            }
113
            $sql = "
114
                SELECT
115
                    p.*
116
                FROM
117
                    preise p
118
                JOIN
119
                    artikel a
120
                ON
121
                    a.id=p.artikel_id
122
                WHERE
123
                    a.father >=-1
124
            ";
125
            $prices = DB::connection( 'old' )->select( $sql );
126
            foreach ( $prices as $price )
127
            {
128
                Price::factory()->createQuietly( [
129
                    "item_id"     => $price->artikel_id,
130
                    "preis_index" => $price->preis_index,
131
                    "preis"       => $price->preis,
132
                    "staffel"     => $price->staffel,
133
                    "created_at"  => $price->geaendert_am,
281 lars 134
                    "created_by"  => $price->erstellt_von,
135
                    "updated_by"  => $price->letzte_Aenderung_von,
260 lars 136
                    "updated_at"  => $price->geaendert_am
137
                ] );
138
            }
139
 
140
        }
141
 
142
        private function migrateActions()
143
        {
272 lars 144
            $this->info( "Migriere Aktionen" );
260 lars 145
            $sql = "
146
                SELECT
147
                    *
148
                FROM
149
                    Aktionen
150
            ";
151
            $actions = DB::connection( 'old' )->select( $sql );
152
            foreach ( $actions as $action )
153
            {
154
                $actionDB = new Action();
155
                $actionDB->id = $action->ID;
156
                $actionDB->headline = $action->headline;
157
                $actionDB->text = $action->text;
158
                $actionDB->rang = $action->rang;
159
                $actionDB->config = $action->config;
264 lars 160
                $actionDB->category = $action->Kategorie;
260 lars 161
                $actionDB->notes = $action->notizen;
162
                $actionDB->valid_from = $action->von;
163
                $actionDB->valid_to = $action->bis;
281 lars 164
                if ( $action->erstellt_von )
165
                {
166
                    $actionDB->created_by = $action->erstellt_von;
167
                }
168
                if ( $action->letzte_Aenderung_von )
169
                {
170
                    $actionDB->updated_by = $action->letzte_Aenderung_von;
171
                }
265 lars 172
                $actionDB->save();
260 lars 173
            }
174
        }
272 lars 175
 
176
        public function migrateMedia()
177
        {
178
            $this->info( "Migriere Medien" );
179
            $sql = "
180
                SELECT
181
                    *
182
                FROM
183
                    medien
184
            ";
185
            $media = DB::connection( 'old' )->select( $sql );
186
            foreach ( $media as $medium )
187
            {
188
                $mediumDB = new Medium();
189
                $mediumDB->id = $medium->id;
190
                $mediumDB->name = $medium->name;
191
                $mediumDB->folder = $medium->folder;
273 lars 192
                $mediumDB->medium_type_id = $medium->typ;
272 lars 193
                $mediumDB->description = $medium->beschreibung;
277 lars 194
                if ( $medium->erstellt_am )
195
                {
196
                    $mediumDB->created_at = date( "Y-m-d H:i:s", $medium->erstellt_am );
197
                }
281 lars 198
                $ersteller = $medium->erstellt_von;
199
                if ( !$ersteller )
200
                {
201
                    $ersteller = "WebanOS Laravel Upgrade";
202
                }
203
                $bearbeiter = $medium->letzte_aenderung_von;
204
                if ( !$bearbeiter )
205
                {
206
                    $bearbeiter = "WebanOS Laravel Upgrade";
207
                }
208
                $mediumDB->created_by = $ersteller;
209
                $mediumDB->updated_by = $bearbeiter;
272 lars 210
                $mediumDB->save();
211
            }
212
        }
233 lars 213
    }