Skip to content

Commit

Permalink
Merge branch '2.x' into next
Browse files Browse the repository at this point in the history
Signed-off-by: Mior Muhammad Zaki <[email protected]>
  • Loading branch information
crynobone committed Dec 14, 2024
2 parents 5309c4d + 4e88f5a commit f7b82fc
Show file tree
Hide file tree
Showing 29 changed files with 377 additions and 299 deletions.
4 changes: 0 additions & 4 deletions .github/workflows/analyse.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,6 @@ jobs:
run: |
composer config http-basic.nova.laravel.com ${{ secrets.NOVA_USERNAME }} ${{ secrets.NOVA_PASSWORD }}
- name: Install Laravel Pint
run: |
composer require "laravel/pint:^1.1" --no-interaction --no-update
- name: Install dependencies
uses: "ramsey/composer-install@v3"
with:
Expand Down
4 changes: 2 additions & 2 deletions .github/workflows/tests.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ jobs:
run: composer show -D

- name: Execute tests
run: vendor/bin/phpunit --testdox
run: composer run test

tests-on-laravel-10:
runs-on: ${{ matrix.os }}
Expand Down Expand Up @@ -97,4 +97,4 @@ jobs:
run: composer show -D

- name: Execute tests
run: vendor/bin/phpunit --testdox
run: composer run test
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@

