Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 245 | Revision 263 | Zur aktuellen Revision | Ganze Datei anzeigen | Leerzeichen ignorieren | Details | Blame | Letzte Änderung | Log anzeigen | RSS feed

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