Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

QueuedExport doesn't allow softDeleted data #136

Open
yahya077 opened this issue Jan 24, 2022 · 10 comments
Open

QueuedExport doesn't allow softDeleted data #136

yahya077 opened this issue Jan 24, 2022 · 10 comments

Comments

@yahya077
Copy link

Versions

  • PHP version: 8.0
  • Laravel version: 8.73
  • Nova version: 3.29
  • Package version: 1.2.9

Description

After softDeleted data selected, QueuedExport doesn't get deleted ones. DownloadExcel class does that.

Additional Information

(new CustomExcelExport())->withDisk('media')->askForFilename(),
The implementations are WithMapping,WithHeadings
The traits are InteractsWithQueue, Queueable;

@patrickbrouwers
Copy link
Member

Hey @yahya077 can you share the query please

@yahya077
Copy link
Author

Hi @patrickbrouwers , let me explain myself. I extended my custom class with QueuedExport. In the __sleep function $this->request->query->get('trashed') returns 'only' but it has to return 'with' because i needed with softDeleted datas.
When I extend with DownloadExcel or ExportToExcel the data comes with softDeletes and work fine.

If i set trashed as 'with' in '__sleep' function it returns serialization error.

@yahya077
Copy link
Author

In the model resource when i override indexQuery with

$request->merge(['trashed' => 'with']);
$request->query->set('trashed','with');
return $query;

Its changing the trashed but QueuedExport doesn't using that parameter. Maybe QueuedExport creating a new query.

@patrickbrouwers
Copy link
Member

I'm not familiar with set('trashed'). The package that serializes the query has support for trashed/soft deleted: https://github.com/laravie/serialize-queries/blob/master/tests/Feature/EloquentTest.php#L87 I guess it would be best if you could try to create an easy to reproduce scenario, so I can share it with the package author

@crynobone
Copy link
Contributor

If you want to set only trashed you have to do it during or before __sleep(). I don't think this package interacts with request during __wakeup(), @patrickbrouwers may confirm this.

laravie/serialize-queries only handle query serialize and unserialize.

@patrickbrouwers
Copy link
Member

I think indeed the request won't be correctly searialized for the wakekup. Perhaps add some logging to check what the value is within that indexQuery at the moment it does the _wakeup

@yahya077
Copy link
Author

Alright, let me give you the sceneario.

My Nova Resource in actions

(new CustomExcelExport())->withDisk('media')->askForFilename(),

My CustomExcelExport class

`extends QueuedExport implements WithMapping,WithHeadings`
// functions that i included are
public function name()
public function headings(): array
public function map($model): array

// Those functions are not empty obviously, it stands for scenario purpose.

The problem

The data doesn't returns with deleted ones.

What I tried

note: these substances are tried separately.

  1. In the nova resource i override indexQuery function to get delated ones. Which is writing queries to get with deleted.
  2. In the nova resource i override indexQuery. With;
$request->merge(['trashed' => 'with']);
$request->query->set('trashed','with');
return $query;
  1. In the nova resource i override initializeQuery. I just add it $withTrashed = 'with'; to the beginning of the function.
  2. In the custom class i override __sleep(). I add it $request->merge(['trashed' => 'with']); and $request->query->set('trashed','with'); to the beginning of the function.

@patrickbrouwers
Copy link
Member

As you are already using a custom export class, you can probably better just overwrite the query method there.

@yahya077
Copy link
Author

Well, I also tried that earlier but It also doesn't work. Why? Let me explain.
When I add a query like get data with deleted ones It doesnt work.
eq: $query->whereNotNull('deleted_at') // this will get all data with that query not the ones i selected from datatable

The query function is not doing its job. I check the all query after i queried. There is a 'where is null deleted_at' query. It seems like before the query function some query prepared already.

If you try it you will see that extra query will broke the code.

@patrickbrouwers
Copy link
Member

It would be a lot easier if you could give a full reproduction scenario, this is quite hard to puzzle together to what you are exactly trying. If you could make a reproduction repository with the most simple situation that will make it less time consuming to look into, without it I won't have time to look into it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants