| 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" );
|
| 1639 |
lars |
56 |
if ( $prefix )
|
|
|
57 |
{
|
|
|
58 |
fwrite( $f, $prefix . "\n" );
|
|
|
59 |
}
|
| 1634 |
lars |
60 |
foreach ( $items as $item )
|
|
|
61 |
{
|
| 1639 |
lars |
62 |
$buffer = array();
|
| 1636 |
lars |
63 |
$item->beschreibung_pagentur = $item->description;
|
|
|
64 |
$item->beschreibung_pagentur = str_replace( " ", " ", $item->beschreibung_pagentur );
|
|
|
65 |
$item->beschreibung_pagentur = str_replace( "<p>", " ", $item->beschreibung_pagentur );
|
|
|
66 |
$item->beschreibung_pagentur = str_replace( "</p>", " ", $item->beschreibung_pagentur );
|
|
|
67 |
$item->beschreibung_pagentur = str_replace( "<li>", "", $item->beschreibung_pagentur );
|
|
|
68 |
$item->beschreibung_pagentur = str_replace( "</li>", ", ", $item->beschreibung_pagentur );
|
|
|
69 |
$item->beschreibung_pagentur = str_replace( "</td>\r\n", "</td>", $item->beschreibung_pagentur );
|
|
|
70 |
$item->beschreibung_pagentur = str_replace( "</tr>\r\n", "</tr>", $item->beschreibung_pagentur );
|
|
|
71 |
$item->beschreibung_pagentur = str_replace( "<tr>\r\n", "<tr>", $item->beschreibung_pagentur );
|
|
|
72 |
$item->beschreibung_pagentur = str_replace( "<td>\r\n", "<td>", $item->beschreibung_pagentur );
|
|
|
73 |
$item->beschreibung_pagentur = str_replace( "</td>\n", "</td>", $item->beschreibung_pagentur );
|
|
|
74 |
$item->beschreibung_pagentur = str_replace( "</tr>\n", "</tr>", $item->beschreibung_pagentur );
|
|
|
75 |
$item->beschreibung_pagentur = str_replace( "<tr>\n", "<tr>", $item->beschreibung_pagentur );
|
|
|
76 |
$item->beschreibung_pagentur = str_replace( "<td>\n", "<td>", $item->beschreibung_pagentur );
|
|
|
77 |
$item->beschreibung_pagentur = str_replace( "</td></tr><tr><td>", " / ", $item->beschreibung_pagentur );
|
|
|
78 |
$item->beschreibung_pagentur = str_replace( "</td><td>", " - ", $item->beschreibung_pagentur );
|
|
|
79 |
$item->beschreibung_pagentur = str_replace( "<td>", "", $item->beschreibung_pagentur );
|
|
|
80 |
$item->beschreibung_pagentur = str_replace( "</td>", ", ", $item->beschreibung_pagentur );
|
|
|
81 |
$item->beschreibung_pagentur = str_replace( '"', '', preg_replace( "/[\r\n\t" . $trenner . "]/", "", strip_tags( $item->beschreibung_pagentur ) ) );
|
|
|
82 |
$item->beschreibung_pagentur = rtrim( $item->beschreibung_pagentur, ", " );
|
| 1637 |
lars |
83 |
//$item->beschreibung_pagentur = removeSpaces( $item->beschreibung_pagentur, true, true, false );
|
| 1636 |
lars |
84 |
$item->beschreibung_pagentur = preg_replace( "/[\s]{2,}/", " ", $item->beschreibung_pagentur );
|
|
|
85 |
$artikel["kurzbeschreibung_pagentur"] = substr( $item->beschreibung_pagentur, 0, 200 );
|
| 1638 |
lars |
86 |
$item->beschreibung_pagentur = substr( $item->beschreibung_pagentur, 0, 5000 );
|
| 1634 |
lars |
87 |
foreach ( $content as $c )
|
|
|
88 |
{
|
|
|
89 |
list( $col, $required ) = $c;
|
|
|
90 |
|
|
|
91 |
// Inhalt ist vorhanden oder muss ausgewertet werden?
|
|
|
92 |
if ( isset( $item->$col ) )
|
|
|
93 |
{
|
|
|
94 |
$col = $item->$col;
|
|
|
95 |
}
|
|
|
96 |
elseif ( !stristr( $col, "return" ) )
|
|
|
97 |
{
|
|
|
98 |
$col = "";
|
|
|
99 |
}
|
|
|
100 |
else
|
|
|
101 |
{
|
|
|
102 |
$col = @eval( $col );
|
|
|
103 |
}
|
|
|
104 |
|
|
|
105 |
// Inhalt mit required vergleichen
|
|
|
106 |
/*
|
|
|
107 |
required
|
|
|
108 |
true: Wert muss vorhanden sein
|
|
|
109 |
false: Wert muss nicht vorhanden sein
|
|
|
110 |
string: Ausdruck muss string ergeben
|
|
|
111 |
*/
|
|
|
112 |
|
|
|
113 |
if ( is_bool( $required ) )
|
|
|
114 |
{
|
|
|
115 |
if ( ( $required === true ) && ( !$col ) )
|
|
|
116 |
{
|
|
|
117 |
continue 2;
|
|
|
118 |
}
|
|
|
119 |
}
|
|
|
120 |
else
|
|
|
121 |
{
|
|
|
122 |
if ( !@eval( $required ) )
|
|
|
123 |
{
|
|
|
124 |
continue 2;
|
|
|
125 |
}
|
|
|
126 |
}
|
|
|
127 |
|
|
|
128 |
$buffer[] = $quote . $col . $quote;
|
|
|
129 |
} // foreach
|
|
|
130 |
fwrite( $f, implode( $trenner, $buffer ) . "\n" );
|
|
|
131 |
}
|
|
|
132 |
fclose( $f );
|
| 1623 |
lars |
133 |
}
|
|
|
134 |
}
|
| 151 |
lars |
135 |
}
|