diff --git a/src/DataSource/Builder.php b/src/DataSource/Builder.php index 09714521..c9daf4e6 100644 --- a/src/DataSource/Builder.php +++ b/src/DataSource/Builder.php @@ -39,7 +39,7 @@ public static function make( public function filter(): EloquentBuilder|QueryBuilder { - $filters = collect($this->component->filters()); + $filters = collect($this->component->filters); if ($filters->isEmpty()) { return $this->query; diff --git a/src/DataSource/Processors/DataSourceBase.php b/src/DataSource/Processors/DataSourceBase.php index f37113b2..d6bbcc11 100644 --- a/src/DataSource/Processors/DataSourceBase.php +++ b/src/DataSource/Processors/DataSourceBase.php @@ -133,7 +133,7 @@ private static function processRows(BaseCollection $results, PowerGridComponent $row = (object) $row; $data = $fields->map(fn ($field) => $field($row, $index)); - $rowId = data_get($row, $component->realPrimaryKey); + $rowId = data_get($row, $component->primaryKeyAlias ?? $component->primaryKey); if ($renderActions) { try { diff --git a/src/Jobs/ExportJob.php b/src/Jobs/ExportJob.php index 40d6ba10..e4e4782f 100644 --- a/src/Jobs/ExportJob.php +++ b/src/Jobs/ExportJob.php @@ -15,22 +15,17 @@ class ExportJob implements ShouldQueue { use Batchable; use Dispatchable; + use ExportableJob; use InteractsWithQueue; use Queueable; use SerializesModels; - use ExportableJob; private array $properties; - /** - * @param string $componentTable - * @param array $columns - * @param array $params - */ public function __construct( string $componentTable, - array $columns, - array $params + array $columns, + array $params ) { $this->columns = $columns; $this->exportableClass = $params['exportableClass']; diff --git a/src/PowerGridComponent.php b/src/PowerGridComponent.php index 8ff215f5..86184a54 100644 --- a/src/PowerGridComponent.php +++ b/src/PowerGridComponent.php @@ -80,7 +80,7 @@ public function updatedPage(): void { $this->checkboxAll = false; - if ($this->hasLazyEnabled) { + if (!app()->runningInConsole() && $this->hasLazyEnabled) { $this->additionalCacheKey = uniqid(); data_set($this->setUp, 'lazy.items', 0); @@ -95,7 +95,7 @@ public function updatedSearch(): void { $this->gotoPage(1, data_get($this->setUp, 'footer.pageName')); - if ($this->hasLazyEnabled) { + if (!app()->runningInConsole() && $this->hasLazyEnabled) { $this->additionalCacheKey = uniqid(); data_set($this->setUp, 'lazy.items', 0); diff --git a/src/Traits/ExportableJob.php b/src/Traits/ExportableJob.php index 604b067d..a41af52f 100644 --- a/src/Traits/ExportableJob.php +++ b/src/Traits/ExportableJob.php @@ -36,19 +36,22 @@ private function getFilename(): Stringable private function prepareToExport(array $properties = []): Eloquent\Collection|Collection { /** @phpstan-ignore-next-line */ - $processDataSource = tap(ProcessDataSource::make($this->componentTable, $properties), fn ($datasource) => $datasource->get()); - - $inClause = $processDataSource->component->filtered ?? []; + $this->componentTable->filters = $this->filters ?? []; /** @phpstan-ignore-next-line */ - $this->componentTable->filters = $this->filters ?? []; + $processDataSource = tap( + ProcessDataSource::make($this->componentTable, $properties), + fn ($datasource) => $datasource->get() + ); + + $inClause = $processDataSource->component->filtered ?? []; /** @phpstan-ignore-next-line */ $currentTable = $processDataSource->component->currentTable; $sortField = Str::of($processDataSource->component->sortField)->contains('.') ? $processDataSource->component->sortField : $currentTable . '.' . $processDataSource->component->sortField; - $results = $processDataSource->prepareDataSource() // @phpstan-ignore-line + $results = $this->componentTable->datasource($this->properties ?? []) // @phpstan-ignore-line ->where( fn ($query) => Builder::make($query, $this->componentTable) ->filterContains() @@ -57,6 +60,8 @@ private function prepareToExport(array $properties = []): Eloquent\Collection|Co ->when($inClause, function ($query, $inClause) use ($processDataSource) { return $query->whereIn($processDataSource->component->primaryKey, $inClause); }) + ->offset($this->offset) + ->limit($this->limit) ->orderBy($sortField, $processDataSource->component->sortDirection) ->get(); diff --git a/src/Traits/WithExport.php b/src/Traits/WithExport.php index e55801b2..37a90d82 100644 --- a/src/Traits/WithExport.php +++ b/src/Traits/WithExport.php @@ -105,13 +105,13 @@ private function putQueuesToBus(string $exportableClass, string $fileExtension): $this->exportedFiles = []; $filters = $processDataSource?->component?->filters ?? []; $queues = collect([]); - $countQueue = $this->total > $this->getQueuesCount() ? $this->getQueuesCount() : 1; - $perPage = $this->total > $countQueue ? ($this->total / $countQueue) : 1; + $queueCount = $this->total > $this->getQueuesCount() ? $this->getQueuesCount() : 1; + $perPage = $this->total > $queueCount ? ($this->total / $queueCount) : 1; $offset = 0; $limit = $perPage; - for ($i = 1; $i < ($countQueue + 1); $i++) { - $fileName = 'powergrid-' . Str::kebab(strval(data_get($this->setUp, 'exportable.fileName'))) . + for ($i = 1; $i < ($queueCount + 1); $i++) { + $fileName = Str::kebab(strval(data_get($this->setUp, 'exportable.fileName'))) . '-' . round(($offset + 1), 2) . '-' . round($limit, 2) . '-' . $this->getId() . @@ -172,7 +172,8 @@ public function prepareToExport(bool $selected = false): Eloquent\Collection|Sup if ($processDataSource->component->datasource() instanceof Collection) { if ($inClause) { - $results = $processDataSource->get(isExport: true)->whereIn($this->primaryKey, $inClause); + $results = $processDataSource->get(isExport: true) + ->whereIn($this->primaryKey, $inClause); return DataSourceBase::transform($results, $this); }