CTOlet / yii2-attachments

Yii2 extension for uploading and attaching the files to the models
66 stars 57 forks source link

Prevent double execution of saveUploads #21

Closed maxxer closed 9 years ago

maxxer commented 9 years ago

It may happen that after the model has been created/updated you need to save it again. Without this patch the saveUploads is executed again on the same POST data, and the behavior tries to save the files twice.

CTOlet commented 9 years ago

Could you explain me again when it may happen? If I have understood right, for example, it will will happen when you save the model twice on the same function / method?

maxxer commented 9 years ago

I'm manually uploading attachment using a custom controller action. So in the controller I save the model, saveUploads is triggered and the files are saved and associated to the model correctly. But after that, in the same controller, I trigger a model method to notify the user about the new model, and I store the notification date into the model. I did something like this:

$model->notify_date = new Expression("NOW()");
$model->save (false, ['notify_date']);

At this time saveUploads is executed again, and $_FILES still holds the files so it tries to save the uploads again, but it fails because they don't exist anymore in tmp.

Anyway I was mistaken, this patch doesn't work, another solution is needed