Hi guys,

I could use some ideas here. Here's the deal:

I have this model, Assets, which holds references to uploaded files in
my app.
My UploadBehavior has some callbacks, one of them is beforeDelete
which makes sure the file gets deleted from the filesystem before
deleting the row in the database.

The problem I'm facing is that when you delete an asset with children,
TreeBehavior deletes children using deleteAll without invoking
callbacks, so my files aren't deleted from the filesystem.


I would like some ideas to put this together, so that when an asset
(an asset can be a folder too) is deleted, all children gets deleted,
including the files in the filesystem. Any ideas?

Here's my model, for reference:

<?php
class Asset extends AssetsAppModel {
        var $name = 'Asset';
        var $displayField = 'filename';

        var $order = array(
                'folder' => 'DESC',
                'lft' => 'ASC',
                'filename' => 'ASC'
        );

        var $actsAs = array(
                'Assets.Upload',
                'Tree'
        );

        function find($type, $options = array()) {
                switch ($type) {
                        case 'folders':
                                return parent::find('all', Set::merge(array(
                                        'conditions' => array('folder' => 1),
                                        'fields' => array('id', 'lft', 'rght', 
'parent_id', 'filename'),
                                ), $options));
                        case 'images':
                                return parent::find('all', Set::merge(array(
                                        'conditions' => array('image' => 1),
                                ), $options));
                        default:
                                return parent::find($type, $options);
                }
        }
}
?>

And my UploadBehavior's beforeDelete callback, which isn't being
called when TreeBehavior does it's stuff:

function beforeDelete(&$model) {
        extract($this->settings[$model->alias]);
        if ($this->Folder->rm($path . $model->id . DS)) {
                return true;
        }
        return false;
}


Hope you guys have some ideas, thanks for your time!
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"CakePHP" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/cake-php?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to