Skip to content

[5.x] Fix storing submissions of forms with 'files' fieldtypes even when disabled #11794

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

Merged
merged 2 commits into from
May 20, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion src/Forms/DeleteTemporaryAttachments.php
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,8 @@ public function handle()
$this->submission->remove($field->handle());
});

$this->submission->saveQuietly();
if ($this->submission->form()->store()) {
$this->submission->saveQuietly();
}
}
}
24 changes: 24 additions & 0 deletions tests/Forms/SendEmailsTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
use Illuminate\Support\Facades\Bus;
use PHPUnit\Framework\Attributes\DataProvider;
use PHPUnit\Framework\Attributes\Test;
use Statamic\Contracts\Forms\SubmissionRepository;
use Statamic\Facades\Form as FacadesForm;
use Statamic\Facades\Site;
use Statamic\Forms\DeleteTemporaryAttachments;
Expand Down Expand Up @@ -115,6 +116,29 @@ public function it_dispatches_delete_attachments_job_after_dispatching_email_job
]);
}

#[Test]
public function delete_attachments_job_only_saves_submission_when_enabled()
{
$form = tap(FacadesForm::make('attachments_test')->email([
'from' => 'first@sender.com',
'to' => 'first@recipient.com',
'foo' => 'bar',
]))->save();

$form
->store(false)
->blueprint()
->ensureField('attachments', ['type' => 'files'])->save();

$submission = $form->makeSubmission();

(new DeleteTemporaryAttachments($submission))->handle();

$submissions = app(SubmissionRepository::class)->all();

$this->assertEmpty($submissions);
}

#[Test]
#[DataProvider('noEmailsProvider')]
public function no_email_jobs_are_queued_if_none_are_configured($emailConfig)
Expand Down