Subversion-Projekte lars-tiefland.laravel_shop

Revision

Revision 1633 | Revision 1635 | Zur aktuellen Revision | Blame | Vergleich mit vorheriger | Letzte Änderung | Log anzeigen | RSS feed

<?php

    namespace App\Console\Commands;

    use Illuminate\Console\Command;
    use App\Models\PriceAgency;

    class dump extends Command
    {
        /**
         * The name and signature of the console command.
         *
         * @var string
         */
        protected $signature = 'command:dump';

        /**
         * The console command description.
         *
         * @var string
         */
        protected $description = 'Erstellt CSV-Dateien für Preisagenturen';

        /**
         * Execute the console command.
         *
         * @return void
         */
        public function handle(): void
        {
            $items = Item::with( 'price', 'medium.medium', "manufacturer" )->where( 'status', 0 )->get();
            $agencies = PriceAgency::where( 'shop_id', $GLOBALS["INI"]["shops_ID"] )->where( "status", "1" )->get();
            foreach ( $agencies as $agency )
            {
                $content = array();
                $this->info( $agency["name"] );
                if ( !$agency["config"] )
                {
                    $this->warn( "Agentur nicht komplett konfiguriert!" );
                    continue;
                }
                $configFile = storage_path( "config/" ) . $agency["config"];
                if ( file_exists( $configFile ) )
                {
                    require $configFile;
                }
                else
                {
                    $this->error( "Konfigdatei " . $configFile . " existiert nicht!" );
                    continue;
                }
                $fName = basename( parse_url( $agency["csv_url"], PHP_URL_PATH ) );
                $fName = storage_path() . "/" . $fName;
                $f = fopen( $fName, "w" );
                foreach ( $items as $item )
                {
                    foreach ( $content as $c )
                    {
                        list( $col, $required ) = $c;

                        // Inhalt ist vorhanden oder muss ausgewertet werden?
                        if ( isset( $item->$col ) )
                        {
                            $col = $item->$col;
                        }
                        elseif ( !stristr( $col, "return" ) )
                        {
                            $col = "";
                        }
                        else
                        {
                            $col = @eval( $col );
                        }

                        // Inhalt mit required vergleichen
                        /*
                        required
                        true: Wert muss vorhanden sein
                        false: Wert muss nicht vorhanden sein
                        string: Ausdruck muss string ergeben
                        */

                        if ( is_bool( $required ) )
                        {
                            if ( ( $required === true ) && ( !$col ) )
                            {
                                continue 2;
                            }
                        }
                        else
                        {
                            if ( !@eval( $required ) )
                            {
                                continue 2;
                            }
                        }

                        $buffer[] = $quote . $col . $quote;
                    } // foreach
                    fwrite( $f, implode( $trenner, $buffer ) . "\n" );
                }
                fclose( $f );
            }
        }
    }