Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 275 | Revision 277 | 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,
69
                    "updated_at"   => $row->letzte_Aenderung_am,
70
                ] );
71
            }
72
        }
73
 
74
        private function migrateItems()
75
        {
76
            $this->info( "Migriere Artikel" );
77
            $sql = '
78
                SELECT
79
                    *
80
                FROM
81
                    artikel
82
                WHERE
83
                    father>=-1
84
            ';
85
            $dirs = DB::connection( 'old' )->select( $sql );
86
            foreach ( $dirs as $row )
87
            {
88
                $dir = new Item();
89
                $dir->id = $row->ID;
90
                $dir->directory_id = $row->Father;
91
                $dir->name = $row->kurzbezeichnung;
92
                $dir->status = $row->status;
93
                $dir->kennung = $row->kennung;
94
                $dir->description = $row->beschreibung;
95
                $dir->created_at = $row->erstellt_am;
96
                $dir->updated_at = $row->letzte_Aenderung_am;
97
                $dir->save();
98
            }
99
            $sql = "
100
                SELECT
101
                    p.*
102
                FROM
103
                    preise p
104
                JOIN
105
                    artikel a
106
                ON
107
                    a.id=p.artikel_id
108
                WHERE
109
                    a.father >=-1
110
            ";
111
            $prices = DB::connection( 'old' )->select( $sql );
112
            foreach ( $prices as $price )
113
            {
114
                Price::factory()->createQuietly( [
115
                    "item_id"     => $price->artikel_id,
116
                    "preis_index" => $price->preis_index,
117
                    "preis"       => $price->preis,
118
                    "staffel"     => $price->staffel,
119
                    "created_at"  => $price->geaendert_am,
120
                    "updated_at"  => $price->geaendert_am
121
                ] );
122
            }
123
 
124
        }
125
 
126
        private function migrateActions()
127
        {
272 lars 128
            $this->info( "Migriere Aktionen" );
260 lars 129
            $sql = "
130
                SELECT
131
                    *
132
                FROM
133
                    Aktionen
134
            ";
135
            $actions = DB::connection( 'old' )->select( $sql );
136
            foreach ( $actions as $action )
137
            {
138
                $actionDB = new Action();
139
                $actionDB->id = $action->ID;
140
                $actionDB->headline = $action->headline;
141
                $actionDB->text = $action->text;
142
                $actionDB->rang = $action->rang;
143
                $actionDB->config = $action->config;
264 lars 144
                $actionDB->category = $action->Kategorie;
260 lars 145
                $actionDB->notes = $action->notizen;
146
                $actionDB->valid_from = $action->von;
147
                $actionDB->valid_to = $action->bis;
265 lars 148
                $actionDB->save();
260 lars 149
            }
150
        }
272 lars 151
 
152
        public function migrateMedia()
153
        {
154
            $this->info( "Migriere Medien" );
155
            $sql = "
156
                SELECT
157
                    *
158
                FROM
159
                    medien
160
            ";
161
            $media = DB::connection( 'old' )->select( $sql );
162
            foreach ( $media as $medium )
163
            {
164
                $mediumDB = new Medium();
165
                $mediumDB->id = $medium->id;
166
                $mediumDB->name = $medium->name;
167
                $mediumDB->folder = $medium->folder;
273 lars 168
                $mediumDB->medium_type_id = $medium->typ;
272 lars 169
                $mediumDB->description = $medium->beschreibung;
275 lars 170
                $mediumDB->created_at = date( "Y-m-d H:i:s", $medium->erstellt_am );
276 lars 171
                $mediumDB->updated_at = $medium->letzte_aenderung_am;
272 lars 172
                $mediumDB->save();
173
            }
174
        }
233 lars 175
    }