Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1634 | Revision 1636 | Zur aktuellen Revision | Details | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

Revision Autor Zeilennr. Zeile
151 lars 1
<?php
2
 
1623 lars 3
    namespace App\Console\Commands;
151 lars 4
 
1623 lars 5
    use Illuminate\Console\Command;
1635 lars 6
    use App\Models\Item;
1623 lars 7
    use App\Models\PriceAgency;
151 lars 8
 
1623 lars 9
    class dump extends Command
10
    {
11
        /**
12
         * The name and signature of the console command.
13
         *
14
         * @var string
15
         */
16
        protected $signature = 'command:dump';
151 lars 17
 
1623 lars 18
        /**
19
         * The console command description.
20
         *
21
         * @var string
22
         */
23
        protected $description = 'Erstellt CSV-Dateien für Preisagenturen';
151 lars 24
 
1623 lars 25
        /**
26
         * Execute the console command.
27
         *
1634 lars 28
         * @return void
1623 lars 29
         */
1634 lars 30
        public function handle(): void
1623 lars 31
        {
1634 lars 32
            $items = Item::with( 'price', 'medium.medium', "manufacturer" )->where( 'status', 0 )->get();
1633 lars 33
            $agencies = PriceAgency::where( 'shop_id', $GLOBALS["INI"]["shops_ID"] )->where( "status", "1" )->get();
1623 lars 34
            foreach ( $agencies as $agency )
35
            {
1634 lars 36
                $content = array();
1623 lars 37
                $this->info( $agency["name"] );
1631 lars 38
                if ( !$agency["config"] )
39
                {
40
                    $this->warn( "Agentur nicht komplett konfiguriert!" );
1632 lars 41
                    continue;
1631 lars 42
                }
1630 lars 43
                $configFile = storage_path( "config/" ) . $agency["config"];
44
                if ( file_exists( $configFile ) )
45
                {
46
                    require $configFile;
47
                }
48
                else
49
                {
50
                    $this->error( "Konfigdatei " . $configFile . " existiert nicht!" );
1634 lars 51
                    continue;
1630 lars 52
                }
1634 lars 53
                $fName = basename( parse_url( $agency["csv_url"], PHP_URL_PATH ) );
54
                $fName = storage_path() . "/" . $fName;
55
                $f = fopen( $fName, "w" );
56
                foreach ( $items as $item )
57
                {
58
                    foreach ( $content as $c )
59
                    {
60
                        list( $col, $required ) = $c;
61
 
62
                        // Inhalt ist vorhanden oder muss ausgewertet werden?
63
                        if ( isset( $item->$col ) )
64
                        {
65
                            $col = $item->$col;
66
                        }
67
                        elseif ( !stristr( $col, "return" ) )
68
                        {
69
                            $col = "";
70
                        }
71
                        else
72
                        {
73
                            $col = @eval( $col );
74
                        }
75
 
76
                        // Inhalt mit required vergleichen
77
                        /*
78
                        required
79
                        true: Wert muss vorhanden sein
80
                        false: Wert muss nicht vorhanden sein
81
                        string: Ausdruck muss string ergeben
82
                        */
83
 
84
                        if ( is_bool( $required ) )
85
                        {
86
                            if ( ( $required === true ) && ( !$col ) )
87
                            {
88
                                continue 2;
89
                            }
90
                        }
91
                        else
92
                        {
93
                            if ( !@eval( $required ) )
94
                            {
95
                                continue 2;
96
                            }
97
                        }
98
 
99
                        $buffer[] = $quote . $col . $quote;
100
                    } // foreach
101
                    fwrite( $f, implode( $trenner, $buffer ) . "\n" );
102
                }
103
                fclose( $f );
1623 lars 104
            }
105
        }
151 lars 106
    }