++ fix temporary PDF viewer URLs, which were causing issues with caching and expiring links. Instead, we now generate short-lived URLs that redirect to the PDF viewer route, ensuring that users can access the PDFs without running into expired links. This change affects the Assegnazione model, the ShortPdfLinkController, and the relevant Blade views for assignments and records. Additionally, I've updated the Home Livewire component to calculate and display the average duration of assignments in months, providing more insight into assignment durations on the dashboard.
This commit is contained in:
@@ -0,0 +1,74 @@
|
||||
<?php
|
||||
|
||||
namespace App\Http\Controllers\Settings;
|
||||
|
||||
use App\Http\Controllers\Controller;
|
||||
use App\Livewire\Settings\XmlExchange;
|
||||
use Illuminate\Http\Request;
|
||||
|
||||
class XmlExchangeUploadController extends Controller
|
||||
{
|
||||
public function convertSqlToXml(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'sqlDump' => ['required', 'file', 'max:256000'],
|
||||
]);
|
||||
|
||||
$file = $request->file('sqlDump');
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
if (! in_array($ext, ['sql', 'txt'])) {
|
||||
return back()->withErrors(['sqlDump' => 'Il file deve essere .sql o .txt']);
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
if (! $content) {
|
||||
return back()->withErrors(['sqlDump' => 'File vuoto o non leggibile.']);
|
||||
}
|
||||
|
||||
$exchange = app(XmlExchange::class);
|
||||
$dataset = $exchange->legacySqlToDatasetPublic($content);
|
||||
$xml = $exchange->datasetToXmlPublic($dataset, 'legacy-sql-conversion');
|
||||
|
||||
return response()->streamDownload(function () use ($xml) {
|
||||
echo $xml;
|
||||
}, 'termanager-conversion.xml', ['Content-Type' => 'application/xml; charset=UTF-8']);
|
||||
}
|
||||
|
||||
public function importXml(Request $request)
|
||||
{
|
||||
$request->validate([
|
||||
'xmlImport' => ['required', 'file', 'max:256000'],
|
||||
]);
|
||||
|
||||
$file = $request->file('xmlImport');
|
||||
$ext = strtolower($file->getClientOriginalExtension());
|
||||
if (! in_array($ext, ['xml', 'txt'])) {
|
||||
return back()->withErrors(['xmlImport' => 'Il file deve essere .xml o .txt']);
|
||||
}
|
||||
|
||||
$content = file_get_contents($file->getRealPath());
|
||||
if (! $content) {
|
||||
return back()->withErrors(['xmlImport' => 'File vuoto o non leggibile.']);
|
||||
}
|
||||
|
||||
$exchange = new XmlExchange();
|
||||
$result = $exchange->importXmlFromContent($content);
|
||||
|
||||
if (isset($result['error'])) {
|
||||
return back()->withErrors(['xmlImport' => $result['error']]);
|
||||
}
|
||||
|
||||
$stats = $result['stats'];
|
||||
$issues = $result['issues'];
|
||||
|
||||
$message = 'Import XML completato con successo.';
|
||||
if (($stats['duplicate_territori'] ?? 0) > 0 || ($stats['assegnazioni_saltate'] ?? 0) > 0) {
|
||||
$message .= ' Territori duplicati saltati: ' . $stats['duplicate_territori'] . '. Assegnazioni saltate: ' . $stats['assegnazioni_saltate'] . '.';
|
||||
}
|
||||
|
||||
return redirect()->route('xml.exchange')
|
||||
->with('success', $message)
|
||||
->with('importStats', $stats)
|
||||
->with('importIssues', $issues);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user