Details
-
Bug
-
Resolution: Fixed
-
Medium
-
3.3.35, 4.5.3
-
None
-
Yes
Description
When form has submissions and one of its fields changes name, deleting submissions with FormSubmissionService::delete will fail and throw an Exception.
Steps to reproduce
1. Clean installation of Ibexa DXP v3.3/4.5
2. In the backoffice create a form inside Form Builder. Add two fields: single line with name Test and a submit button.
3. Add at least one submission.
4. Change the "Test" field name to "Test2". Add at least one more submission.
5. Create a command deleting all submissions from this Form using FormSubmissionService (please set "FORM_CONTENT_ID" to your Form ContentId):
#v3.3 <?php namespace App\Command; use eZ\Publish\API\Repository\ContentService; use EzSystems\EzPlatformFormBuilder\FormSubmission\FormSubmissionServiceInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class FormSubmissionsRemoveCommand extends Command { private const FORM_CONTENT_ID = 66; public static $defaultName = 'test:fsr'; /** @var \EzSystems\EzPlatformFormBuilder\FormSubmission\FormSubmissionServiceInterface */ private $formSubmissionService; /** @var \eZ\Publish\API\Repository\ContentService */ private $contentService; public function __construct( FormSubmissionServiceInterface $formSubmissionService, ContentService $contentService ) { $this->formSubmissionService = $formSubmissionService; $this->contentService = $contentService; parent::__construct(); } public function execute(InputInterface $input, OutputInterface $output): int { $formContent = $this->contentService->loadContent(self::FORM_CONTENT_ID); $submissions = $this->formSubmissionService->loadByContent($formContent->contentInfo); foreach ($submissions as $submission) { $this->formSubmissionService->delete($submission); } $output->writeln("Done!"); return Command::SUCCESS; } }
#v4.5 <?php namespace App\Command; use Ibexa\Contracts\Core\Repository\ContentService; use Ibexa\Contracts\FormBuilder\FormSubmission\FormSubmissionServiceInterface; use Symfony\Component\Console\Command\Command; use Symfony\Component\Console\Input\InputInterface; use Symfony\Component\Console\Output\OutputInterface; class FormSubmissionsRemoveCommand extends Command { private const FORM_CONTENT_ID = 66; public static $defaultName = 'test:fsr'; private FormSubmissionServiceInterface $formSubmissionService; private ContentService $contentService; public function __construct( FormSubmissionServiceInterface $formSubmissionService, ContentService $contentService ) { $this->formSubmissionService = $formSubmissionService; $this->contentService = $contentService; parent::__construct(); } public function execute(InputInterface $input, OutputInterface $output): int { $formContent = $this->contentService->loadContent(self::FORM_CONTENT_ID); $submissions = $this->formSubmissionService->loadByContent($formContent->contentInfo); foreach ($submissions as $submission) { $this->formSubmissionService->delete($submission); } $output->writeln("Done!"); return Command::SUCCESS; } }
6. Execute the command:
php bin/console test:fsr
Result:
Call to a member function getName() on null
Expected result:
Submissions are deleted successfully.