Delay uploaded file handling till form validation passes

Components

Labels

Description

When "inp_edit_swfupload" block is used on form, then selected files are actually uploaded in two cases:

  1. when "upload" button is pressed (under uploader control)

  2. when "save" button is pressed (on top of form)

By default SWFUploader uploads files in temp directory ("/system/tmp") and when saving record to database ("save" button pressed) is moving uploaded files from temp directory to actual directory, specified in unit config.

But, when we have some invalid data on form, like required field value is not entered and "save" button is pressed, then we are returned to form with validation errors displayed, but are already uploaded to target directory.

Files, uploaded to temp directory should only be moved to target directory when "save" button is pressed and there are not validation errors on form.

Context Information

None

Additional information (do not use)

This is what happens in what order:

  1. OnSave event is called.

  2. withing OnSave event method "kDBItem::SetFieldsFromHash" is called

  3. method "kDBItem::SetFieldsFromHash" calls "kUploadFormatter::Parse" method
    Last of mentioned methods actually performs file moving from temp directory to target directory.

And only after that form validation happens when "OnPreSave" event is called.

So Parse method actually doesn't know anything about validation result, because no validation happened at that moment.

Instead of actually moving files I propose to put moving operations to "<prefix_special>pending_actions<m_wid>" variable (it is kind of queue).

Queue processing should be made in OnSave event (when temporary tables are used) and in OnAfterItemUpdate/OnAfterItemCreate (when temporary tables are not used).


By no "pending_actions" variable is used only to schedule uploaded file deletion operation. This processing should be joined with file moving and centrally processed in one place.

Attachments

5
  • 24 Jul 2012, 10:32 AM
  • 19 Jul 2012, 09:47 AM
  • 16 Jul 2012, 04:45 PM
  • 16 Jul 2012, 10:46 AM
  • 15 Jul 2012, 07:47 PM

Activity

Alex December 2, 2013 at 12:01 PM

This solution were creating more problems, than it was solving and it was finally removed in https://in-portal.atlassian.net/browse/INP-1241#icft=INP-1241.

Alex July 25, 2012 at 10:29 AM

Since 5.2.0 version was released.

Alex July 24, 2012 at 10:33 AM

Patch "subscription_creation_fatal_error_fix.patch" fixes problem when after creation of subscription-type product SQL error ending with "...ItemResourceId=)..." was thrown.

Alex July 19, 2012 at 9:48 AM

In this task I've changed what hidden fields are used to transfer uploaded file into back to server and "tmp_names" hidden field no longer exists.

JavaScript class FormManager, who used it also stopped working because of that. Fix for it is attached in "form_manager_and_flash_uploader_fix.patch" patch.

Alex July 16, 2012 at 4:47 PM

Patch "uploader_onafteritemupdate_fix.patch" along with #0001355 task solves problem with kDBItem changed fields not being detected in OnAfterItemUpdate event.

Fixed

Details

Priority

Assignee

Reporter

Developer

Change Log Group

Fixed

Change Log Message

Patch Instructions

Patches must be submitted through Phabricator.

External issue ID

External issue URL

Story Points

Fix versions

Affects versions

Created June 3, 2009 at 7:30 PM
Updated December 30, 2024 at 2:21 AM
Resolved July 25, 2012 at 10:29 AM