Subversion-Projekte lars-tiefland.laravel_shop

Revision

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