Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 280 | Revision 282 | 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;
281 lars 99
                if ( $row->erstellt_von )
100
                {
101
                    $dir->created_by = $row->erstellt_von;
102
                }
103
                if ( $row->letzte_Aenderung_von )
104
                {
105
                    $dir->updated_by = $row->letzte_Aenderung_von;
106
                }
260 lars 107
                $dir->save();
108
            }
109
            $sql = "
110
                SELECT
111
                    p.*
112
                FROM
113
                    preise p
114
                JOIN
115
                    artikel a
116
                ON
117
                    a.id=p.artikel_id
118
                WHERE
119
                    a.father >=-1
120
            ";
121
            $prices = DB::connection( 'old' )->select( $sql );
122
            foreach ( $prices as $price )
123
            {
124
                Price::factory()->createQuietly( [
125
                    "item_id"     => $price->artikel_id,
126
                    "preis_index" => $price->preis_index,
127
                    "preis"       => $price->preis,
128
                    "staffel"     => $price->staffel,
129
                    "created_at"  => $price->geaendert_am,
281 lars 130
                    "created_by"  => $price->erstellt_von,
131
                    "updated_by"  => $price->letzte_Aenderung_von,
260 lars 132
                    "updated_at"  => $price->geaendert_am
133
                ] );
134
            }
135
 
136
        }
137
 
138
        private function migrateActions()
139
        {
272 lars 140
            $this->info( "Migriere Aktionen" );
260 lars 141
            $sql = "
142
                SELECT
143
                    *
144
                FROM
145
                    Aktionen
146
            ";
147
            $actions = DB::connection( 'old' )->select( $sql );
148
            foreach ( $actions as $action )
149
            {
150
                $actionDB = new Action();
151
                $actionDB->id = $action->ID;
152
                $actionDB->headline = $action->headline;
153
                $actionDB->text = $action->text;
154
                $actionDB->rang = $action->rang;
155
                $actionDB->config = $action->config;
264 lars 156
                $actionDB->category = $action->Kategorie;
260 lars 157
                $actionDB->notes = $action->notizen;
158
                $actionDB->valid_from = $action->von;
159
                $actionDB->valid_to = $action->bis;
281 lars 160
                if ( $action->erstellt_von )
161
                {
162
                    $actionDB->created_by = $action->erstellt_von;
163
                }
164
                if ( $action->letzte_Aenderung_von )
165
                {
166
                    $actionDB->updated_by = $action->letzte_Aenderung_von;
167
                }
265 lars 168
                $actionDB->save();
260 lars 169
            }
170
        }
272 lars 171
 
172
        public function migrateMedia()
173
        {
174
            $this->info( "Migriere Medien" );
175
            $sql = "
176
                SELECT
177
                    *
178
                FROM
179
                    medien
180
            ";
181
            $media = DB::connection( 'old' )->select( $sql );
182
            foreach ( $media as $medium )
183
            {
184
                $mediumDB = new Medium();
185
                $mediumDB->id = $medium->id;
186
                $mediumDB->name = $medium->name;
187
                $mediumDB->folder = $medium->folder;
273 lars 188
                $mediumDB->medium_type_id = $medium->typ;
272 lars 189
                $mediumDB->description = $medium->beschreibung;
277 lars 190
                if ( $medium->erstellt_am )
191
                {
192
                    $mediumDB->created_at = date( "Y-m-d H:i:s", $medium->erstellt_am );
193
                }
281 lars 194
                $ersteller = $medium->erstellt_von;
195
                if ( !$ersteller )
196
                {
197
                    $ersteller = "WebanOS Laravel Upgrade";
198
                }
199
                $bearbeiter = $medium->letzte_aenderung_von;
200
                if ( !$bearbeiter )
201
                {
202
                    $bearbeiter = "WebanOS Laravel Upgrade";
203
                }
204
                $mediumDB->created_by = $ersteller;
205
                $mediumDB->updated_by = $bearbeiter;
272 lars 206
                $mediumDB->save();
207
            }
208
        }
233 lars 209
    }