Skip to content

Commit 8cc8f92

Browse files
authored
[5.x] Fix storing submissions of forms with 'files' fieldtypes even when disabled (#11794)
1 parent 90d0ff4 commit 8cc8f92

File tree

2 files changed

+27
-1
lines changed

2 files changed

+27
-1
lines changed

src/Forms/DeleteTemporaryAttachments.php

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,8 @@ public function handle()
3131
$this->submission->remove($field->handle());
3232
});
3333

34-
$this->submission->saveQuietly();
34+
if ($this->submission->form()->store()) {
35+
$this->submission->saveQuietly();
36+
}
3537
}
3638
}

tests/Forms/SendEmailsTest.php

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
use Illuminate\Support\Facades\Bus;
66
use PHPUnit\Framework\Attributes\DataProvider;
77
use PHPUnit\Framework\Attributes\Test;
8+
use Statamic\Contracts\Forms\SubmissionRepository;
89
use Statamic\Facades\Form as FacadesForm;
910
use Statamic\Facades\Site;
1011
use Statamic\Forms\DeleteTemporaryAttachments;
@@ -115,6 +116,29 @@ public function it_dispatches_delete_attachments_job_after_dispatching_email_job
115116
]);
116117
}
117118

119+
#[Test]
120+
public function delete_attachments_job_only_saves_submission_when_enabled()
121+
{
122+
$form = tap(FacadesForm::make('attachments_test')->email([
123+
'from' => 'first@sender.com',
124+
'to' => 'first@recipient.com',
125+
'foo' => 'bar',
126+
]))->save();
127+
128+
$form
129+
->store(false)
130+
->blueprint()
131+
->ensureField('attachments', ['type' => 'files'])->save();
132+
133+
$submission = $form->makeSubmission();
134+
135+
(new DeleteTemporaryAttachments($submission))->handle();
136+
137+
$submissions = app(SubmissionRepository::class)->all();
138+
139+
$this->assertEmpty($submissions);
140+
}
141+
118142
#[Test]
119143
#[DataProvider('noEmailsProvider')]
120144
public function no_email_jobs_are_queued_if_none_are_configured($emailConfig)

0 commit comments

Comments
 (0)