# PHPUnit
/coverage/*
/.phpunit.cache/*
/.phpunit.result.cache
14 changes: 11 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,15 +21,17 @@ You can replace `Laravel\Nova\Actions\ExportAsCsv` with `NovaKit\NovaQueuedExpor

```php
use Laravel\Nova\Actions\ExportAsCsv;
use Laravel\Nova\Http\Requests\NovaRequest;
use NovaKit\NovaQueuedExportAsCsv\Actions\QueuedExportAsCsv;

// ...

/**
* Get the actions available for the resource.
*
* @param \Laravel\Nova\Http\Requests\NovaRequest $request
* @return array
* @return array<int, \Laravel\Nova\Actions\Action>
*/
public function actions(NovaRequest $request)
public function actions(NovaRequest $request): array
{
return [
QueuedExportAsCsv::make(),
Expand All @@ -40,6 +42,10 @@ public function actions(NovaRequest $request)
If you would like to change the storage disk to store the CSV file that is available for download, you may invoke the `withStorageDisk()` method when registering the action:

```php
use NovaKit\NovaQueuedExportAsCsv\Actions\QueuedExportAsCsv;

// ...

return [
QueuedExportAsCsv::make()->withStorageDisk('s3'),
];
Expand All @@ -51,6 +57,8 @@ You can also customise the response message by using the following code:
use Laravel\Nova\Actions\Action;
use NovaKit\NovaQueuedExportAsCsv\Actions\QueuedExportAsCsv;

// ...

return [
QueuedExportAsCsv::make()->then(function () {
return response()->json(Action::message('Action has been queued!'));
Expand Down
31 changes: 17 additions & 14 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
},
"autoload-dev": {
"psr-4": {
"NovaKit\\NovaQueuedExportAsCsv\\Tests\\": "tests/",
"Tests\\": "tests/",
"Workbench\\App\\": "workbench/app/",
"Workbench\\Database\\Factories\\": "workbench/database/factories/",
"Workbench\\Database\\Seeders\\": "workbench/database/seeders/"
Expand All @@ -25,29 +25,30 @@
"require": {
"php": "^8.1",
"composer-runtime-api": "^2.2",
"illuminate/support": "^10.34 || ^11.0",
"illuminate/support": "^10.48.23 || ^11.35",
"laravie/serialize-queries": "^3.0",
"laravel/serializable-closure": "^1.0",
"symfony/polyfill-php83": "^1.28"
},
"require-dev": {
"guzzlehttp/guzzle": "^7.2",
"larastan/larastan": "^2.4",
"laravel/nova": "^4.35",
"laravel/nova": "^5.0",
"laravel/nova-devtool": "^1.0.1",
"laravel/pint": "^1.17",
"nova-kit/nova-devtool": "^1.0",
"orchestra/testbench": "^8.20 || ^9.0",
"orchestra/pest-plugin-testbench": "^2.0",
"phpstan/phpstan": "^1.11"
},
"conflict": {
"laravel/nova": "<5.0.0 || >=6.0.0"
},
"repositories": [
{
"type": "composer",
"url": "https://nova.laravel.com"
}
{ "type": "composer", "url": "https://nova.laravel.com" }
],
"extra": {
"branch-alias": {
"dev-main": "2.x-dev"
"config": {
"allow-plugins": {
"pestphp/pest-plugin": true
}
},
"scripts": {
Expand All @@ -59,14 +60,16 @@
"prepare": "@php vendor/bin/testbench package:discover --ansi",
"build": "@php vendor/bin/testbench workbench:build --ansi",
"serve": [
"Composer\\Config::disableProcessTimeout",
"@build",
"@php vendor/bin/testbench serve"
"@php vendor/bin/testbench serve --ansi"
],
"lint": [
"@php vendor/bin/phpstan analyse"
"@php vendor/bin/pint --ansi",
"@php vendor/bin/phpstan analyse --verbose"
],
"test": [
"@php vendor/bin/phpunit"
"@php vendor/bin/pest"
],
"ci": [
"@lint",
Expand Down
6 changes: 4 additions & 2 deletions phpstan.neon.dist
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,10 @@ parameters:
# The level 8 is the highest level
level: 6

checkMissingIterableValueType: false
ignoreErrors:
- identifier: missingType.generics
- identifier: missingType.iterableValue

noUnnecessaryCollectionCall: false
checkModelProperties: false
reportUnmatchedIgnoredErrors: false
checkGenericClassInNonGenericObjectType: false
20 changes: 8 additions & 12 deletions phpunit.xml
Original file line number Diff line number Diff line change
@@ -1,21 +1,12 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/9.3/phpunit.xsd"
xsi:noNamespaceSchemaLocation="https://schema.phpunit.de/10.5/phpunit.xsd"
backupGlobals="false"
backupStaticAttributes="false"
colors="true"
convertDeprecationsToExceptions="true"
convertErrorsToExceptions="true"
convertNoticesToExceptions="true"
convertWarningsToExceptions="true"
processIsolation="false"
stopOnFailure="false"
verbose="true">
<coverage includeUncoveredFiles="false">
<include>
<directory suffix=".php">src/</directory>
</include>
</coverage>
cacheDirectory=".phpunit.cache"
backupStaticProperties="false">
<testsuites>
<testsuite name="Test Suite">
<directory suffix="Test.php">./tests/</directory>
Expand All @@ -26,4 +17,9 @@
<env name="APP_KEY" value="AckfSECXIvnK5r28GVIWUAxmbBSjTsmF"/>
<env name="DB_CONNECTION" value="testing"/>
</php>
<source>
<include>
<directory suffix=".php">src/</directory>
</include>
</source>
</phpunit>
5 changes: 4 additions & 1 deletion pint.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
{
"preset": "laravel",
"rules": {
"no_superfluous_phpdoc_tags": false
"method_chaining_indentation": false,
"no_superfluous_phpdoc_tags": {
"allow_mixed": true
}
}
}
19 changes: 5 additions & 14 deletions src/Actions/QueuedExportAsCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,20 @@ class QueuedExportAsCsv extends ExportAsCsv
{
/**
* Storage disk used to store the file.
*
* @var string|null
*/
public $storageDisk;
public ?string $storageDisk;

/**
* Determine if file should be deleted after send.
*
* @var bool
*/
public $deleteFileAfterSend = false;
public bool $deleteFileAfterSend = false;

/**
* Construct a new action instance.
*
* @param string|null $name
* @param string|null $storageDisk
* @return void
*/
public function __construct($name = null, $storageDisk = null)
public function __construct(?string $name = null, ?string $storageDisk = null)
{
parent::__construct($name);

Expand All @@ -47,10 +41,9 @@ public function __construct($name = null, $storageDisk = null)
/**
* Set the storage disk.
*
* @param string|null $storageDisk
* @return $this
*/
public function withStorageDisk($storageDisk)
public function withStorageDisk(?string $storageDisk)
{
$this->storageDisk = $storageDisk;

Expand All @@ -59,11 +52,9 @@ public function withStorageDisk($storageDisk)

/**
* Perform the action request using custom dispatch handler.
*
* @return \Laravel\Nova\Actions\Response
*/
#[\Override]
protected function dispatchRequestUsing(ActionRequest $request, Response $response, ActionFields $fields)
protected function dispatchRequestUsing(ActionRequest $request, Response $response, ActionFields $fields): Response
{
$query = $request->toSelectedResourceQuery();

Expand Down
33 changes: 6 additions & 27 deletions src/Events/QueuedCsvExported.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,38 +10,17 @@ class QueuedCsvExported
{
use Dispatchable, InteractsWithSockets, SerializesModels;

/**
* The User instance.
*
* @var \Illuminate\Contracts\Auth\Authenticatable&\Illuminate\Database\Eloquent\Model
*/
public $user;

/**
* The storage filename.
*
* @var string
*/
public $filename;

/**
* The storage disk.
*
* @var string|null
*/
public $storageDisk;

/**
* Create a new event instance.
*
* @param \Illuminate\Contracts\Auth\Authenticatable&\Illuminate\Database\Eloquent\Model $user
* @param string|null $storageDisk
* @return void
*/
public function __construct($user, string $filename, $storageDisk)
{
$this->user = $user;
$this->filename = $filename;
$this->storageDisk = $storageDisk;
public function __construct(
public $user,
public readonly string $filename,
public readonly ?string $storageDisk
) {
//
}
}
43 changes: 9 additions & 34 deletions src/Jobs/QueuedExportAsCsv.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
use Illuminate\Bus\Queueable;
use Illuminate\Contracts\Queue\ShouldQueue;
use Illuminate\Filesystem\Filesystem;
use Illuminate\Foundation\Auth\User;
use Illuminate\Foundation\Bus\Dispatchable;
use Illuminate\Http\File;
use Illuminate\Queue\InteractsWithQueue;
Expand All @@ -21,60 +20,36 @@ class QueuedExportAsCsv implements ShouldQueue
{
use Dispatchable, InteractsWithQueue, Queueable, SerializesModels;

/**
* The query builder.
*
* @var array<string, mixed>
*/
public $query;

/**
* The User ID.
*
* @var string|int
*/
public $userId;

/**
* The custom format callback.
*
* @var (callable(\Illuminate\Database\Eloquent\Model):array<string, mixed>)|null
*/
public $withFormatCallback;

/**
* The configuration options.
*
* @var array{filename: string, storageDisk: string|null, notify: string}
*/
public $options;
public array $options;

/**
* Create a new job instance.
*
* @param array<string, mixed> $query
* @param string|int $userId
* @param (callable(\Illuminate\Database\Eloquent\Model):array<string, mixed>)|null $withFormatCallback
* @param array{filename: string, storageDisk: string|null, notify: string} $options
* @return void
*/
public function __construct(array $query, $userId, $withFormatCallback, array $options)
{
$this->query = $query;
$this->userId = $userId;
$this->withFormatCallback = $withFormatCallback;

public function __construct(
public array $query,
public string|int $userId,
public $withFormatCallback,
array $options
) {
$this->options = array_merge([
'storageDisk' => null,
], $options);
}

/**
* Execute the job.
*
* @return void
*/
public function handle()
public function handle(): void
{
$query = unserialize($this->query);

Expand All @@ -98,7 +73,7 @@ public function handle()
'nova-actions-export-as-csv', new File($exportedFilename), $filename, 'public'
);

(new Filesystem())->delete($exportedFilename);
(new Filesystem)->delete($exportedFilename);

/** @var \Illuminate\Contracts\Auth\Authenticatable&\Illuminate\Database\Eloquent\Model $user */
$user = $userModel::findOrFail($this->userId);
Expand Down
2 changes: 2 additions & 0 deletions testbench.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@ seeders:

workbench:
start: /nova
user: [email protected]
build:
- package:discover
- asset-publish
- create-sqlite-db
- db:wipe
Expand Down
Loading

0 comments on commit f7b82fc

Please sign in to comment.