Skip to content

Commit 82cc810

Browse files
authored
Merge pull request #21 from jargoud/feat/import-form-action
feat(import): dynamic form action
2 parents f6f96da + d5ce26f commit 82cc810

File tree

11 files changed

+39
-26
lines changed

11 files changed

+39
-26
lines changed

composer.json

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,10 @@
2727
"require-dev": {
2828
"laravel/scout": "^10.10",
2929
"nunomaduro/collision": "^8.1",
30-
"nunomaduro/larastan": "^2.0",
30+
"nunomaduro/larastan": "^3.0",
3131
"orchestra/testbench": "^9.0",
32-
"phpstan/phpstan": "^1.10",
32+
"phpstan/phpstan": "^2.0",
3333
"phpunit/phpunit": "^10.1",
34-
"spatie/laravel-ray": "^1.30",
3534
"squizlabs/php_codesniffer": "^3.7",
3635
"vimeo/psalm": "^5.0"
3736
},

phpstan.neon

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -2,20 +2,11 @@ includes:
22
- ./vendor/nunomaduro/larastan/extension.neon
33

44
parameters:
5-
6-
paths:
7-
- src/
8-
9-
# Level 9 is the highest level
10-
level: 6
11-
12-
# ignoreErrors:
13-
# - '#PHPDoc tag @var#'
14-
#
15-
# excludePaths:
16-
# - ./*/*/FileToBeExcluded.php
17-
#
18-
# checkMissingIterableValueType: false
19-
checkMissingIterableValueType: false
20-
21-
checkGenericClassInNonGenericObjectType: false
5+
level: 6
6+
paths:
7+
- src
8+
ignoreErrors:
9+
- '#Class [a-zA-Z0-9\\_]+ implements generic interface [a-zA-Z0-9\\_]+ but does not specify its types: [a-zA-Z0-9\\_]+#'
10+
- '#Method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\) return type with generic class [a-zA-Z0-9\\_]+ does not specify its types: .+#'
11+
- '#Trait [a-zA-Z0-9\\_]+ is used zero times and is not analysed.#'
12+
- '#Unable to resolve the template type TRelatedModel in call to method [a-zA-Z0-9\\_]+::[a-zA-Z0-9\\_]+\(\)#'

resources/views/pages/import.blade.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@
2828
<div class="{{ $crud->getEditContentClass() }}">
2929
@include('crud::inc.grouped_errors')
3030

31-
<form action="{{ url($crud->route . '/import') }}" enctype="multipart/form-data" method="post">
31+
<form action="{{ $action }}" enctype="multipart/form-data" method="post">
3232
@csrf
3333

3434
@includeFirst(

src/Http/Controllers/Admin/Interfaces/ExportableCrud.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ interface ExportableCrud
88
{
99
public function getExport(): ImportExport;
1010

11+
/**
12+
* @return array<string, mixed>
13+
*/
1114
public function getExportParameters(): array;
1215
}

src/Http/Controllers/Admin/Interfaces/ImportableCrud.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,5 +8,8 @@ interface ImportableCrud
88
{
99
public function getImport(): ImportExport;
1010

11+
/**
12+
* @return array<string, mixed>
13+
*/
1114
public function getImportParameters(): array;
1215
}

src/Http/Controllers/Admin/Interfaces/MultiExportableCrud.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,5 +7,8 @@ interface MultiExportableCrud
77
public const QUERY_PARAM = 'export';
88
public const DEFAULT_EXPORT_NAME = 'default';
99

10+
/**
11+
* @return array<string, mixed>
12+
*/
1013
public function getAvailableExports(): array;
1114
}

src/Http/Controllers/Admin/Traits/HasImportButton.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,9 @@ public function import(): View
3232

3333
$this->data['crud'] = $this->crud;
3434
$this->data['title'] = $this->crud->getTitle();
35+
$this->data['action'] = url(
36+
$this->crud->route . '/' . config('backpack-async-import-export.admin_import_route'),
37+
);
3538

3639
return view('backpack-async-export::pages.import', $this->data);
3740
}

src/Http/Requests/ImportRequest.php

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,9 @@ class ImportRequest extends FormRequest
88
{
99
const PARAM_FILE = 'file';
1010

11+
/**
12+
* @return array<string, mixed>
13+
*/
1114
public function rules(): array
1215
{
1316
return [

src/Jobs/ExportJob.php

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,9 +26,11 @@ class ExportJob implements ShouldQueue
2626
use SerializesModels;
2727

2828
private ImportExport $export;
29-
private array $exportParameters;
3029

31-
public function __construct(ImportExport $export, array $exportParameters)
30+
/**
31+
* @param array<string, mixed> $exportParameters
32+
*/
33+
public function __construct(ImportExport $export, private array $exportParameters)
3234
{
3335
$this->export = $export;
3436
$this->exportParameters = $exportParameters;

src/Jobs/ImportJob.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,9 @@ class ImportJob implements ShouldQueue
2121
use Queueable;
2222
use SerializesModels;
2323

24+
/**
25+
* @param array<string, mixed> $exportParameters
26+
*/
2427
public function __construct(
2528
private ImportExport $export,
2629
private array $exportParameters
@@ -70,7 +73,7 @@ public function handle(): void
7073
->implode(', ');
7174
throw new \Exception($message);
7275
}
73-
} catch (\Exception|\Throwable $exception) {
76+
} catch (\Throwable $exception) {
7477
$this->export->update([
7578
ImportExport::COLUMN_STATUS => ImportExportStatus::Error,
7679
ImportExport::COLUMN_ERROR => $exception->getMessage(),

0 commit comments

Comments
 (0)