Skip to content

Commit

Permalink
Fix exports too
Browse files Browse the repository at this point in the history
  • Loading branch information
ryanmitchell committed Dec 9, 2024
1 parent fc993b8 commit 833c568
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
16 changes: 16 additions & 0 deletions src/Commands/ExportForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -9,12 +9,15 @@
use Statamic\Contracts\Forms\Form as FormContract;
use Statamic\Contracts\Forms\FormRepository as FormRepositoryContract;
use Statamic\Contracts\Forms\Submission as SubmissionContract;
use Statamic\Contracts\Forms\SubmissionRepository as SubmissionRepositoryContract;
use Statamic\Eloquent\Forms\Form;
use Statamic\Eloquent\Forms\FormRepository;
use Statamic\Eloquent\Forms\Submission;
use Statamic\Eloquent\Forms\SubmissionRepository;
use Statamic\Forms\Form as StacheForm;
use Statamic\Forms\FormRepository as StacheFormRepository;
use Statamic\Forms\Submission as StacheSubmission;
use Statamic\Stache\Repositories\SubmissionRepository as StacheSubmissionRepository;
use Statamic\Statamic;

class ExportForms extends Command
Expand Down Expand Up @@ -55,10 +58,15 @@ public function handle()
private function usingDefaultRepositories(Closure $callback)
{
Facade::clearResolvedInstance(FormContract::class);
Facade::clearResolvedInstance(FormRepositoryContract::class);
Facade::clearResolvedInstance(SubmissionContract::class);
Facade::clearResolvedInstance(SubmissionRepositoryContract::class);

app()->bind(FormContract::class, Form::class);
app()->bind(FormRepositoryContract::class, FormRepository::class);
app()->bind(SubmissionContract::class, Submission::class);
app()->bind(SubmissionRepositoryContract::class, SubmissionRepository::class);
app()->bind(\Statamic\Contracts\Forms\SubmissionQueryBuilder::class, \Statamic\Eloquent\Forms\SubmissionQueryBuilder::class);

$callback();
}
Expand All @@ -78,10 +86,12 @@ private function exportForms()
->honeypot($form->honeypot());

Statamic::repository(FormRepositoryContract::class, StacheFormRepository::class);
Facade::clearResolvedInstance(SubmissionRepositoryContract::class);

$newForm->save();

Statamic::repository(FormRepositoryContract::class, FormRepository::class);
Facade::clearResolvedInstance(SubmissionRepositoryContract::class);

$form->submissions()->each(function ($submission) use ($newForm) {
$id = $submission->date()->getPreciseTimestamp(4);
Expand All @@ -92,7 +102,13 @@ private function exportForms()
->form($newForm)
->data($submission->data());

Statamic::repository(SubmissionRepositoryContract::class, StacheSubmissionRepository::class);
Facade::clearResolvedInstance(SubmissionRepositoryContract::class);

$newSubmission->save();

Statamic::repository(SubmissionRepositoryContract::class, SubmissionRepository::class);
Facade::clearResolvedInstance(SubmissionRepositoryContract::class);
});
});

Expand Down
2 changes: 1 addition & 1 deletion src/Commands/ImportForms.php
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ private function importForms(): void
$shouldImportForms = $this->shouldImportForms();
$shouldImportSubmissions = $this->shouldImportFormSubmissions();

$this->withProgressBar((new FormRepository)->all(), function ($form, $shouldImportForms, $shouldImportSubmissions) {
$this->withProgressBar((new FormRepository)->all(), function ($form) use ($shouldImportForms, $shouldImportSubmissions) {
if ($shouldImportForms) {
$lastModified = Carbon::createFromTimestamp(File::lastModified($form->path()));

Expand Down

0 comments on commit 833c568

Please sign in to comment.