Skip to content

Commit d1c085b

Browse files
committed
upgrade a laravel 12.
soppresso supporto gdxp xml
1 parent e4d9fec commit d1c085b

26 files changed

Lines changed: 84 additions & 267 deletions

code/app/Console/Commands/ExportSupplier.php

Lines changed: 5 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -9,32 +9,19 @@
99

1010
class ExportSupplier extends Command
1111
{
12-
protected $signature = 'gdxp:write:supplier {supplier_id} {format}';
12+
protected $signature = 'gdxp:write:supplier {supplier_id}';
1313

1414
protected $description = 'Genera il file GDXP per un dato fornitore';
1515

1616
public function handle()
1717
{
1818
$id = $this->argument('supplier_id');
19-
$format = $this->argument('format');
20-
2119
$obj = Supplier::findOrFail($id);
22-
$working_dir = sys_get_temp_dir();
2320

24-
if ($format == 'xml') {
25-
$xml = $obj->exportXML();
26-
chdir($working_dir);
27-
$filename = md5($xml);
28-
file_put_contents($filename, $xml);
29-
30-
$archivepath = sprintf('%s/%s.gdxp', $working_dir, str_replace('/', '_', $obj->printableName()));
31-
zipAll($archivepath, [$filename]);
32-
}
33-
else {
34-
$json = $obj->exportJSON();
35-
$archivepath = sprintf('%s/%s.json', $working_dir, str_replace('/', '_', $obj->printableName()));
36-
file_put_contents($archivepath, $json);
37-
}
21+
$working_dir = sys_get_temp_dir();
22+
$json = $obj->exportJSON();
23+
$archivepath = sprintf('%s/%s.json', $working_dir, str_replace('/', '_', $obj->printableName()));
24+
file_put_contents($archivepath, $json);
3825

3926
$this->info('File creato in ' . $archivepath);
4027
}

code/app/Console/Kernel.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ protected function schedule(Schedule $schedule)
1919
Se si fa qualche modifica nell'elenco di questi comandi, apportare
2020
le stesse modifiche nel suddetto script
2121
*/
22-
if (env('GASDOTTO_NET', false) === false) {
22+
if (config('gasdotto.network', false) === false) {
2323
$schedule->command('check:fees')->daily();
2424
$schedule->command('close:orders')->daily();
2525
$schedule->command('open:orders')->daily();

code/app/Helpers/Files.php

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,8 @@
11
<?php
22

3+
use Illuminate\Support\Str;
4+
use Illuminate\Support\Facades\Log;
5+
36
function localFilePath($obj, $field)
47
{
58
if (! empty($obj->$field)) {
@@ -14,7 +17,7 @@ function localFilePath($obj, $field)
1417

1518
function saveFile($file, $obj, $field)
1619
{
17-
$filename = \Illuminate\Support\Str::random(30);
20+
$filename = Str::random(30);
1821
$file->move(gas_storage_path('app'), $filename);
1922
$obj->$field = sprintf('app/%s', $filename);
2023
$obj->save();
@@ -55,10 +58,11 @@ function downloadFile($obj, $field)
5558

5659
function zipAll($path, $files)
5760
{
58-
$archive = \ezcArchive::open($path, \ezcArchive::ZIP);
61+
$archive = new ZipArchive();
62+
$archive->open($path, ZipArchive::CREATE);
5963

6064
foreach ($files as $f) {
61-
$archive->append([$f], '');
65+
$archive->addFile($f, basename($f));
6266
unlink($f);
6367
}
6468
}

code/app/Helpers/Formatters.php

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -84,36 +84,36 @@ function output_csv($filename, $head, $contents, $format_callback, $out_file = n
8484
$csv_separator = currentAbsoluteGas()->getConfig('csv_separator');
8585

8686
if (is_null($out_file)) {
87-
$FH = fopen('php://output', 'w');
87+
$fh = fopen('php://output', 'w');
8888
}
8989
else {
90-
$FH = fopen($out_file, 'w');
90+
$fh = fopen($out_file, 'w');
9191
}
9292

9393
if ($head) {
94-
fputcsv($FH, $head, $csv_separator);
94+
fputcsv($fh, $head, $csv_separator);
9595
}
9696

9797
if (is_null($format_callback)) {
9898
if (is_string($contents)) {
99-
fwrite($FH, $contents);
99+
fwrite($fh, $contents);
100100
}
101101
elseif (is_array($contents)) {
102102
foreach ($contents as $c) {
103-
fputcsv($FH, $c, $csv_separator);
103+
fputcsv($fh, $c, $csv_separator);
104104
}
105105
}
106106
}
107107
else {
108108
foreach ($contents as $c) {
109109
$row = $format_callback($c);
110110
if ($row) {
111-
fputcsv($FH, $row, $csv_separator);
111+
fputcsv($fh, $row, $csv_separator);
112112
}
113113
}
114114
}
115115

116-
fclose($FH);
116+
fclose($fh);
117117
};
118118

119119
if (is_null($out_file)) {
@@ -258,14 +258,14 @@ function formatAccordionLabel($label, $icon)
258258

259259
function baseEncrypt($string)
260260
{
261-
$key = substr(env('APP_KEY'), 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
261+
$key = substr(config('app.key'), 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
262262
$nonce = random_bytes(SODIUM_CRYPTO_SECRETBOX_NONCEBYTES);
263263
return base64_encode($nonce . sodium_crypto_secretbox($string, $nonce, $key));
264264
}
265265

266266
function baseDecrypt($string)
267267
{
268-
$key = substr(env('APP_KEY'), 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
268+
$key = substr(config('app.key'), 0, SODIUM_CRYPTO_SECRETBOX_KEYBYTES);
269269
$decoded = base64_decode($string);
270270
$nonce = mb_substr($decoded, 0, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, '8bit');
271271
$ciphertext = mb_substr($decoded, SODIUM_CRYPTO_SECRETBOX_NONCEBYTES, null, '8bit');

code/app/Helpers/Paths.php

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ function gas_storage_path($path = null, $folder = false)
99
{
1010
$ret = storage_path();
1111

12-
$local = env('STORAGE_FOLDER', null);
12+
$local = config('gasdotto.storage.folder', null);
1313
if ($local != null) {
1414
$ret .= sprintf('/%s', $local);
1515
}
@@ -18,10 +18,8 @@ function gas_storage_path($path = null, $folder = false)
1818
$ret .= sprintf('/%s', $path);
1919
}
2020

21-
if ($folder) {
22-
if (file_exists($ret) === false) {
23-
mkdir($ret, 0777);
24-
}
21+
if ($folder && file_exists($ret) === false) {
22+
mkdir($ret, 0777);
2523
}
2624

2725
return $ret;
@@ -51,7 +49,7 @@ function env_file()
5149
$instance = substr($_SERVER['HTTP_HOST'], 0, strpos($_SERVER['HTTP_HOST'], '.'));
5250
}
5351
elseif (app()->runningInConsole()) {
54-
$domain = parse_url(env('APP_URL'), PHP_URL_HOST);
52+
$domain = parse_url(config('app.url'), PHP_URL_HOST);
5553
$instance = preg_replace('/^([^\.]*)\.gasdotto\.net.*$/', '\1', $domain);
5654
}
5755

code/app/Http/Controllers/GasController.php

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -196,10 +196,12 @@ public function databaseDump(Request $request)
196196
abort(500);
197197
}
198198

199-
$dumper->setHost(env('DB_HOST'))
200-
->setDbName(env('DB_DATABASE'))
201-
->setUserName(env('DB_USERNAME'))
202-
->setPassword(env('DB_PASSWORD'))
199+
$config_prefix = 'database.' . config('database.default') . '.';
200+
201+
$dumper->setHost(config($config_prefix . 'host'))
202+
->setDbName(config($config_prefix . 'database'))
203+
->setUserName(config($config_prefix . 'username'))
204+
->setPassword(config($config_prefix . 'password'))
203205
->dumpToFile($filepath);
204206

205207
return response()->download($filepath, 'database_gasdotto_' . date('Y_m_d') . '.sql')->deleteFileAfterSend();

code/app/Http/Controllers/ImportController.php

Lines changed: 25 additions & 73 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,10 @@
33
namespace App\Http\Controllers;
44

55
use Illuminate\Http\Request;
6+
use Illuminate\Support\Facades\DB;
7+
use Illuminate\Support\Facades\Log;
8+
use Illuminate\Support\Facades\App;
69

7-
use DB;
8-
use Log;
9-
use App;
10-
11-
use ezcArchive;
1210
use App\Exceptions\MissingFieldException;
1311
use App\Importers\CSV\CSVImporter;
1412
use App\Importers\GDXP\Suppliers;
@@ -33,45 +31,45 @@ public function postCsv(Request $request)
3331
return $this->errorResponse(__('texts.generic.unauthorized'));
3432
}
3533

34+
$return = null;
35+
3636
try {
3737
switch ($step) {
3838
case 'guess':
3939
$parameters = $importer->guess($request);
40-
41-
return view('import.csvsortcolumns', $parameters);
40+
$return = view('import.csvsortcolumns', $parameters);
41+
break;
4242

4343
case 'select':
4444
try {
4545
$parameters = $importer->select($request);
46-
47-
return $importer->formatSelect($parameters);
46+
$return = $importer->formatSelect($parameters);
4847
}
4948
catch (MissingFieldException $e) {
50-
return view('import.csvimportfinal', [
49+
$return = view('import.csvimportfinal', [
5150
'title' => __('texts.imports.help.failure_notice'),
5251
'objects' => [],
5352
'errors' => [$e->getMessage()],
5453
]);
5554
}
5655

56+
break;
57+
5758
case 'run':
5859
$parameters = $importer->run($request);
59-
60-
return view($importer->finalTemplate(), $parameters);
60+
$return = view($importer->finalTemplate(), $parameters);
61+
break;
6162

6263
default:
6364
throw new \InvalidArgumentException('Passaggio non previsto in fase di importazione: ' . $step);
6465
break;
6566
}
6667
}
6768
catch (\Exception $e) {
68-
return $this->errorResponse($e->getMessage());
69+
$return = $this->errorResponse($e->getMessage());
6970
}
7071

71-
return $this->errorResponse(__('texts.imports.help.invalid_command', [
72-
'type' => $type,
73-
'step' => $step,
74-
]));
72+
return $return;
7573
}
7674

7775
public function getGdxp(Request $request)
@@ -81,70 +79,24 @@ public function getGdxp(Request $request)
8179
$obj = $classname::findOrFail($id);
8280

8381
$working_dir = sys_get_temp_dir();
84-
85-
switch ($request->input('format', 'json')) {
86-
case 'xml':
87-
$xml = $obj->exportXML();
88-
89-
chdir($working_dir);
90-
$filename = md5($xml);
91-
file_put_contents($filename, $xml);
92-
93-
$downloadable = sprintf('%s/%s.gdxp', $working_dir, str_replace('/', '_', $obj->printableName()));
94-
$archive = ezcArchive::open('compress.zlib://' . $downloadable, ezcArchive::TAR_USTAR);
95-
$archive->append([$filename], '');
96-
unlink($filename);
97-
break;
98-
99-
case 'json':
100-
default:
101-
$json = $obj->exportJSON();
102-
$downloadable = sprintf('%s/%s.json', $working_dir, str_replace('/', '_', $obj->printableName()));
103-
file_put_contents($downloadable, $json);
104-
break;
105-
}
82+
$json = $obj->exportJSON();
83+
$downloadable = sprintf('%s/%s.json', $working_dir, str_replace('/', '_', $obj->printableName()));
84+
file_put_contents($downloadable, $json);
10685

10786
return response()->download($downloadable)->deleteFileAfterSend(true);
10887
}
10988

11089
private function readGdxpFile($path, $execute, $supplier_replace)
11190
{
112-
$working_dir = sys_get_temp_dir();
113-
11491
$data = [];
115-
$type = mime_content_type($path);
116-
117-
if (in_array($type, ['text/plain', 'application/json'])) {
118-
$info = json_decode(file_get_contents($path));
119-
foreach ($info->blocks as $c) {
120-
if ($execute) {
121-
$data[] = Suppliers::importJSON($info, $c->supplier, $supplier_replace);
122-
}
123-
else {
124-
$data[] = Suppliers::readJSON($c->supplier);
125-
}
126-
}
127-
}
128-
else {
129-
$archive = ezcArchive::open('compress.zlib://' . $path);
130-
while ($archive->valid()) {
131-
$entry = $archive->current();
132-
$archive->extractCurrent($working_dir);
133-
$filepath = sprintf('%s/%s', $working_dir, $entry->getPath());
134-
$contents = file_get_contents($filepath);
135-
$contents = simplexml_load_string($contents);
136-
137-
foreach ($contents->children() as $c) {
138-
if ($execute) {
139-
$data[] = Suppliers::importXML($c, $supplier_replace);
140-
}
141-
else {
142-
$data[] = Suppliers::readXML($c);
143-
}
144-
}
14592

146-
unlink($filepath);
147-
$archive->next();
93+
$info = json_decode(file_get_contents($path));
94+
foreach ($info->blocks as $c) {
95+
if ($execute) {
96+
$data[] = Suppliers::importJSON($info, $c->supplier, $supplier_replace);
97+
}
98+
else {
99+
$data[] = Suppliers::readJSON($c->supplier);
148100
}
149101
}
150102

code/app/Http/Controllers/MailController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ private function registerBounce($event, $email, $message)
5959

6060
public function postStatusScaleway(Request $request)
6161
{
62-
if (env('MAIL_MAILER') == 'scaleway') {
62+
if (config('mail.default') == 'scaleway') {
6363
$message = Message::fromRawPostData();
6464
$validator = new MessageValidator(null, '/\.scw\.cloud$/');
6565

code/app/Http/Middleware/CheckInstall.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@ public function handle($request, Closure $next)
2222
Artisan::call('db:seed', ['--force' => true]);
2323
Artisan::call('db:seed', ['--force' => true, '--class' => 'FirstInstallSeed']);
2424

25-
if (env('GASDOTTO_NET', false) == true) {
25+
if (config('gasdotto.network', false)) {
2626
Artisan::call('db:seed', ['--force' => true, '--class' => 'GasdottoNetSeeder']);
2727
}
2828

code/app/Models/Concerns/ExportableTrait.php

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,6 @@ public function exportableURL()
99
return url('import/gdxp?classname=' . get_class($this) . '&id=' . $this->id);
1010
}
1111

12-
abstract public function exportXML();
13-
1412
abstract public function exportJSON();
1513

1614
abstract public function catalogueExportURL();

0 commit comments

Comments
 (0)