Closed Restless-ET closed 10 years ago
I'll take a look today to that point and let you know what we can do,
Very well, I will wait on some feedback from you then. If I can be of any assistance please just let me know.
Regards
Hi @Restless-ET
I tried the collection upload widget in synchronous mode ans delete seems to correctly work. You can check it in the project: https://github.com/sescandell/CollectionUploadSample and go to the URI: http://your_domain/app_dev.php/admin/acme_demo_bundle/Library
You can so create a library (in synchronous mode) and you'll be redirected on edit page where you can:
and everything seems to work.
Don't hesitate to tell me if I missed something
Hi @sescandell
I've tried out your sample code and everything seems to work correctly indeed. Although your entity (and database) structure differs from mine. You've a many-to-many relation set between Library and Media entities. So when you choose to remove a Media element you simply remove the respective entry on the relational table created. This neither eliminates the entry on the Media table nor the uploaded file from the file system. I was really expecting for the latter to happen since the "unlink()" method is (supposedly) called on the preSubmit() function.
In my case I've set an one-to-many relation between my Service and Attachment entities. So what I'm expecting when I remove a file is for it to be removed from the file system as well as the corresponding entry on the DB. I'm not really sure if it's my current setup what's really causing this issue, I'll do a few more experimentations... Either way, I just wanted to share this with you since you might have an idea of what might by causing this.
Also, if you believe that this problem is not actually related with this bundle/library please just tell me so.
Regards
I'll give a look to this component thinking about your situation. I'll let you know if I think about something.
Keep in touch,
I think the problem is in here:
#Avocode\FormExtensionsBundle\Form\EventListener\CollectionUploadSubscriber
foreach ($data->$getter() as $file) {
if (!in_array($file->$pkGetter(), $this->submitted_pk)) {
$data->$getter()->removeElement($file);
}
}
In collections with one-to-Many relations: On onSubmit() method, the $data->$getter() will only have the submitted(not deleted) files and the IF condition is always false.
Yes, same problem here, it seems that the
$data = $form->getParent()->getData();
retrieves the object already persisted with the new data instead of retrieving the one prior to submission.
Do you have any idea on how to fix this as it really is a problem.
Thanks
Hey @sescandell, did you have some thought about that, I stil don't manage to make it work.
Thanks
I used to have the same problem but it I fixed it when I added the orphanRemoval=true
notation to the property that contains the file Entities.
Example:
/**
* @ORM\OneToMany(targetEntity="Asset", mappedBy="page", orphanRemoval=true, cascade={"persist"})
* @ORM\OrderBy({"position" = "ASC"})
*/
protected $items;
Awesome, it works this way, thanks.
This issue should be closed then
I can't manage to get this working, either by using the delete button or the checkboxes approach.
I've poked around a little bit and seems to be that the problem is related to the fact that on the preSubmit() function of CollectionUploadSubscriber.php the $data array doesn't seem to contain the key named 'delete_uploads'. I fail to grasp why this is happening though... if you can point me in the right direction I'll make an attempt to try fixing it.