Closed ghost closed 10 years ago
Are the child records deleted but not the images? Or are the child records still there also?
This is my image table. only the first image gets deleted when deleting the product record associated.
What did you mean by child records, My form in products has one image input. When submitting it is creating 1 record in images any the behavior saves 3 version of the image. When deleting the product record the record in images deletes and the first image but not the 2 additional transforms.
Yeah that's what I meant.
That all looks good. What versions are you using?
cakephp 2.4.3, uploader ver 4.5.0, php 5.5.3. I did email some model/controller clips yesterday for you to look at.
What direction should I research?
Won't have time to look at this until after the holidays, but you can debug a bit. Basically just see if the beforeDelete() is being called for images.
https://github.com/milesj/uploader/blob/master/Model/Behavior/AttachmentBehavior.php#L259
If it's not, it may be a limitation of Cake. If it is being called, make sure that all the fields with files are deleted here.
https://github.com/milesj/uploader/blob/master/Model/Behavior/AttachmentBehavior.php#L443
Did a little debug in attachmentBehavior.php line 470
pr($columns[$column]) ;pr($value);
data returned was good, so we are still holding the data to be deleted.
Array
(
[image_orig] => image
[image_max] => image
[image_thumb] => image
)
image
img/product_images/04f6b3ea183eb9d70981161c4424a6cf525afd9f.png
image
img/product_images/max/04f6b3ea183eb9d70981161c4424a6cf525afd9f.png
image
img/product_images/thumb/04f6b3ea183eb9d70981161c4424a6cf525afd9f.png
the next line is
if ($this->_deleteFile($model, $columns[$column], $value)) {
$save[$column] = '';
After further testing as long as you don't separate the images into folders all 3 images get deleted correctly. can we add this function?
Figured it out.
You also need to be using absolute URLs for uploadDir
.
I went ahead and set the following.
define('UPLOAD_DIR', WWW_ROOT . '/img/product_images/max/');
Then in the model for the transforms
'transforms' => array(
'imageMax' => array(
'class' => 'resize',
'nameCallback' => 'formatName',
'append' => '-max',
'prepend' => '',
'uploadDir' => UPLOAD_DIR,
// 'finalPath' => 'product_images/',
'dbColumn' => 'image_max',
'defaultPath' => '',
'overwrite' => true,
'self' => false,
'width' => PRODUCT_MAX_WIDTH,
'height' => PRODUCT_MAX_HEIGHT,
'aspect' => false
All 3 upload fine. When deleting the record this or still remains.
Have you updated versions? I tested it last night with your exact configuration and it worked.
Will test again, didn't see you updated to 4.5.1
I setup a hasmany association between products and images. I defined a AttachmentBehavior in the image model. When adding a product the images are uploaded and saved fine. When I delete the record the image record and main image is only removed but not the 2 additional transforms I defined. I can't figure out why only 1 of the 3 images are only removed.