Skip to content

Commit

Permalink
Fix exports
Browse files Browse the repository at this point in the history
  • Loading branch information
riasvdv committed Nov 30, 2023
1 parent 8114d42 commit 0046ed3
Show file tree
Hide file tree
Showing 3 changed files with 20 additions and 11 deletions.
8 changes: 4 additions & 4 deletions src/Controllers/ExportController.php
Original file line number Diff line number Diff line change
Expand Up @@ -27,12 +27,12 @@ public function __invoke($type)

if (request()->has('download')) {
$path = storage_path('statamic/tmp/redirect/'.time().'.'.$type);

File::put($path, $content);
$response = response()->download($path)->deleteFileAfterSend(true);
} else {
$response = response($content)->header('Content-Type', $exporter->contentType());

return response()->download($path)->deleteFileAfterSend();
}

return $response;
return response($content)->header('Content-Type', $exporter->contentType());
}
}
13 changes: 10 additions & 3 deletions src/Exporters/CsvExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,12 @@
use League\Csv\Writer;
use Rias\StatamicRedirect\Facades\Redirect;
use SplTempFileObject;
use Statamic\Forms\Exporters\AbstractExporter;
use Statamic\Forms\Exporters\Exporter;

class CsvExporter extends AbstractExporter
class CsvExporter extends Exporter
{
protected static string $title = 'Redirects';

/**
* @var Writer
*/
Expand All @@ -27,7 +29,7 @@ public function __construct()
*
* @return string
*/
public function export()
public function export(): string
{
$this->insertHeaders();

Expand Down Expand Up @@ -65,4 +67,9 @@ private function insertData()

$this->writer->insertAll($data);
}

public function contentType(): string
{
return 'text/csv';
}
}
10 changes: 6 additions & 4 deletions src/Exporters/JsonExporter.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@
namespace Rias\StatamicRedirect\Exporters;

use Rias\StatamicRedirect\Facades\Redirect;
use Statamic\Forms\Exporters\AbstractExporter;
use Statamic\Forms\Exporters\Exporter;

class JsonExporter extends AbstractExporter
class JsonExporter extends Exporter
{
protected static string $title = 'Redirects';

/**
* Perform the export.
*
* @return string
*/
public function export()
public function export(): string
{
$submissions = Redirect::all()->map(function (Redirect $redirect) {
$redirectData = $redirect->fileData();
Expand All @@ -31,7 +33,7 @@ public function export()
*
* @return string
*/
public function contentType()
public function contentType(): string
{
return 'application/json';
}
Expand Down

0 comments on commit 0046ed3

Please sign in to comment.