|
7 | 7 | use Illuminate\Support\Facades\Facade; |
8 | 8 | use Statamic\Console\RunsInPlease; |
9 | 9 | use Statamic\Contracts\Forms\Form as FormContract; |
| 10 | +use Statamic\Contracts\Forms\FormRepository as FormRepositoryContract; |
10 | 11 | use Statamic\Contracts\Forms\Submission as SubmissionContract; |
| 12 | +use Statamic\Contracts\Forms\SubmissionRepository as SubmissionRepositoryContract; |
11 | 13 | use Statamic\Eloquent\Forms\Form; |
12 | 14 | use Statamic\Facades\File; |
13 | 15 | use Statamic\Forms\Form as StacheForm; |
14 | 16 | use Statamic\Forms\FormRepository; |
15 | 17 | use Statamic\Forms\Submission as StacheSubmission; |
| 18 | +use Statamic\Stache\Repositories\SubmissionRepository; |
16 | 19 |
|
17 | 20 | class ImportForms extends Command |
18 | 21 | { |
@@ -50,26 +53,33 @@ public function handle(): int |
50 | 53 | private function useDefaultRepositories(): void |
51 | 54 | { |
52 | 55 | Facade::clearResolvedInstance(FormContract::class); |
| 56 | + Facade::clearResolvedInstance(FormRepositoryContract::class); |
53 | 57 | Facade::clearResolvedInstance(SubmissionContract::class); |
| 58 | + Facade::clearResolvedInstance(SubmissionRepositoryContract::class); |
54 | 59 |
|
55 | 60 | app()->bind(FormContract::class, StacheForm::class); |
| 61 | + app()->bind(FormRepositoryContract::class, FormRepository::class); |
56 | 62 | app()->bind(SubmissionContract::class, StacheSubmission::class); |
57 | | - app()->bind(\Statamic\Eloquent\Forms\SubmissionQueryBuilder::class, \Statamic\Stache\Query\SubmissionQueryBuilder::class); |
| 63 | + app()->bind(SubmissionRepositoryContract::class, SubmissionRepository::class); |
| 64 | + app()->bind(\Statamic\Contracts\Forms\SubmissionQueryBuilder::class, \Statamic\Stache\Query\SubmissionQueryBuilder::class); |
58 | 65 | } |
59 | 66 |
|
60 | 67 | private function importForms(): void |
61 | 68 | { |
62 | | - $this->withProgressBar((new FormRepository)->all(), function ($form) { |
63 | | - if ($this->shouldImportForms()) { |
| 69 | + $shouldImportForms = $this->shouldImportForms(); |
| 70 | + $shouldImportSubmissions = $this->shouldImportFormSubmissions(); |
| 71 | + |
| 72 | + $this->withProgressBar((new FormRepository)->all(), function ($form) use ($shouldImportForms, $shouldImportSubmissions) { |
| 73 | + if ($shouldImportForms) { |
64 | 74 | $lastModified = Carbon::createFromTimestamp(File::lastModified($form->path())); |
65 | 75 |
|
66 | 76 | Form::makeModelFromContract($form) |
67 | 77 | ->fill(['created_at' => $lastModified, 'updated_at' => $lastModified]) |
68 | 78 | ->save(); |
69 | 79 | } |
70 | 80 |
|
71 | | - if ($this->shouldImportFormSubmissions()) { |
72 | | - $form->submissions()->each(function ($submission) use ($form) { |
| 81 | + if ($shouldImportSubmissions) { |
| 82 | + $form->querySubmissions()->lazy()->each(function ($submission) use ($form) { |
73 | 83 | $timestamp = app('statamic.eloquent.form_submissions.model')::make()->fromDateTime($submission->date()); |
74 | 84 |
|
75 | 85 | app('statamic.eloquent.form_submissions.model')::firstOrNew(['created_at' => $timestamp]) |
|
0 commit comments