Subversion-Projekte lars-tiefland.laravel_shop

Revision

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