diff --git a/code/Control/UserDefinedFormController.php b/code/Control/UserDefinedFormController.php index 4f2e8049f..3ed0b753f 100644 --- a/code/Control/UserDefinedFormController.php +++ b/code/Control/UserDefinedFormController.php @@ -20,6 +20,7 @@ use SilverStripe\ORM\ValidationException; use SilverStripe\ORM\ValidationResult; use SilverStripe\Security\Security; +use SilverStripe\UserForms\Extension\UserFormFileExtension; use SilverStripe\UserForms\Form\UserForm; use SilverStripe\UserForms\Model\EditableFormField; use SilverStripe\UserForms\Model\EditableFormField\EditableFileField; @@ -257,6 +258,7 @@ public function process($data, $form) $upload = Upload::create(); $file = File::create(); $file->ShowInSearch = 0; + $file->UserFormUpload = UserFormFileExtension::USER_FORM_UPLOAD_TRUE; try { $upload->loadIntoFile($_FILES[$field->Name], $file, $foldername); } catch (ValidationException $e) { diff --git a/code/Extension/UserFormFileExtension.php b/code/Extension/UserFormFileExtension.php index 5072a8eab..cffcbda56 100644 --- a/code/Extension/UserFormFileExtension.php +++ b/code/Extension/UserFormFileExtension.php @@ -7,14 +7,18 @@ use SilverStripe\ORM\DataExtension; use SilverStripe\ORM\DataObject; use SilverStripe\ORM\Queries\SQLUpdate; +use SilverStripe\UserForms\Control\UserDefinedFormController; use SilverStripe\UserForms\Model\Submission\SubmittedFileField; use SilverStripe\Versioned\Versioned; class UserFormFileExtension extends DataExtension { - private const USER_FORM_UPLOAD_UNKNOWN = null; - private const USER_FORM_UPLOAD_FALSE = 'f'; - private const USER_FORM_UPLOAD_TRUE = 't'; + + public const USER_FORM_UPLOAD_UNKNOWN = null; + + public const USER_FORM_UPLOAD_FALSE = 'f'; + + public const USER_FORM_UPLOAD_TRUE = 't'; private static $db = [ 'UserFormUpload' => "Enum('f, t', null)", @@ -23,22 +27,18 @@ class UserFormFileExtension extends DataExtension /** * Check if the file is associated with a userform submission * Save the result in the database as a tri-state for two reasons: - * a) performance - prevent need for extra db query - * b) if in future the userform submission is deleted and the uploaded file is not (orphaned), then a record - * is retained that the file was originally updated from a userform submission - * - * @see File::isUserFormUpload() + * a) performance - prevent the need for an extra DB query + * b) if in the future the userform submission is deleted and the uploaded file is not (orphaned), + * then it is still recorded that the file was originally uploaded from a userform submission * * @param bool $value + * @see File::isUserFormUpload(), UserDefinedFormController::process() */ public function updateIsUserFormUpload(&$value): void { /** @var File|Versioned $file */ $file = $this->owner; // TODO: updated userform module to update the column on upload - - // return; // TODO - if ($file->UserFormUpload != self::USER_FORM_UPLOAD_UNKNOWN) { $value = $file->UserFormUpload == self::USER_FORM_UPLOAD_TRUE; } else {