Fix: Export all pages when exporting a csv
continuous-integration/drone/push Build is passing Details

This commit is contained in:
philipp lang 2024-05-09 02:07:31 +02:00
parent b3354e1474
commit b1581bf9c8
3 changed files with 31 additions and 2 deletions

View File

@ -43,7 +43,7 @@ class ExportAction
public function asController(ActionRequest $request): StreamedResponse public function asController(ActionRequest $request): StreamedResponse
{ {
$members = FilterScope::fromRequest($request->input('filter'))->getQuery()->get(); $members = FilterScope::fromRequest($request->input('filter'))->withOptions(['hitsPerPage' => 20000])->getQuery()->get();
$contents = $this->handle($members); $contents = $this->handle($members);
Storage::disk('temp')->put('mitglieder.csv', $contents); Storage::disk('temp')->put('mitglieder.csv', $contents);

View File

@ -20,6 +20,12 @@ use Spatie\LaravelData\Mappers\SnakeCaseMapper;
#[MapOutputName(SnakeCaseMapper::class)] #[MapOutputName(SnakeCaseMapper::class)]
class FilterScope extends ScoutFilter class FilterScope extends ScoutFilter
{ {
/**
* @var array<string, mixed>
*/
public array $options = [];
/** /**
* @param array<int, int> $activityIds * @param array<int, int> $activityIds
* @param array<int, int> $subactivityIds * @param array<int, int> $subactivityIds
@ -43,6 +49,16 @@ class FilterScope extends ScoutFilter
) { ) {
} }
/**
* @param array<string, mixed> $options
*/
public function withOptions(array $options): self
{
$this->options = $options;
return $this;
}
public function getQuery(): Builder public function getQuery(): Builder
{ {
$this->search = $this->search ?: ''; $this->search = $this->search ?: '';
@ -97,7 +113,7 @@ class FilterScope extends ScoutFilter
$options['filter'] = $this->implode(collect([$andFilter])->push($this->inExpression('id', $this->include)), 'OR'); $options['filter'] = $this->implode(collect([$andFilter])->push($this->inExpression('id', $this->include)), 'OR');
$options['sort'] = ['lastname:asc', 'firstname:asc']; $options['sort'] = ['lastname:asc', 'firstname:asc'];
return $engine->search($query, $options); return $engine->search($query, [...$this->options, ...$options]);
}); });
} }

View File

@ -27,6 +27,19 @@ class ExportCsvActionTest extends EndToEndTestCase
$this->assertFalse(str_contains($contents, 'Max')); $this->assertFalse(str_contains($contents, 'Max'));
} }
public function testItExportsAllMembers(): void
{
Storage::fake('temp');
$this->withoutExceptionHandling()->login()->loginNami();
Member::factory()->defaults()->count(40)->create();
sleep(1);
$this->callFilter('member-export', [])->assertDownload('mitglieder.csv');
$contents = Storage::disk('temp')->get('mitglieder.csv');
$this->assertCount(42, explode("\n", $contents));
}
public function testItOrdersByLastname(): void public function testItOrdersByLastname(): void
{ {
Storage::fake('temp'); Storage::fake('temp');