bmcclure / CakePHP-Media-Plugin

A CakePHP (2.0) plugin enabling transfer/manipulation/embedding of files in 23 ways.
Other
60 stars 24 forks source link

Adding the media plugin behaviours prevents edit/delete of record #6

Closed andybeak closed 11 years ago

andybeak commented 12 years ago

If I add the code:

//media plugin behaviors var $actsAs = array( 'Media.Transfer', 'Media.Coupler', 'Media.Generator' );

to my model then I can no longer edit or delete the records. If I remove it then the fields provided by the media manager are not populate.

ghost commented 12 years ago

Could you elaborate the issue more?

andybeak commented 12 years ago

Thanks for helping on this.

I've installed the media manager into a Cake installation to manage product images

Table structure for table images:

CREATE TABLE IF NOT EXISTS images ( id int(11) NOT NULL AUTO_INCREMENT, caption varchar(45) DEFAULT NULL, basename varchar(45) DEFAULT NULL, dirname varchar(45) DEFAULT NULL, default tinyint(1) DEFAULT NULL, created datetime DEFAULT NULL, modified datetime DEFAULT NULL, PRIMARY KEY (id) ) ENGINE=InnoDB DEFAULT CHARSET=latin1 AUTO_INCREMENT=4 ;

I've baked this model and it's controller and then installed media manager.

I added a test image which worked properly - creating the record in the database and the various size images that I require (thumb, category listing, product page).

However the delete function on a record in the table fails entirely and the edit function reports success but doesn't actually update the record.

Removing the above lines from my model allows the edit and delete functions to work again - at the cost of breaking media manager.

ghost commented 12 years ago

could you paste the edit ctp?

andybeak commented 12 years ago

<?php echo $this->Form->create('Image');?>

Form->input('id'); echo $this->Form->input('caption'); echo $this->Form->input('basename'); echo $this->Form->input('dirname'); echo $this->Form->input('default'); echo $this->Form->input('product_id'); ?>

<?php echo $this->Form->end(**('Submit'));?>

ghost commented 12 years ago

I see what the problem is. <?php echo $this->Form->create('Image', array('type'=>'fie'));?>

and your caption (if its the image) should be set to type file as well. Hope this helps

andybeak commented 12 years ago

Oh my word - sorry to waste your time on that - that fixed the edit.

But the delete function still fails.

public function delete($id = null) { if (!$this->request->is('post')) { throw new MethodNotAllowedException(); } $this->Image->id = $id; if (!$this->Image->exists()) { throw new NotFoundException(__('Invalid image')); }

    if ($this->Image->delete()) {
        $this->Session->setFlash(__('Image deleted'));
        $this->redirect(array('action'=>'index'));
    } else {            
        $this->Session->setFlash(__('Image was not deleted'));
        $this->redirect(array('action' => 'index'));
    }
}

This always flashes "Image was not deleted". I have debugged and checked that $id is being passed correctly.

As soon as I remove the media behaviours from the model I am able to delete the images.

By "delete" I mean "delete from database". I do have an unlink function to remove them from disk, which I've commented out until I get the database function working.

ghost commented 12 years ago

Now this is weird, from the sites I made, it CRUD should work as long as the steps are followed, it will also delete the image linked with the data as well.

Thanks for bringing it up. Let me get back to you on this.

ndm2 commented 11 years ago

This is very old, I'd say it can be closed until someone can come up with a reproducible problem.

bmcclure commented 11 years ago

Good point!