EDIT: UPDATING MY QUESTION FOR MORE CLARIFICATION
==========================================================
I use MeioUpload to upload pictures. The picture location is placed in the DB users table in image as such:/img/uploads/users/img/picture34.png.
When a user is deleted, CakePHP is also accessing the physical location of this image from User.image and deleting that image.
There is no belongTo/HasMany relationship here as I do not have an image model/controller.
How can I prevent CakePHP from physically deleting this image?
==========================================================
In my application I have the option to remove a user using the admin_delete function in my users_controller.php. However, when this function is called (see following function), the image saved in the DB is also deleted. How can I prevent this function from removing the image.
function admin_delete($id = null) {
if (!$id) {
$this->Session->setFlash(__('Este usuario nao existe', true));
$this->redirect(array('action'=>'index'));
}
if ($this->User->delete($id)) {
$this->Session->setFlash(__('Este usuario ja foi removido', true));
$this->redirect(array('action'=>'index'));
}
$this->Session->setFlash(__('Este usuario nao foi removido', true));
$this->redirect(array('action' => 'index'));
}
Thanks,
EDIT
The Meioupload behavior defines this beforeDelete method:
Since there is no option to don’t delete the image I think the only way is to temporary detach the behavior. Couldn’t test it but something like this could work:
===
I’m assuming the image is associated with the user model by a belongsTo/hasMany association? In this case the standard delete method has a parameter to avoid deleting of associated data, here is the definition of the delete function:
if you set cascade to false you associated image doesn’t get deleted: