Subversion-Projekte lars-tiefland.laravel_shop

Revision

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