Unfortunately, enabling callbacks in deleteAll corrupts the tree...

Opened a ticket here https://trac.cakephp.org/ticket/4846#preview

On 5 Jun., 12:13, grigri <[EMAIL PROTECTED]> wrote:
> Just override the Asset::deleteAll function:
>
> class Asset extends AppModel {
>   // ...
>
>   function deleteAll($conditions, $cascade=true, $callbacks=true) {
>     // Note the default parameter change : $callbacks is now true if
> unspecified
>     return parent::deleteAll($conditions, $cascade, $callbacks);
>   }
>
> }
>
> On Jun 5, 10:56 am, biesbjerg <[EMAIL PROTECTED]> wrote:
>
> > 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